diff --git a/src/Php/Backend/CompilerBackend.php b/src/Php/Backend/CompilerBackend.php index 32ad240b..23bcb466 100644 --- a/src/Php/Backend/CompilerBackend.php +++ b/src/Php/Backend/CompilerBackend.php @@ -15,6 +15,11 @@ abstract class CompilerBackend */ protected PlatformBase $platform; + /** + * 最近创建的 Response File 路径,用于构建完成后清理 + */ + protected string $lastResponseFile = ''; + public function __construct(PlatformBase $platform) { $this->platform = $platform; @@ -163,6 +168,7 @@ abstract class CompilerBackend protected function createResponseFile(array $objectFiles, string $targetFile): string { $rspFile = dirname($targetFile) . DIRECTORY_SEPARATOR . basename($targetFile) . '.rsp'; + $this->lastResponseFile = $rspFile; $lines = []; foreach ($objectFiles as $file) { // 路径含空格时用双引号包裹,MSVC link.exe 和 GCC/Clang 均支持 @@ -174,4 +180,14 @@ abstract class CompilerBackend file_put_contents($rspFile, implode("\n", $lines)); return '@' . $rspFile; } + + /** + * 删除最近创建的 Response File 临时文件 + */ + public function cleanupResponseFile(): void + { + if ($this->lastResponseFile !== '' && file_exists($this->lastResponseFile)) { + unlink($this->lastResponseFile); + } + } } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index d1ebef75..ec664231 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -1558,6 +1558,9 @@ CODE; $this->error('target file not generated: ' . $targetFile); } + // 删除 Response File 临时文件 + $this->getCompilerBackend()->cleanupResponseFile(); + $this->climate->green('Build successful: ' . $targetFile); return $targetFile;