-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Check if GNU patch is used #426
Closed
Closed
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -443,6 +443,14 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, | |
// differences between how patch works on windows and unix. | ||
$patch_options = '--no-backup-if-mismatch'; | ||
if (PHP_OS_FAMILY == 'BSD') { | ||
$patchVersion = ''; | ||
$this->executor->execute('patch --version', $patchVersion); | ||
if (strpos($patchBinaryVersion, 'GNU patch') === false) { | ||
throw new \Exception( | ||
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. The intention here should be for non-GNU versions of patch to actually work! :) Please review the PR at #402 where we try to get the non-GNU patch working (with a pretty trivial fix). |
||
"Please make sure to have GNU patch installed, see " | ||
. "https://github.com/cweagans/composer-patches/wiki/Install-%22patch%22-binary" | ||
); | ||
} | ||
$patch_options = '--posix --batch'; | ||
} | ||
foreach ($patch_levels as $patch_level) { | ||
|
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.
This won't work reliably because PHP_OS_FAMILY reflect the build target for the running PHP version, not the current hosting environment. In my case on MacOS Ventura, for whatever reason, PHP_OS_FAMILY is Linux. See https://github.com/loophp/phposinfo, but I don't know that we want to introduce a new dependency just for this.
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.
I think what you're saying is the PHP documentation is wrong: When it says "The operating system family PHP was built for" what they actually mean is "The operating system family PHP was built on"? If so, uhg..
So maybe looking at patch --version is correct after all, although all the logic needed there might not be pretty.
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.
Yeah the only semi-reliable way to detect runtime OS is php_uname, but even that will fall back to displaying the build OS in some situations. I found the phposinfo library to do a pretty good job of compensating for this by using a combination of php_uname, PHP_OS_FAMILY, and shell commands to verify the OS version.
It's obviously better to avoid any conditional logic based on the OS in the first place.