-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Check flavour to prevent mixed architectures #9126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,18 @@ git_init_if_necessary() { | |
trap - EXIT | ||
fi | ||
|
||
if [[ -n "${HOMEBREW_MACOS_VERSION}" ]] && | ||
[[ -z "$(git config --get homebrew.flavour 2>/dev/null)" ]] | ||
then | ||
if [[ "${HOMEBREW_PREFIX}" = "${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}" ]]; then | ||
git config --replace-all homebrew.flavour "arm64" 2>/dev/null | ||
elif [[ "${HOMEBREW_PREFIX}" = "${HOMEBREW_DEFAULT_PREFIX}" ]]; then | ||
git config --replace-all homebrew.flavour "x86_64" 2>/dev/null | ||
else | ||
git config --replace-all homebrew.flavour "$(uname -m)" 2>/dev/null | ||
fi | ||
fi | ||
Comment on lines
+48
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
[[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] || return | ||
safe_cd "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" | ||
if [[ ! -d ".git" ]] | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ module Install | |||||||||||||
module_function | ||||||||||||||
|
||||||||||||||
def perform_preinstall_checks(all_fatal: false, cc: nil) | ||||||||||||||
check_prefix | ||||||||||||||
check_flavour_matches_architecture | ||||||||||||||
check_cpu | ||||||||||||||
attempt_directory_creation | ||||||||||||||
check_cc_argv(cc) | ||||||||||||||
|
@@ -29,19 +29,44 @@ def perform_build_from_source_checks(all_fatal: false) | |||||||||||||
Diagnostic.checks(:build_from_source_checks, fatal: all_fatal) | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
def check_prefix | ||||||||||||||
if Hardware::CPU.intel? && HOMEBREW_PREFIX.to_s == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX | ||||||||||||||
odie "Cannot install in Homebrew on Intel processor in ARM default prefix (#{HOMEBREW_PREFIX})!" | ||||||||||||||
elsif Hardware::CPU.arm? && HOMEBREW_PREFIX.to_s == HOMEBREW_DEFAULT_PREFIX | ||||||||||||||
odie <<~EOS | ||||||||||||||
Cannot install in Homebrew on ARM processor in Intel default prefix (#{HOMEBREW_PREFIX})! | ||||||||||||||
Please create a new installation in #{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX} using one of the | ||||||||||||||
"Alternative Installs" from: | ||||||||||||||
#{Formatter.url("https://docs.brew.sh/Installation")} | ||||||||||||||
You can migrate your previously installed formula list with: | ||||||||||||||
brew bundle dump | ||||||||||||||
def check_flavour_matches_architecture | ||||||||||||||
homebrew_flavour = HOMEBREW_REPOSITORY.cd do | ||||||||||||||
Utils.popen_read("git", "config", "--get", "homebrew.flavour").chomp.presence | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could consider passing this as a global variable, too, so it only needs read once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that in my first draft, which:
I removed it after your comment that said:
That environment variable wasn’t user configuration. It was read-only, would be set by Homebrew, ignoring whatever its initial value is. Its purpose was to pass it as a global variable so it only needs to be read once. I removed it anyway according to your request. So you’d prefer me to add that variable back, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I didn't request you remove it, I requested we avoid it being user configurable as it wasn't clear from the proposal whether it would be or not.
Yes, I think it would be worth considering if it aligns with the fix for #9126 (comment) #9126 (comment) is another global variable that should be passed from Bash into Ruby to avoid duplication if it's needed there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MikeMcQuaid Ok, thanks. Will look for the old commit, restore it and apply your suggestions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||||||||||||||
end | ||||||||||||||
|
||||||||||||||
if !homebrew_flavour || | ||||||||||||||
(Hardware::CPU.intel? && homebrew_flavour == "x86_64") || | ||||||||||||||
(Hardware::CPU.arm? && homebrew_flavour == "arm64") | ||||||||||||||
return | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
error_title = "This Homebrew installation in #{HOMEBREW_PREFIX} only works on #{homebrew_flavour} processors." | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
odie error_title unless Hardware::CPU.arm? | ||||||||||||||
|
||||||||||||||
ohai "Checking whether Rosetta is installed" | ||||||||||||||
rosetta_installed = quiet_system( | ||||||||||||||
"/usr/bin/swift", | ||||||||||||||
"#{HOMEBREW_REPOSITORY}/Library/Homebrew/utils/rosetta_installed.swift", | ||||||||||||||
) | ||||||||||||||
rosetta_instructions = if rosetta_installed | ||||||||||||||
<<~EOS | ||||||||||||||
To use it, you can: | ||||||||||||||
- run your Terminal from Rosetta 2 or | ||||||||||||||
- run 'arch -x86_64 brew' instead of 'brew'. | ||||||||||||||
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
the inline |
||||||||||||||
EOS | ||||||||||||||
else | ||||||||||||||
"To use it, you need to install Rosetta 2 first." | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
odie <<~EOS | ||||||||||||||
#{error_title} | ||||||||||||||
#{rosetta_instructions} | ||||||||||||||
Or create a new installation in #{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX} using one of the | ||||||||||||||
"Alternative Installs" from: | ||||||||||||||
#{Formatter.url("https://docs.brew.sh/Installation")} | ||||||||||||||
You can migrate your previously installed formula list with: | ||||||||||||||
brew bundle dump | ||||||||||||||
EOS | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
def check_cpu | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/swift | ||
|
||
import CoreFoundation | ||
exit(CFBundleIsArchitectureLoadable(CPU_TYPE_X86_64) ? 0 : 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these stay around given other comments after this:
global.rb
so that their definitions aren't duplicated