Keg relocation doesn't account for `uses_from_macos` when replacing `#!@@HOMEBREW_<language>@@` shebangs
brew doctor output
Your system is ready to brew.
Verification
- [x] My "
brew doctoroutput" above saysYour system is ready to brew.and am still able to reproduce my issue. - [x] I ran
brew updatetwice and am still able to reproduce my issue. - [x] This issue's title and/or description do not reference a single formula e.g.
brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.
brew config output
HOMEBREW_VERSION: 4.5.3-24-gfe3783d
ORIGIN: https://github.com/Homebrew/brew
HEAD: fe3783d71170f82d1972a4607a02743bf31b6bbf
Last commit: 22 hours ago
Branch: master
Core tap HEAD: 5781dd56dbf1c91d1b564926309419ed3cb6f49d
Core tap last commit: 65 minutes ago
Core tap JSON: 28 May 14:47 UTC
Core cask tap HEAD: d6815b1a22b7fd81cd0db066c986a02420fa1298
Core cask tap last commit: 62 minutes ago
Core cask tap JSON: 28 May 14:47 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.tm1kqu39ox/org.xquartz:0
HOMEBREW_EDITOR: nvim
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_NO_ENV_HINTS: set
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.4.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.4/bin/ruby
CPU: octa-core 64-bit arm_blizzard_avalanche
Clang: 17.0.0 build 1700
Git: 2.49.0 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.4.1-arm64
CLT: 16.3.0.0.1.1742442376
Xcode: 16.3
Rosetta 2: false
What were you trying to do (and why)?
A user wanted to install ack formula which should work normally with system's Perl, but it replaced shebang with /opt/homebrew/opt/ack/bin/ack (see the original issue Homebrew/homebrew-core#224886)
What happened (include all command output)?
brew install ack
The installed ack binary with shebang on top used #!/opt/homebrew/opt/ack/bin/ack instead of #!/usr/bin/perl<whatever version>
What did you expect to happen?
Perl scripts with uses_from_macos "perl" should use #!/usr/bin/perl<whatever version> instead of #!<Homebrew prefix here>/opt/perl/bin/perl
It looks like someone tried to account for this behavior but it doesn't work correctly: https://github.com/Homebrew/brew/blob/fe3783d71170f82d1972a4607a02743bf31b6bbf/Library/Homebrew/extend/os/mac/keg_relocate.rb#L204C93-L218
Step-by-step reproduction instructions (by running brew commands)
# On your mac:
brew install ack # an example of perl formula that uses `uses_from_macos "perl"`
# and has `all:` bottle (with `#!@@HOMEBREW_PERL@@`)
head -1 "${HOMEBREW_PREFIX}/bin/ack"
# it uses `#!<Homebrew prefix here>/opt/perl/bin/perl` instead of `#!/usr/bin/perl<whatever version>`
The problem is likely from it being an all bottle and it happened to pick up the Linux tab when creating it and is using that when installing on macOS. The code likely works fine for non-all bottles that retain the correct tab.
all bottles probably should use /usr/bin/env perl always.
@Bo98 not sure if it can be fixed that way. F.e. there is mhonarc formula which depends on Perl from Homebrew but has all bottle. I tried to modify the formula to use system's Perl but it fails with "missing libraries" error (however I'm not Perl expert, if it's possible to stop relying on Homebrew Perl it would be nice)
Oh right, yeah that one has depends_on. Usually the tab contains this information but this information isn't available for all bottles so might require some work on the tab system.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.