fix phar patch

This commit is contained in:
crazywhalecc 2023-05-01 12:50:01 +08:00
parent 85ac553ded
commit 280284e4c2
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
5 changed files with 17 additions and 29 deletions

View File

@ -221,7 +221,7 @@
"type": "git",
"path": "php-src/sapi/micro",
"rev": "master",
"url": "https://github.com/dixyes/phpmicro",
"url": "https://github.com/crazywhalecc/phpmicro",
"license": {
"type": "file",
"path": "LICENSE"

View File

@ -218,7 +218,7 @@ class LinuxBuilder extends BuilderBase
}
if ($this->phar_patched) {
shell()->cd(SOURCE_PATH . '/php-src')->exec('patch -p1 -R < sapi/micro/patches/phar.patch');
SourcePatcher::patchMicro(['phar'], true);
}
}
@ -255,12 +255,7 @@ class LinuxBuilder extends BuilderBase
}
if ($this->getExt('phar')) {
$this->phar_patched = true;
try {
shell()->cd(SOURCE_PATH . '/php-src')->exec('patch -p1 < sapi/micro/patches/phar.patch');
} catch (RuntimeException $e) {
logger()->error('failed to patch phat due to patch exit with code ' . $e->getCode());
$this->phar_patched = false;
}
SourcePatcher::patchMicro(['phar']);
}
shell()->cd(SOURCE_PATH . '/php-src')

View File

@ -187,7 +187,7 @@ class MacOSBuilder extends BuilderBase
}
if ($this->phar_patched) {
f_passthru('cd ' . SOURCE_PATH . '/php-src && patch -p1 -R < sapi/micro/patches/phar.patch');
SourcePatcher::patchMicro(['phar'], true);
}
}
@ -218,13 +218,7 @@ class MacOSBuilder extends BuilderBase
}
if ($this->getExt('phar')) {
$this->phar_patched = true;
try {
// TODO: 未来改进一下 patch让除了这种 patch 类型的文件以外可以恢复原文件
shell()->cd(SOURCE_PATH . '/php-src')->exec('patch -p1 < sapi/micro/patches/phar.patch');
} catch (RuntimeException $e) {
logger()->error('failed to patch phat due to patch exit with code ' . $e->getCode());
$this->phar_patched = false;
}
SourcePatcher::patchMicro(['phar']);
}
shell()->cd(SOURCE_PATH . '/php-src')

View File

@ -442,7 +442,7 @@ class FileSystem
private static function emitSourceExtractHook(string $name)
{
foreach ((self::$_extract_hook[$name] ?? []) as $hook) {
if ($hook($name) === true) {
if ($hook() === true) {
logger()->info('Patched source [' . $name . '] after extracted');
}
}

View File

@ -117,7 +117,7 @@ class SourcePatcher
);
}
public static function patchMicro(): bool
public static function patchMicro(?array $list = null, bool $reverse = false): bool
{
if (!file_exists(SOURCE_PATH . '/php-src/sapi/micro/php_micro.c')) {
return false;
@ -137,7 +137,7 @@ class SourcePatcher
$check = !defined('DEBUG_MODE') ? ' -q' : '';
// f_passthru('cd ' . SOURCE_PATH . '/php-src && git checkout' . $check . ' HEAD');
$patch_list = [
$default = [
'static_opcache',
'static_extensions_win32',
'cli_checks',
@ -146,15 +146,13 @@ class SourcePatcher
'win32',
'zend_stream',
];
$patch_list = array_merge($patch_list, match (PHP_OS_FAMILY) {
'Windows' => [
'cli_static',
],
'Darwin' => [
'macos_iconv',
],
default => [],
});
if (PHP_OS_FAMILY === 'Windows') {
$default[] = 'cli_static';
}
if (PHP_OS_FAMILY === 'Darwin') {
$default[] = 'macos_iconv';
}
$patch_list = $list ?? $default;
$patches = [];
$serial = ['80', '81', '82'];
foreach ($patch_list as $patchName) {
@ -177,8 +175,9 @@ class SourcePatcher
f_passthru(
'cd ' . SOURCE_PATH . '/php-src && ' .
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patchesStr . ' | patch -p1'
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patchesStr . ' | patch -p1 ' . ($reverse ? '-R' : '')
);
return true;
}