From 49de2b0c1ae56d31d5c59dc42c292475f57d4344 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 11 Nov 2021 17:30:02 +0800 Subject: [PATCH] Check arch instead of the brand string --- Library/Homebrew/brew.sh | 18 +++++++++++++----- Library/Homebrew/cmd/vendor-install.sh | 7 ++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index daa0874b3c..b12933979a 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -6,6 +6,7 @@ # Doesn't need a default case because we don't support other OSs # shellcheck disable=SC2249 HOMEBREW_PROCESSOR="$(uname -m)" +HOMEBREW_PHYSICAL_PROCESSOR="${HOMEBREW_PROCESSOR}" HOMEBREW_SYSTEM="$(uname -s)" case "${HOMEBREW_SYSTEM}" in Darwin) HOMEBREW_MACOS="1" ;; @@ -17,12 +18,19 @@ esac # same file under the native architecture # These variables are set from the user environment. # shellcheck disable=SC2154 -if [[ "${HOMEBREW_CHANGE_ARCH_TO_ARM}" == "1" ]] && - [[ "${HOMEBREW_MACOS}" == "1" ]] && - [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]] && - [[ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" == "1" ]] +if [[ "${HOMEBREW_MACOS}" == "1" ]] && + [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]] then - exec arch -arm64e "${HOMEBREW_BREW_FILE}" "$@" + # used in vendor-install.sh + # shellcheck disable=SC2034 + HOMEBREW_PHYSICAL_PROCESSOR="arm64" + HOMEBREW_ROSETTA="$(sysctl -n sysctl.proc_translated)" + + if [[ "${HOMEBREW_CHANGE_ARCH_TO_ARM}" == "1" ]] && + [[ "${HOMEBREW_ROSETTA}" == "1" ]] + then + exec arch -arm64e "${HOMEBREW_BREW_FILE}" "$@" + fi fi # Where we store built products; a Cellar in HOMEBREW_PREFIX (often /usr/local diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index b406fe0b36..4c76f8e856 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -14,15 +14,16 @@ VENDOR_DIR="${HOMEBREW_LIBRARY}/Homebrew/vendor" # Built from https://github.com/Homebrew/homebrew-portable-ruby. if [[ -n "${HOMEBREW_MACOS}" ]] then - if [[ "$(sysctl -n machdep.cpu.brand_string)" != "Apple"* ]] || + if [[ "${HOMEBREW_PHYSICAL_PROCESSOR}" == "x86_64" ]] || # Handle the case where /usr/local/bin/brew is run under arm64. # It's a x86_64 installation there (we refuse to install arm64 binaries) so # use a x86_64 Portable Ruby. - [[ "${HOMEBREW_PROCESSOR}" == "arm64" && "${HOMEBREW_PREFIX}" == "/usr/local" ]] + [[ "${HOMEBREW_PHYSICAL_PROCESSOR}" == "arm64" && "${HOMEBREW_PREFIX}" == "/usr/local" ]] then ruby_FILENAME="portable-ruby-2.6.8.yosemite.bottle.tar.gz" ruby_SHA="0cb1cc7af109437fe0e020c9f3b7b95c3c709b140bde9f991ad2c1433496dd42" - else + elif [[ "${HOMEBREW_PHYSICAL_PROCESSOR}" == "arm64" ]] + then ruby_FILENAME="portable-ruby-2.6.8.arm64_big_sur.bottle.tar.gz" ruby_SHA="f2d5cab5a4dd49e5b3de780a3cd0a1f61642fea247d1c25aa40cd43f1be290b5" fi