From adde76b715ed816331d9d02dda341dbcaf3fcf4a Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 30 May 2026 15:24:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20phpx?= =?UTF-8?q?/src/misc=20=E7=9B=AE=E5=BD=95=E4=B8=8B=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E7=BC=93=E5=AD=98=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现 hasMiscObjectFileCache 方法用于检查 phpx/src/misc 下的源文件是否已有有效缓存 - 添加 isPhpxMiscFile 方法判断文件是否为 phpx/misc 目录下的文件 - 在编译前检查 misc 目录下的文件是否命中缓存并跳过编译 - 缓存检查逻辑独立于 enableCache 参数,始终生效(除非指定 --force) - 仅当目标文件比源文件和 phpx 头文件更新时才使用缓存 - 遍历 phpx/include 和 phpx/src/misc 目录检查头文件修改时间 --- src/Php/Translator.php | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 4caf3248..139264c0 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -706,6 +706,53 @@ CODE; return false; } + /** + * 检查 phpx/src/misc/ 下的源文件是否已有有效缓存。 + * 独立于 enableCache,始终生效(除非指定 --force)。 + * 仅检查 .o 文件是否比源文件和 phpx 头文件更新。 + */ + public function hasMiscObjectFileCache(string $cppFile): bool + { + if ($this->climate->arguments->defined('force')) { + return false; + } + + $objectFile = $this->getObjectFile($cppFile); + if (!file_exists($objectFile)) { + return false; + } + + $objectMtime = filemtime($objectFile); + if ($objectMtime <= filemtime($cppFile)) { + return false; + } + + $phpxDir = $this->getPhpxDir(); + $headerDirs = [$phpxDir . '/include', $phpxDir . '/src/misc']; + + foreach ($headerDirs as $dir) { + if (!is_dir($dir)) { + continue; + } + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS) + ); + foreach ($iterator as $file) { + if ($file->getExtension() === 'h' && $file->getMTime() > $objectMtime) { + return false; + } + } + } + + return true; + } + + public function isPhpxMiscFile(string $cppFile): bool + { + $miscDir = $this->getPhpxDir() . '/src/misc/'; + return str_starts_with($cppFile, $miscDir); + } + /** * 判断文件是否为 C++ 源文件 */ @@ -744,6 +791,13 @@ CODE; public function compileFile(string $cppFile, string $objectFile, bool $parallel = false): void { + if ($this->isPhpxMiscFile($cppFile) && $this->hasMiscObjectFileCache($cppFile)) { + if (!$parallel) { + $this->climate->darkGray('[cache] skip: ' . $cppFile); + } + return; + } + if ($this->hasObjectFileCache($cppFile)) { if (!$parallel) { $this->climate->darkGray('skip: ' . $cppFile . ', cache exists');