Skip to content
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

Fix Issue #401 - correctly apply multiple command line parameter flags for non-GNU patch #444

Closed

Conversation

arcanumbridge
Copy link

@amokato @mikeohara @mfb
Would you see if this version also fixes MacOS & FreeBSD? I've been only able to test on FreeBSD 13.1.

Copy link

@joelpittet joelpittet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition incorrect

// sniff if we're using GNU patch
$patchVersion = '';
$this->executor->execute('patch --version', $patchVersion);
if (strpos($patchVersion, 'GNU patch') === false) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should be !== because these options only work on GNU

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FreeBSD has a non-GNU patch (version is patch 2.0-12u11 FreeBSD) and definitely has both the --posix and --batch options: https://man.freebsd.org/cgi/man.cgi?patch(1)

Copy link
Author

@arcanumbridge arcanumbridge Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelpittet BSD patch in FreeBSD has these options too. I don't know why Apple wouldn't have at least pulled the latest version of patch from FreeBSD. Does the Ventura patch have --posix or --no-backup-if-mismatch? Are you able to send me a copy of the2.0-12u11-Apple patch man page and the output of the patch usage. I can replace --batch with '-t', but need a replacement for --posix or --no-backup-if-mismatch for the Apple patch case.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arcanumbridge On Ventura 13.2 it appears to have all the flags, so maybe not straightforward to "sniff"

$ patch --version
patch 2.0-12u11-Apple
$ man patch
NAME
     patch – apply a diff file to an original

SYNOPSIS
     patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]
           [-g vcs-option] [-F max-fuzz] [-i patchfile] [-o out-file]
           [-p strip-count] [-r rej-name] [-T | -Z] [-V t | nil | never | none]
           [-x number] [-Y prefix] [-z backup-ext] [--quoting-style style] [--posix]
           [origfile [patchfile]]
     patch <patchfile
...
     --no-backup-if-mismatch
             This option negates --backup-if-mismatch, creating backups for every
             file unless backups have been disabled with --posix or -V none.
     --posix
             Enables strict IEEE Std 1003.1-2008 (“POSIX.1”) conformance,
             specifically:

             1.   Backup files are not created unless the -b option is specified.

             2.   If unspecified, the file name used is the first of the old, new
                  and index files that exists.
     -t, --batch
             Similar to -f, in that it suppresses questions, but makes some
             different assumptions: skip patches for which a file to patch cannot be
             found (the same as -f); skip patches for which the file has the wrong
             version for the "Prereq": line in the patch; and assume that patches
             are reversed if they look like they are.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this looks like potentially good news, if at some point Apple updated their patch to the same version as FreeBSD?

@danepowell
Copy link
Collaborator

danepowell commented Feb 2, 2023

I don't see how this PR could fix #423 given that it's against master and I cannot reproduce #423 in master using the test case from #423 (comment)

Edit: nevermind... explanation in my next comment

@arcanumbridge arcanumbridge changed the title Fix Issue #401 & #423 - correctly apply multiple command line parameter flags for non-GNU patch Fix Issue #401 - correctly apply multiple command line parameter flags for non-GNU patch Feb 2, 2023
@arcanumbridge
Copy link
Author

@danepowell Since you can't reproduce in master, I've removed the Issue #423 from the title. I've updated the condition to at least not break when using Apple patch.

@danepowell
Copy link
Collaborator

danepowell commented Feb 2, 2023

Ignore my above comment, the reason master is not broken is because Git patching works before the patch utility can ever be called.

However: this PR still doesn't solve the problem in #423 on Ventura. If I check out this PR and delete the Git patching logic in master (forcing it to use the patch utility), patching still hangs awaiting input (using the latest commit ef86816). If I revert a78843a, patching errors immediately, which is better than hanging waiting for input, I suppose, but only marginally! 😄

@arcanumbridge
Copy link
Author

@mfb @cweagans I've rolled this back to just handle the FreeBSD / non-GNU case since we don't have enough info to handle the Apple patch case too. I think we're good to commit now unless you guys have anything else.

@arcanumbridge
Copy link
Author

@mfb @danepowell @cweagans I've done one more take at this. It will still probably fail on MacOS Ventura, but hopefully it doesn't stall out. I'm testing for gpatch, patch and erroring out if nothing is found and also still sniffing for gnu patch. We want to use gpatch if it's found since it might have better compatibility than the native OS patch.

@cweagans
Copy link
Owner

This is now extremely out of date. Can you please try the behavior in main and let me know if it works for you? We can reopen this if necessary, but main doesn't use patch at all now -- it's all just git + an escape hatch that you can use to apply patches however you'd like.

@cweagans cweagans closed this Feb 13, 2023
@arcanumbridge
Copy link
Author

arcanumbridge commented Feb 13, 2023 via email

@cweagans
Copy link
Owner

No, it's just one freeform config per patch. I'm not sure why you wouldn't have git installed on a build node, but it seems way easier to just standardize on a tool rather than trying to support a bunch of different combinations.

Also: In parallel to this work, I'm looking into #474. That could potentially be a path forward for you -- you could just rely on a known version of GNU patch that is installed along with your Composer dependencies. There are some caveats though: GNU patch doesn't support git-style binary patches, and because it's a reimplementation of the Git behaviors, there might be some differences between how patch handles patches and how git handles patches.

@cweagans
Copy link
Owner

There is also https://docs.cweagans.net/composer-patches/api/capabilities/ -- you could write a Resolver to apply your patches if you need custom OS-specific functionality.

I'd encourage you to look into the feasibility of installing git on your build nodes though. It seems like a much more straightforward proposition. If that's not possible, I'd love to understand why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants