@@ -18,7 +18,6 @@ class SourcePatcher
18
18
public static function init (): void
19
19
{
20
20
// FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']);
21
- FileSystem::addSourceExtractHook ('micro ' , [SourcePatcher::class, 'patchMicro ' ]);
22
21
FileSystem::addSourceExtractHook ('openssl ' , [SourcePatcher::class, 'patchOpenssl11Darwin ' ]);
23
22
FileSystem::addSourceExtractHook ('swoole ' , [SourcePatcher::class, 'patchSwoole ' ]);
24
23
FileSystem::addSourceExtractHook ('php-src ' , [SourcePatcher::class, 'patchPhpLibxml212 ' ]);
@@ -106,7 +105,7 @@ public static function patchBeforeConfigure(BuilderBase $builder): void
106
105
* @throws RuntimeException
107
106
* @throws FileSystemException
108
107
*/
109
- public static function patchMicro (string $ name = '' , string $ target = '' , ?array $ items = null ): bool
108
+ public static function patchMicro (?array $ items = null ): bool
110
109
{
111
110
if (!file_exists (SOURCE_PATH . '/php-src/sapi/micro/php_micro.c ' )) {
112
111
return false ;
@@ -153,11 +152,7 @@ public static function patchMicro(string $name = '', string $target = '', ?array
153
152
154
153
foreach ($ patches as $ patch ) {
155
154
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 ' );
161
156
}
162
157
163
158
return true ;
@@ -166,24 +161,32 @@ public static function patchMicro(string $name = '', string $target = '', ?array
166
161
/**
167
162
* Use existing patch file for patching
168
163
*
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
170
165
* @param string $cwd Working directory for patch command
171
166
* @param bool $reverse Reverse patches (default: False)
172
167
* @throws RuntimeException
173
168
*/
174
169
public static function patchFile (string $ patch_name , string $ cwd , bool $ reverse = false ): bool
175
170
{
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 )) {
177
177
return false ;
178
178
}
179
179
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
+ }
182
184
183
185
// 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 }" );
187
190
}
188
191
189
192
// detect
0 commit comments