Skip to content

Keg relocation doesn't account for uses_from_macos when replacing #!@@HOMEBREW_<language>@@ shebangs #20023

Open
@botantony

Description

@botantony

brew doctor output

Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • 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>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions