codeigniter4-patches icon indicating copy to clipboard operation
codeigniter4-patches copied to clipboard

`$PATH` is changed during `patch` execution

Open kenjis opened this issue 2 years ago • 5 comments

This may be an issue on macOS, $PATH is changed in src/patch. So it may change the php binary version, and may install unexpected versions of the packages.

In my case, I have both /usr/local/opt/[email protected]/bin/php (8.2) and /usr/local/bin/php (8.3). I expect that PHP 8.2 is used, but patch uses PHP 8.3.

  • OS: macOS 12.7.2
  • Shell: bash
$ vendor/bin/patch
bin/patch
/usr/local/opt/[email protected]/bin:/usr/local/opt/curl/bin:/usr/local/opt/openldap/sbin:/usr/local/opt/openldap/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/sbin:/usr/local/opt/[email protected]/bin:./vendor/bin:/Users/kenji/.composer/vendor/bin:/Users/kenji/.nodebrew/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/kenji/bin

src/patch
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/curl/bin:/usr/local/opt/openldap/sbin:/usr/local/opt/openldap/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/sbin:/usr/local/opt/[email protected]/bin:./vendor/bin:/Users/kenji/.composer/vendor/bin:/Users/kenji/.nodebrew/current/bin:/Users/kenji/bin
--- vendor/bin/patch.bk	2023-09-29 13:02:52.000000000 +0900
+++ vendor/bin/patch	2024-01-21 13:37:11.000000000 +0900
@@ -1,5 +1,9 @@
 #!/usr/bin/env sh
 
+echo "bin/patch"
+echo $PATH
+echo
+
 # Support bash to support `source` with fallback on $0 if this does not run with bash
 # https://stackoverflow.com/a/35006505/6512
 selfArg="$BASH_SOURCE"
--- vendor/tatter/patches/src/patch.bk	2023-09-26 21:23:22.000000000 +0900
+++ vendor/tatter/patches/src/patch	2024-01-21 13:37:04.000000000 +0900
@@ -1,5 +1,9 @@
 #!/bin/sh -l
 
+echo "src/patch"
+echo $PATH
+exit
+
 ##
 # Tatter\Patches
 # https://github.com/tattersoftware/codeigniter4-patches

kenjis avatar Jan 21 '24 04:01 kenjis

Interesting. I took a quick look at this in the same way on a RH-flavor Linux install and my PATHs are not rearranged like you're describing.

bin/patch
/root/.vscode-server/bin/8b3775030ed1a69b13e4f4c628c612102e30a681/bin/remote-cli:/root/.nvm/versions/node/v13.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

src/patch
/root/.vscode-server/bin/8b3775030ed1a69b13e4f4c628c612102e30a681/bin/remote-cli:/root/.nvm/versions/node/v13.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Unfortunately I don't have a Mac to look into this further on that end.

whoisninjaturtle avatar Feb 06 '24 08:02 whoisninjaturtle

Hmm it's probably the Login directive:

#!/bin/sh -l

Maybe it doesn't play well with Composer's script wrapping?

MGatner avatar Feb 08 '24 03:02 MGatner

I noticed that change and wondered myself too. I did look closely at the two given PATHs and they are simply just rearranged, not actually different in content, which makes me think it's a sourcing order issue

whoisninjaturtle avatar Feb 08 '24 03:02 whoisninjaturtle

I guess macOS does something.

kenjis avatar Feb 08 '24 04:02 kenjis

More to your original point, it would seem advantageous in multi-version environments to be able to pass the desired PHP executable path into patch via CLI option

whoisninjaturtle avatar Feb 08 '24 04:02 whoisninjaturtle