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

Patching hangs on PHP 8.2+ on apple processors #13

Open
KorvinSzanto opened this issue Apr 14, 2023 · 10 comments · May be fixed by #14
Open

Patching hangs on PHP 8.2+ on apple processors #13

KorvinSzanto opened this issue Apr 14, 2023 · 10 comments · May be fixed by #14

Comments

@KorvinSzanto
Copy link
Contributor

KorvinSzanto commented Apr 14, 2023

My composer.json file is:

{
    "require": {
        "mlocati/composer-patcher": "^1.2",
        "wikimedia/less.php": "1.8.2"
    },
    "config": {
        "allow-plugins": {
            "mlocati/composer-patcher": true
        }
    },
    "extra": {
        "patches": {
            "wikimedia/less.php:1.8.2": {
                "Add PHP 8.2 compatibility": "wikimedia/less.php/fix-php-8.2-compatibility.patch"
            }
        }
    }
}

and I have placed this file at the place specified in composer.json.

The first time I run composer update I get the following successful output:

$ composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
  - Locking mlocati/composer-patcher (1.2.5)
  - Locking wikimedia/less.php (1.8.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing mlocati/composer-patcher (1.2.5): Extracting archive
  - Installing wikimedia/less.php (1.8.2): Extracting archive
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
Gathering patches from __root__ (extra.patches).
Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php... done.
No security vulnerability advisories found

Now if I run either composer update or composer install again, the output hangs at:

Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php...

and will hang indefinitely unless I either jam ctrl + c or press enter repeatedly. Pressing enter twice yields this output:

Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php...

Array to string conversion
No security vulnerability advisories found
@KorvinSzanto
Copy link
Contributor Author

KorvinSzanto commented Apr 14, 2023

With verbose output the hang looks like this:

Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php... Executing command (CWD): patch --version
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -N -d '/Users/korvin/projects/concrete5/test-composer-patcher/vendor/wikimedia/less.php' -i '/Users/korvin/projects/concrete5/test-composer-patcher/wikimedia/less.php/fix-php-8.2-compatibility.patch' -r '/private/var/folders/by/p20fzf4171z55k0jk9264mb40000gn/T/PCHIvDPlF/0.rej' --dry-run
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -N -d '/Users/korvin/projects/concrete5/test-composer-patcher/vendor/wikimedia/less.php' -i '/Users/korvin/projects/concrete5/test-composer-patcher/wikimedia/less.php/fix-php-8.2-compatibility.patch' -r '/private/var/folders/by/p20fzf4171z55k0jk9264mb40000gn/T/PCHIvDPlF/1.rej'
Executing command (CWD): patch '-p0' --no-backup-if-mismatch -N -d '/Users/korvin/projects/concrete5/test-composer-patcher/vendor/wikimedia/less.php' -i '/Users/korvin/projects/concrete5/test-composer-patcher/wikimedia/less.php/fix-php-8.2-compatibility.patch' -r '/private/var/folders/by/p20fzf4171z55k0jk9264mb40000gn/T/PCHIvDPlF/2.rej' --dry-run

And if I press enter twice:


Array to string conversion
No patches found for __root__.

If I run that last command that's hanging manually it looks to prompt me for a file, but that could just be because it's happening out of sync. Here's what it looks like when I run it and hit enter twice:

$ patch '-p0' --no-backup-if-mismatch -N -d '/Users/korvin/projects/concrete5/test-composer-patcher/vendor/wikimedia/less.php' -i '/Users/korvin/projects/concrete5/test-composer-patcher/wikimedia/less.php/fix-php-8.2-compatibility.patch' -r '/private/var/folders/by/p20fzf4171z55k0jk9264mb40000gn/T/PCHIvDPlF/2.rej' --dry-run
File to patch:
No file found--skip this patch? [y]
zsh: segmentation fault  patch '-p0' --no-backup-if-mismatch -N -d  -i  -r  --dry-run

@mlocati
Copy link
Owner

mlocati commented Apr 14, 2023

I think that the problem is that the dependency patcher relies on the GNU implementation of the patch command, whereas Mac computers come with the BSD version of it.

While I'll try to find some time to find a solution, I think that the issue could be fixed by running

# Install the GNU version of the patch command
brew install gpatch
# Instruct the system to use the GNU version of the patch command by default
brew link gpatch --force --overwrite

@KorvinSzanto
Copy link
Contributor Author

You are correct, I didn't need to force the overwrite, it was enough to just brew install gpatch.

@mlocati mlocati linked a pull request Apr 20, 2023 that will close this issue
@mlocati
Copy link
Owner

mlocati commented Apr 20, 2023

@KorvinSzanto Could you check if #14 fixes the issue when using the standard patch command available on Mac?

@KorvinSzanto
Copy link
Contributor Author

@mlocati Looks like the fix doesn't work. I used the same sample composer.json as above except I:

  1. Unlinked gpatch with brew unlink gpatch
  2. Changed the requirement for mlocati/composer-patcher to dev-bsd-patch
  3. Deleted composer.lock and vendor
  4. Ran composer install, first run is fine
  5. Ran composer install again, hangs.

@mlocati
Copy link
Owner

mlocati commented Apr 27, 2023

I managed to access a Mac, and checked the patch command:

Ubuntu 22.04 FreeBSD 13.2 Mac OS X 13.3
First line of patch -v GNU patch 2.7.6 patch 2.0-12u11 FreeBSD patch 2.0-12u11-Apple
man patch See here See here Same as FreeBSD, with the additional options --backup-if-mismatch, --no-backup-if-mismatch, -g, --quoting-style, -T, -Y, -Z

So, I've updated #14 and the code in the bsd-patch branch should work now.

@KorvinSzanto
Copy link
Contributor Author

I retried my steps from my last comment and I'm still seeing the same hanging behavior, it works the first time but then subsequent installs where the patch is already applied hang. I'm definitely getting the 127a4b9 commit as shown by my output:

$ composer install
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
  - Locking mlocati/composer-patcher (dev-bsd-patch 127a4b9)
  - Locking wikimedia/less.php (1.8.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing mlocati/composer-patcher (dev-bsd-patch 127a4b9): Extracting archive
  - Installing wikimedia/less.php (1.8.2): Extracting archive
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
Gathering patches from __root__ (extra.patches).
Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php... done.

$ composer install
Gathering patches from __root__ (extra.patches).
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
Gathering patches from __root__ (extra.patches).
Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php..

@mlocati
Copy link
Owner

mlocati commented Apr 29, 2023

On Mac OS X 10.15.7, the output of patch -v is

patch 2.5.8
Copyright (C) 1988 Larry Wall
Copyright (C) 2002 Free Software Foundation, Inc.

This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

written by Larry Wall and Paul Eggert

So, there's no (or there may be not) Apple in the first line.

So, I guess that the best choice we have in order to detect the patch flavour is to inspect the output of patch --help, which is

Usage: patch [OPTION]... [ORIGFILE [PATCHFILE]]

Input options:

  -p NUM  --strip=NUM  Strip NUM leading components from file names.
  -F LINES  --fuzz LINES  Set the fuzz factor to LINES for inexact matching.
  -l  --ignore-whitespace  Ignore white space changes between patch and input.

  -c  --context  Interpret the patch as a context difference.
  -e  --ed  Interpret the patch as an ed script.
  -n  --normal  Interpret the patch as a normal difference.
  -u  --unified  Interpret the patch as a unified difference.

  -N  --forward  Ignore patches that appear to be reversed or already applied.
  -R  --reverse  Assume patches were created with old and new files swapped.

  -i PATCHFILE  --input=PATCHFILE  Read patch from PATCHFILE instead of stdin.

Output options:

  -o FILE  --output=FILE  Output patched files to FILE.
  -r FILE  --reject-file=FILE  Output rejects to FILE.

  -D NAME  --ifdef=NAME  Make merged if-then-else output using NAME.
  -E  --remove-empty-files  Remove output files that are empty after patching.

  -Z  --set-utc  Set times of patched files, assuming diff uses UTC (GMT).
  -T  --set-time  Likewise, assuming local time.

  --quoting-style=WORD   output file names using quoting style WORD.
    Valid WORDs are: literal, shell, shell-always, c, escape.
    Default is taken from QUOTING_STYLE env variable, or 'shell' if unset.

Backup and version control options:

  -b  --backup  Back up the original contents of each file.
  --backup-if-mismatch  Back up if the patch does not match exactly.
  --no-backup-if-mismatch  Back up mismatches only if otherwise requested.

  -V STYLE  --version-control=STYLE  Use STYLE version control.
	STYLE is either 'simple', 'numbered', or 'existing'.
  -B PREFIX  --prefix=PREFIX  Prepend PREFIX to backup file names.
  -Y PREFIX  --basename-prefix=PREFIX  Prepend PREFIX to backup file basenames.
  -z SUFFIX  --suffix=SUFFIX  Append SUFFIX to backup file names.

  -g NUM  --get=NUM  Get files from RCS etc. if positive; ask if negative.

Miscellaneous options:

  -t  --batch  Ask no questions; skip bad-Prereq patches; assume reversed.
  -f  --force  Like -t, but ignore bad-Prereq patches, and assume unreversed.
  -s  --quiet  --silent  Work silently unless an error occurs.
  --verbose  Output extra information about the work being done.
  --dry-run  Do not actually change any files; just print what would happen.
  --posix  Conform to the POSIX standard.

  -d DIR  --directory=DIR  Change the working directory to DIR first.
  --binary  Read and write data in binary mode (no effect on this platform).

  -v  --version  Output version info.
  --help  Output this help.

Report bugs to <bug-patch@gnu.org>.

I'll try to add support for this.

@mlocati
Copy link
Owner

mlocati commented Apr 30, 2023

Changed the requirement for mlocati/composer-patcher to dev-bsd-patch

@KorvinSzanto Could you try if the last code in the bsd-patch branch works for you? I can't replicate your issue even on a Mac (10.15.7), but I've updated #14 with a potential fix.

@KorvinSzanto
Copy link
Contributor Author

With the latest version of that branch I get the following output with no hangs:

Gathering patches from __root__ (extra.patches).
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
Gathering patches from __root__ (extra.patches).
Applying patch __root__/Add PHP 8.2 compatibility to wikimedia/less.php... Unable to apply the patch "Add PHP 8.2 compatibility" provided by "__root__": failed to apply the patch with the patch command: patching file 'lib/Less/Tree.php'
Ignoring previously applied (or reversed) patch.
1 out of 1 hunks ignored--saving rejects to '/private/var/folders/by/p20fzf4171z55k0jk9264mb40000gn/T/PCHmtFtft/1.rej'
patching file 'lib/Less/Tree/Ruleset.php'
Ignoring previously applied (or reversed) patch.
1 out of 1 hunks ignored--saving rejects to 'lib/Less/Tree/Ruleset.php.rej'

Honestly just using the brew version of gpatch is fine for my workflow

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 a pull request may close this issue.

2 participants