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