Skip to content

Commit 840e09a

Browse files
authored
Merge pull request #811 from crazywhalecc/fix/micro-patches
Fix/micro patches
2 parents b04ffad + d00a522 commit 840e09a

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

config/env.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ SPC_EXTRA_LIBS=
7878
; upx executable path
7979
UPX_EXEC=${PKG_ROOT_PATH}/bin/upx
8080
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
81-
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream
81+
SPC_MICRO_PATCHES=cli_checks,disable_huge_page
8282

8383
; *** default build command for building php ***
8484
; buildconf command
@@ -118,7 +118,7 @@ SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
118118
; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated)
119119
SPC_EXTRA_LIBS=
120120
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
121-
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,macos_iconv
121+
SPC_MICRO_PATCHES=cli_checks,macos_iconv
122122

123123
; *** default build command for building php ***
124124
; buildconf command

src/SPC/builder/BuilderBase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use SPC\store\FileSystem;
1515
use SPC\store\LockFile;
1616
use SPC\store\SourceManager;
17+
use SPC\store\SourcePatcher;
1718
use SPC\util\CustomExt;
1819

1920
abstract class BuilderBase
@@ -203,6 +204,8 @@ public function proveExts(array $static_extensions, array $shared_extensions = [
203204
$this->emitPatchPoint('before-exts-extract');
204205
SourceManager::initSource(exts: [...$static_extensions, ...$shared_extensions]);
205206
$this->emitPatchPoint('after-exts-extract');
207+
// patch micro
208+
SourcePatcher::patchMicro();
206209
}
207210

208211
foreach ([...$static_extensions, ...$shared_extensions] as $extension) {

src/SPC/store/SourcePatcher.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class SourcePatcher
1717
public static function init(): void
1818
{
1919
// FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']);
20-
FileSystem::addSourceExtractHook('micro', [SourcePatcher::class, 'patchMicro']);
2120
FileSystem::addSourceExtractHook('openssl', [SourcePatcher::class, 'patchOpenssl11Darwin']);
2221
FileSystem::addSourceExtractHook('swoole', [SourcePatcher::class, 'patchSwoole']);
2322
FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchPhpLibxml212']);
@@ -105,7 +104,7 @@ public static function patchBeforeConfigure(BuilderBase $builder): void
105104
* @throws RuntimeException
106105
* @throws FileSystemException
107106
*/
108-
public static function patchMicro(string $name = '', string $target = '', ?array $items = null): bool
107+
public static function patchMicro(?array $items = null): bool
109108
{
110109
if (!file_exists(SOURCE_PATH . '/php-src/sapi/micro/php_micro.c')) {
111110
return false;
@@ -152,11 +151,7 @@ public static function patchMicro(string $name = '', string $target = '', ?array
152151

153152
foreach ($patches as $patch) {
154153
logger()->info("Patching micro with {$patch}");
155-
$patchesStr = str_replace('/', DIRECTORY_SEPARATOR, $patch);
156-
f_passthru(
157-
'cd ' . SOURCE_PATH . '/php-src && ' .
158-
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patchesStr . ' | patch -p1 '
159-
);
154+
self::patchFile(SOURCE_PATH . "/php-src/{$patch}", SOURCE_PATH . '/php-src');
160155
}
161156

162157
return true;
@@ -165,24 +160,32 @@ public static function patchMicro(string $name = '', string $target = '', ?array
165160
/**
166161
* Use existing patch file for patching
167162
*
168-
* @param string $patch_name Patch file name in src/globals/patch/
163+
* @param string $patch_name Patch file name in src/globals/patch/ or absolute path
169164
* @param string $cwd Working directory for patch command
170165
* @param bool $reverse Reverse patches (default: False)
171166
* @throws RuntimeException
172167
*/
173168
public static function patchFile(string $patch_name, string $cwd, bool $reverse = false): bool
174169
{
175-
if (!file_exists(ROOT_DIR . "/src/globals/patch/{$patch_name}")) {
170+
if (FileSystem::isRelativePath($patch_name)) {
171+
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
172+
} else {
173+
$patch_file = $patch_name;
174+
}
175+
if (!file_exists($patch_file)) {
176176
return false;
177177
}
178178

179-
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
180-
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file);
179+
$patch_str = FileSystem::convertPath($patch_file);
180+
if (!file_exists($patch_str)) {
181+
throw new RuntimeException("Patch file [{$patch_str}] does not exist");
182+
}
181183

182184
// Copy patch from phar
183-
if (\Phar::running() !== '') {
184-
file_put_contents(SOURCE_PATH . '/' . $patch_name, file_get_contents($patch_file));
185-
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, SOURCE_PATH . '/' . $patch_name);
185+
if (str_starts_with($patch_str, 'phar://')) {
186+
$filename = pathinfo($patch_file, PATHINFO_BASENAME);
187+
file_put_contents(SOURCE_PATH . "/{$filename}", file_get_contents($patch_file));
188+
$patch_str = FileSystem::convertPath(SOURCE_PATH . "/{$filename}");
186189
}
187190

188191
// detect

0 commit comments

Comments
 (0)