Skip to content

Commit 68e500e

Browse files
authored
Merge branch 'main' into refactor/spc-target
2 parents 956667b + 840e09a commit 68e500e

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

config/env.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
134134
; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated)
135135
SPC_EXTRA_LIBS=
136136
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
137-
SPC_MICRO_PATCHES=cli_checks,disable_huge_page
137+
SPC_MICRO_PATCHES=cli_checks,macos_iconv
138138

139139
; *** default build command for building php ***
140140
; 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
@@ -18,7 +18,6 @@ class SourcePatcher
1818
public static function init(): void
1919
{
2020
// FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']);
21-
FileSystem::addSourceExtractHook('micro', [SourcePatcher::class, 'patchMicro']);
2221
FileSystem::addSourceExtractHook('openssl', [SourcePatcher::class, 'patchOpenssl11Darwin']);
2322
FileSystem::addSourceExtractHook('swoole', [SourcePatcher::class, 'patchSwoole']);
2423
FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchPhpLibxml212']);
@@ -106,7 +105,7 @@ public static function patchBeforeConfigure(BuilderBase $builder): void
106105
* @throws RuntimeException
107106
* @throws FileSystemException
108107
*/
109-
public static function patchMicro(string $name = '', string $target = '', ?array $items = null): bool
108+
public static function patchMicro(?array $items = null): bool
110109
{
111110
if (!file_exists(SOURCE_PATH . '/php-src/sapi/micro/php_micro.c')) {
112111
return false;
@@ -153,11 +152,7 @@ public static function patchMicro(string $name = '', string $target = '', ?array
153152

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

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

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

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

189192
// detect

0 commit comments

Comments
 (0)