diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 51b7ec89..6ce94775 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -5090,10 +5090,14 @@ class CompilerBase extends \PhpAot\Core\Translator protected function setBuildDir(string $string): void { - $this->buildDir = $string; - if (!is_dir($this->buildDir)) { - mkdir($this->buildDir, 0777, true); + if (!is_dir($string)) { + mkdir($string, 0777, true); } + $resolved = realpath($string); + if ($resolved === false) { + throw new \RuntimeException('Failed to resolve build path: ' . $string); + } + $this->buildDir = $resolved; } protected function isStubFile(string $file): bool diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 2806b9c7..196eeebd 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -546,6 +546,13 @@ class Translator extends Preprocessor if (empty($sourceFiles)) { $this->stop('No valid source file found'); } + + // 生成头文件:函数声明、全局变量声明 + $this->genFunctionDeclaration($this->getIncludeDir() . "/php_{$this->targetName}_func_decl.h"); + $this->genExternGlobalVars($this->getIncludeDir() . "/php_{$this->targetName}_global_var_decl.h"); + // 生成扩展模块源文件 + $sourceFiles[] = $this->genExtension(); + return $sourceFiles; } @@ -1052,13 +1059,6 @@ CODE; { $job = $this->maxJob; - // 生成所有函数声明、全局变量声明的头文件 - $this->genFunctionDeclaration($this->getIncludeDir() . "/php_{$this->targetName}_func_decl.h"); - $this->genExternGlobalVars($this->getIncludeDir() . "/php_{$this->targetName}_global_var_decl.h"); - - // 生成扩展模块的源文件 - $sourceFiles[] = $this->genExtension(); - // embed 需要 main 函数,以及 cli 的内置函数定义 if ($this->isBuildModeBin()) { $sourceFiles[] = $this->getPhpxDir() . '/src/misc/main.cc'; diff --git a/src/compiler.php b/src/compiler.php index 63366913..5dcf9843 100644 --- a/src/compiler.php +++ b/src/compiler.php @@ -27,7 +27,7 @@ function main(int $argc, array $argv): void if ($translator->isDryRun()) { $buildDir = $translator->getBuildDir(); $count = count($sourceFiles); - echo "Dry run completed: {$count} C++ source file(s) generated in {$buildDir}\n"; + $translator->output("Dry run completed: {$count} C++ source file(s) generated in {$buildDir}", 'lightBlue'); return; }