feat(php): 添加 Response File 临时文件清理功能

- 在 CompilerBackend 中添加 lastResponseFile 属性记录最近创建的响应文件路径
- 修改 createResponseFile 方法保存响应文件路径到实例属性
- 新增 cleanupResponseFile 方法用于删除临时响应文件
- 在 Translator 构建成功后调用 cleanupResponseFile 清理临时文件
pull/3/head
韩天峰 2 months ago
parent ec07242ce1
commit ebc6891a40
  1. 16
      src/Php/Backend/CompilerBackend.php
  2. 3
      src/Php/Translator.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);
}
}
}

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

Loading…
Cancel
Save