diff --git a/examples/tetris-sdl/project.yml b/examples/tetris-sdl/project.yml index 26e0e524..e87cf5f3 100644 --- a/examples/tetris-sdl/project.yml +++ b/examples/tetris-sdl/project.yml @@ -5,8 +5,8 @@ sources: - main.php - ./php-src - ./cpp-src -ldflags: +ld-flags: - "-lSDL2" -cxxflags: +cxx-flags: - "-I/usr/include/SDL2" - "-D_REENTRANT" diff --git a/phpunit/src/CompilerBaseApiTest.php b/phpunit/src/CompilerBaseApiTest.php index 240939bf..cbe95869 100644 --- a/phpunit/src/CompilerBaseApiTest.php +++ b/phpunit/src/CompilerBaseApiTest.php @@ -312,6 +312,21 @@ YAML, 'custom-name.yml', 'yaml-alias'); $this->assertSame(dirname($projectFile) . '/out', $this->getPropertyValue('outputDir')); } + public function testParseProjectYamlNameDoesNotSetOutputDirectory(): void + { + $projectFile = $this->createProjectFile(<<<'YAML' +name: tetris +sources: + - main.php +YAML, 'myproject.yml', 'examples/tetris-sdl'); + + $this->invokeMethod('parseProjectYaml', $projectFile); + + $this->assertSame('tetris', $this->getPropertyValue('targetName')); + $this->assertSame('', $this->getPropertyValue('outputDir')); + $this->assertSame('tetris', $this->invokeMethod('getTargetFileName')); + } + public function testParseProjectYamlResolvesRelativePathOptionsAgainstYamlDirectory(): void { $projectFile = $this->createProjectFile(<<<'YAML' diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 8ae59339..fa69a39d 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -2173,10 +2173,12 @@ CODE; } } - // 读取 output/name - $output = $cfg['output'] ?? $cfg['name'] ?? null; + // 读取 output/name。name 只表示目标名,不能按 YAML 目录解析成输出路径。 + $output = $cfg['output'] ?? null; if (!empty($output)) { $this->setTargetName($this->resolvePath((string) $output, $projectDir, 'Output path')); + } elseif (!empty($cfg['name'])) { + $this->setTargetName((string) $cfg['name']); } // 读取 cpp-compiler