feat(compiler): 添加输出目录参数支持

- 在 CompilerBase 中添加 outputDir 属性用于存储 -o 参数指定的输出目录
- 实现将目标文件路径与输出目录进行拼接的功能
- 在 Translator 中解析输出参数中的路径分隔符并分离目录和文件名
- 支持通过 -o 参数直接指定完整的输出路径包括目录结构
pull/3/head
韩天峰 2 months ago
parent a6a62c8e81
commit e55da7297d
  1. 5
      src/Php/CompilerBase.php
  2. 5
      src/Php/Translator.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;
}

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

Loading…
Cancel
Save