From ebc6891a40f54ff996fcfbefe0912dff26a729d2 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 26 Jun 2026 19:46:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=20Response=20Fi?= =?UTF-8?q?le=20=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CompilerBackend 中添加 lastResponseFile 属性记录最近创建的响应文件路径 - 修改 createResponseFile 方法保存响应文件路径到实例属性 - 新增 cleanupResponseFile 方法用于删除临时响应文件 - 在 Translator 构建成功后调用 cleanupResponseFile 清理临时文件 --- src/Php/Backend/CompilerBackend.php | 16 ++++++++++++++++ src/Php/Translator.php | 3 +++ 2 files changed, 19 insertions(+) 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;