-
-
Notifications
You must be signed in to change notification settings - Fork 305
Fix/micro patches #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix/micro patches #811
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25c2def
Remove unnecessary SPC_MICRO_PATCHES
crazywhalecc ad080da
Refactor micro patching logic in SourcePatcher
crazywhalecc 88d99a7
Update src/SPC/store/SourcePatcher.php
crazywhalecc 3965a89
Add missing directory separator
crazywhalecc d00a522
Add exception for checking patch file exist
crazywhalecc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,7 +17,6 @@ class SourcePatcher | |||||
public static function init(): void | ||||||
{ | ||||||
// FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']); | ||||||
FileSystem::addSourceExtractHook('micro', [SourcePatcher::class, 'patchMicro']); | ||||||
FileSystem::addSourceExtractHook('openssl', [SourcePatcher::class, 'patchOpenssl11Darwin']); | ||||||
FileSystem::addSourceExtractHook('swoole', [SourcePatcher::class, 'patchSwoole']); | ||||||
FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchPhpLibxml212']); | ||||||
|
@@ -105,7 +104,7 @@ public static function patchBeforeConfigure(BuilderBase $builder): void | |||||
* @throws RuntimeException | ||||||
* @throws FileSystemException | ||||||
*/ | ||||||
public static function patchMicro(string $name = '', string $target = '', ?array $items = null): bool | ||||||
public static function patchMicro(?array $items = null): bool | ||||||
{ | ||||||
if (!file_exists(SOURCE_PATH . '/php-src/sapi/micro/php_micro.c')) { | ||||||
return false; | ||||||
|
@@ -152,11 +151,7 @@ public static function patchMicro(string $name = '', string $target = '', ?array | |||||
|
||||||
foreach ($patches as $patch) { | ||||||
logger()->info("Patching micro with {$patch}"); | ||||||
$patchesStr = str_replace('/', DIRECTORY_SEPARATOR, $patch); | ||||||
f_passthru( | ||||||
'cd ' . SOURCE_PATH . '/php-src && ' . | ||||||
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patchesStr . ' | patch -p1 ' | ||||||
); | ||||||
self::patchFile(SOURCE_PATH . "/php-src{$patch}", SOURCE_PATH . '/php-src'); | ||||||
} | ||||||
|
||||||
return true; | ||||||
|
@@ -165,24 +160,29 @@ public static function patchMicro(string $name = '', string $target = '', ?array | |||||
/** | ||||||
* Use existing patch file for patching | ||||||
* | ||||||
* @param string $patch_name Patch file name in src/globals/patch/ | ||||||
* @param string $patch_name Patch file name in src/globals/patch/ or absolute path | ||||||
* @param string $cwd Working directory for patch command | ||||||
* @param bool $reverse Reverse patches (default: False) | ||||||
* @throws RuntimeException | ||||||
*/ | ||||||
public static function patchFile(string $patch_name, string $cwd, bool $reverse = false): bool | ||||||
{ | ||||||
if (!file_exists(ROOT_DIR . "/src/globals/patch/{$patch_name}")) { | ||||||
if (FileSystem::isRelativePath($patch_name)) { | ||||||
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}"; | ||||||
} else { | ||||||
$patch_file = $patch_name; | ||||||
} | ||||||
if (!file_exists($patch_file)) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}"; | ||||||
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file); | ||||||
$patch_str = FileSystem::convertPath($patch_file); | ||||||
|
||||||
// Copy patch from phar | ||||||
if (\Phar::running() !== '') { | ||||||
file_put_contents(SOURCE_PATH . '/' . $patch_name, file_get_contents($patch_file)); | ||||||
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, SOURCE_PATH . '/' . $patch_name); | ||||||
if (str_starts_with($patch_str, 'phar://')) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
$filename = pathinfo($patch_file, PATHINFO_BASENAME); | ||||||
file_put_contents(SOURCE_PATH . "/{$filename}", file_get_contents($patch_file)); | ||||||
$patch_str = FileSystem::convertPath(SOURCE_PATH . "/{$filename}"); | ||||||
} | ||||||
|
||||||
// detect | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The initial
file_exists($patch_file)
check makes the subsequentfile_exists($patch_str)
check redundant; consider removing one or consolidating the logic.Copilot uses AI. Check for mistakes.