fix: 修正项目名称与输出目录的解析逻辑

pull/15/head
韩天峰 2 months ago
parent fc5eeb3c0f
commit 6577f9bf81
  1. 4
      examples/tetris-sdl/project.yml
  2. 15
      phpunit/src/CompilerBaseApiTest.php
  3. 6
      src/Php/Translator.php

@ -5,8 +5,8 @@ sources:
- main.php
- ./php-src
- ./cpp-src
ldflags:
ld-flags:
- "-lSDL2"
cxxflags:
cxx-flags:
- "-I/usr/include/SDL2"
- "-D_REENTRANT"

@ -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'

@ -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

Loading…
Cancel
Save