refactor(php): 移除编译缓存机制并更新强制编译描述

- 移除了 Preprocessor 和 Translator 中的缓存检查逻辑
- 删除了 hasCppFileCache 和 hasObjectFileCache 方法
- 更新 force 参数描述为 "Force recompile phpx misc files (ignore cache)"
- 简化了编译流程,不再跳过已存在缓存的文件
- 保留了 misc 目录下源文件的缓存检查功能
- 从 Constants.php 和 Translator.php 中移除了相关的缓存控制代码
pull/1/head
韩天峰 3 months ago
parent adde76b715
commit fda0acc38f
  1. 2
      src/Php/Constants.php
  2. 21
      src/Php/Preprocessor.php
  3. 31
      src/Php/Translator.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,
],

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

@ -119,7 +119,7 @@ class Translator extends Preprocessor
$climate->tab()->out('-o, --output <file> 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 <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 <num> 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);

Loading…
Cancel
Save