diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6ce94775..e0ea530c 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -334,6 +334,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected bool $bigintTypes = false; protected string $rootPath; protected string $buildDir; + protected string $outputDir = ''; // -o 参数指定的输出目录 protected int $debugLine = 0; protected CLImate $climate; protected bool $stubFile = false; @@ -2391,6 +2392,10 @@ class CompilerBase extends \PhpAot\Core\Translator $targetFile .= $extension; } + if ($this->outputDir !== '') { + $targetFile = rtrim($this->outputDir, '/\\') . '/' . $targetFile; + } + return $targetFile; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 196eeebd..b776fea0 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -412,6 +412,11 @@ class Translator extends Preprocessor if ($this->climate->arguments->defined('output')) { $name = $this->climate->arguments->get('output'); } + // 如果指定了路径(包含目录分隔符),提取目录和文件名 + if (str_contains($name, '/') || str_contains($name, '\\')) { + $this->outputDir = dirname($name); + $name = basename($name); + } $name = str_replace(['-', '*'], '_', $name); if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) { $this->climate->red('The target name `' . $name . '` must be a valid identifier');