From fda0acc38f63967937a5a30f6dade0ea28fa4ba7 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 30 May 2026 15:26:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E7=A7=BB=E9=99=A4=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E7=BC=93=E5=AD=98=E6=9C=BA=E5=88=B6=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=BC=BA=E5=88=B6=E7=BC=96=E8=AF=91=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了 Preprocessor 和 Translator 中的缓存检查逻辑 - 删除了 hasCppFileCache 和 hasObjectFileCache 方法 - 更新 force 参数描述为 "Force recompile phpx misc files (ignore cache)" - 简化了编译流程,不再跳过已存在缓存的文件 - 保留了 misc 目录下源文件的缓存检查功能 - 从 Constants.php 和 Translator.php 中移除了相关的缓存控制代码 --- src/Php/Constants.php | 2 +- src/Php/Preprocessor.php | 21 --------------------- src/Php/Translator.php | 31 ++----------------------------- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 4c2572be..5e60c78a 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -107,7 +107,7 @@ class Constants 'force' => [ 'prefix' => 'f', 'longPrefix' => 'force', - 'description' => 'Force compile even if cache exists', + 'description' => 'Force recompile phpx misc files (ignore cache)', 'required' => false, 'noValue' => true, ], diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index 164472ea..ea60e5d1 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -26,8 +26,6 @@ use PhpParser\NodeTraverser; class Preprocessor extends CompilerBase { - protected bool $enableCache = false; - public function sortFiles(array &$list): void { $sorter = new StringSort(); @@ -87,27 +85,8 @@ class Preprocessor extends CompilerBase return $info['dirname'] . $this->getPlatform()->getPathSeparator() . $info['filename'] . $ext; } - public function hasCppFileCache(string $file): bool - { - if (!$this->enableCache or $this->climate->arguments->defined('force')) { - return false; - } - $cppFile = $this->getCppFile($file); - if (file_exists($cppFile) and filemtime($cppFile) > filemtime($file)) { - return true; - } - - return false; - } - public function prepareFile(string $file): void { - if ($this->hasCppFileCache($file)) { - $this->climate->darkGray('skip: ' . $file . ', cache exists'); - - return; - } - $phpCode = $this->loadFile($file); $this->symbolCallInFile[$this->file] = []; $this->resetFile(); diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 139264c0..2b73679a 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -119,7 +119,7 @@ class Translator extends Preprocessor $climate->tab()->out('-o, --output Output binary name (default: input basename)'); $climate->tab()->out('-v, --version Show version'); $climate->tab()->out('-h, --help Show this help message'); - $climate->tab()->out('-f, --force Force compile even if cache exists'); + $climate->tab()->out('-f, --force Force recompile phpx misc files (ignore cache)'); $climate->tab()->out('-m, --mode Compilation mode, -m bin(binary) or -m ext(extension), default: bin'); $climate->tab()->out('-r, --run Run the compiled binary after build'); $climate->tab()->out('-j, --job Number of parallel compilation jobs (default: 4)'); @@ -206,11 +206,6 @@ class Translator extends Preprocessor public function convertFile(string $file): string { $file = realpath($file); - if ($this->hasCppFileCache($file)) { - $this->climate->darkGray('skip: ' . $file . ', cache exists'); - - return $this->getCppFile($file); - } $phpCode = $this->loadFile($file); $this->localHeaders = []; while (true) { @@ -693,22 +688,8 @@ CODE; return self::MODULE_NAME_PREFIX . $this->targetName; } - public function hasObjectFileCache(string $cppFile): bool - { - if (!$this->enableCache or $this->climate->arguments->defined('force')) { - return false; - } - $objectFile = $this->getObjectFile($cppFile); - if (file_exists($objectFile) and filemtime($objectFile) > filemtime($cppFile)) { - return true; - } - - return false; - } - /** - * 检查 phpx/src/misc/ 下的源文件是否已有有效缓存。 - * 独立于 enableCache,始终生效(除非指定 --force)。 + * 检查 phpx/src/misc/ 下的源文件是否已有有效缓存,始终生效(除非指定 --force)。 * 仅检查 .o 文件是否比源文件和 phpx 头文件更新。 */ public function hasMiscObjectFileCache(string $cppFile): bool @@ -798,14 +779,6 @@ CODE; return; } - if ($this->hasObjectFileCache($cppFile)) { - if (!$parallel) { - $this->climate->darkGray('skip: ' . $cppFile . ', cache exists'); - } - - return; - } - // 检测文件语言类型 $language = $this->getLanguageFromExtension($cppFile);