From 6577f9bf814aea52faf55dcd890ba0abd4939763 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 8 Jul 2026 18:04:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=B8=8E=E8=BE=93=E5=87=BA=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/tetris-sdl/project.yml | 4 ++-- phpunit/src/CompilerBaseApiTest.php | 15 +++++++++++++++ src/Php/Translator.php | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) 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