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

Don't relocate Apple Silicon bottles for default prefix #19384

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Library/Homebrew/keg_relocate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def prepare_relocation_to_placeholders
alias generic_prepare_relocation_to_placeholders prepare_relocation_to_placeholders

def replace_locations_with_placeholders
# Skip relocation for Apple Silicon with default prefix
return [] if Utils::Bottles.skip_relocation_for_apple_silicon?


relocation = prepare_relocation_to_placeholders.freeze
relocate_dynamic_linkage(relocation)
replace_text_in_files(relocation)
Expand All @@ -125,7 +129,11 @@ def prepare_relocation_to_locations
end
alias generic_prepare_relocation_to_locations prepare_relocation_to_locations

def replace_placeholders_with_locations(files, skip_linkage: false)
def replace_placeholders_with_locations(files = nil, skip_linkage: false)
# Skip relocation for Apple Silicon with default prefix
return if Utils::Bottles.skip_relocation_for_apple_silicon?


relocation = prepare_relocation_to_locations.freeze
relocate_dynamic_linkage(relocation) unless skip_linkage
replace_text_in_files(relocation, files:)
Expand Down
27 changes: 26 additions & 1 deletion Library/Homebrew/test/utils/bottles/bottles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,29 @@ class #{Formulary.class_s(formula_name)} < Formula
end
end
end
end

describe "#skip_relocation_for_apple_silicon?" do
it "returns true for Apple Silicon with default prefix by default" do
allow(Hardware::CPU).to receive(:arm?).and_return(true)
allow(OS).to receive(:mac?).and_return(true)
allow(HOMEBREW_PREFIX).to receive(:to_s).and_return(HOMEBREW_MACOS_ARM_DEFAULT_PREFIX)
allow(ENV).to receive(:fetch).with("HOMEBREW_BOTTLE_SKIP_RELOCATION_ARM64", "false").and_return("true")

expect(described_class.skip_relocation_for_apple_silicon?).to be true
end

it "returns false for Intel Mac" do
allow(Hardware::CPU).to receive(:arm?).and_return(false)
allow(OS).to receive(:mac?).and_return(true)

expect(described_class.skip_relocation_for_apple_silicon?).to be false
end

it "returns false for custom prefix on Apple Silicon" do
allow(Hardware::CPU).to receive(:arm?).and_return(true)
allow(OS).to receive(:mac?).and_return(true)
allow(HOMEBREW_PREFIX).to receive(:to_s).and_return("/custom/path")

expect(described_class.skip_relocation_for_apple_silicon?).to be false
end
end
11 changes: 11 additions & 0 deletions Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ def load_tab(formula)
end
end

# Determines if bottle relocation should be skipped for Apple Silicon with default prefix
sig { returns(T::Boolean) }
def skip_relocation_for_apple_silicon?
return false unless Hardware::CPU.arm?
return false unless OS.mac?
return false unless HOMEBREW_PREFIX.to_s == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX

# Allow gradual rollout via environment variable
ENV.fetch("HOMEBREW_BOTTLE_SKIP_RELOCATION_ARM64", "false") == "true"
end

private

def bottle_file_list(bottle_file)
Expand Down
Loading