From 43d10940b9625876098693ee483ee283958b5575 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:32:05 +0800 Subject: [PATCH 1/3] Revert "Revert "cmd/shellenv: improve for newer macOS using `/usr/libexec/path_helper`"" --- Library/Homebrew/brew.sh | 11 +++++++---- Library/Homebrew/cmd/shellenv.sh | 31 +++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 136da511f963f..2ab0d5ccca982 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -54,6 +54,13 @@ then HOMEBREW_DEFAULT_CACHE="${HOME}/Library/Caches/Homebrew" HOMEBREW_DEFAULT_LOGS="${HOME}/Library/Logs/Homebrew" HOMEBREW_DEFAULT_TEMP="/private/tmp" + + HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)" + + IFS=. read -r -a MACOS_VERSION_ARRAY <<<"${HOMEBREW_MACOS_VERSION}" + printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" "${MACOS_VERSION_ARRAY[@]}" + + unset MACOS_VERSION_ARRAY else CACHE_HOME="${HOMEBREW_XDG_CACHE_HOME:-${HOME}/.cache}" HOMEBREW_DEFAULT_CACHE="${CACHE_HOME}/Homebrew" @@ -523,7 +530,6 @@ then HOMEBREW_PRODUCT="Homebrew" HOMEBREW_SYSTEM="Macintosh" [[ "${HOMEBREW_PROCESSOR}" == "x86_64" ]] && HOMEBREW_PROCESSOR="Intel" - HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)" # Don't change this from Mac OS X to match what macOS itself does in Safari on 10.12 HOMEBREW_OS_USER_AGENT_VERSION="Mac OS X ${HOMEBREW_MACOS_VERSION}" @@ -534,9 +540,6 @@ then HOMEBREW_PHYSICAL_PROCESSOR="arm64" fi - IFS=. read -r -a MACOS_VERSION_ARRAY <<<"${HOMEBREW_MACOS_VERSION}" - printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" "${MACOS_VERSION_ARRAY[@]}" - IFS=. read -r -a MACOS_VERSION_ARRAY <<<"${HOMEBREW_MACOS_OLDEST_ALLOWED}" printf -v HOMEBREW_MACOS_OLDEST_ALLOWED_NUMERIC "%02d%02d%02d" "${MACOS_VERSION_ARRAY[@]}" diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index 3070a10b02ecf..a4af9b9a7219d 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -18,6 +18,23 @@ homebrew-shellenv() { HOMEBREW_SHELL_NAME="$(/bin/ps -p "${PPID}" -c -o comm=)" fi + if [[ -n "${HOMEBREW_MACOS}" ]] && + [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -ge "140000" ]] && + [[ -x /usr/libexec/path_helper ]] + then + HOMEBREW_PATHS_FILE="${HOMEBREW_PREFIX}/etc/paths" + + if [[ ! -f "${HOMEBREW_PATHS_FILE}" ]] + then + printf '%s/bin\n%s/sbin\n' "${HOMEBREW_PREFIX}" "${HOMEBREW_PREFIX}" >"${HOMEBREW_PATHS_FILE}" 2>/dev/null + fi + + if [[ -r "${HOMEBREW_PATHS_FILE}" ]] + then + PATH_HELPER_ROOT="${HOMEBREW_PREFIX}" + fi + fi + case "${HOMEBREW_SHELL_NAME}" in fish | -fish) echo "set -gx HOMEBREW_PREFIX \"${HOMEBREW_PREFIX}\";" @@ -31,7 +48,12 @@ homebrew-shellenv() { echo "setenv HOMEBREW_PREFIX ${HOMEBREW_PREFIX};" echo "setenv HOMEBREW_CELLAR ${HOMEBREW_CELLAR};" echo "setenv HOMEBREW_REPOSITORY ${HOMEBREW_REPOSITORY};" - echo "setenv PATH ${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:\$PATH;" + if [[ -n "${PATH_HELPER_ROOT}" ]] + then + echo "eval \`/usr/bin/env PATH_HELPER_ROOT=\"${PATH_HELPER_ROOT}\" /usr/libexec/path_helper -c\`;" + else + echo "setenv PATH ${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:\$PATH;" + fi echo "test \${?MANPATH} -eq 1 && setenv MANPATH :\${MANPATH};" echo "setenv INFOPATH ${HOMEBREW_PREFIX}/share/info\`test \${?INFOPATH} -eq 1 && echo :\${INFOPATH}\`;" ;; @@ -47,7 +69,12 @@ homebrew-shellenv() { echo "export HOMEBREW_PREFIX=\"${HOMEBREW_PREFIX}\";" echo "export HOMEBREW_CELLAR=\"${HOMEBREW_CELLAR}\";" echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" - echo "export PATH=\"${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin\${PATH+:\$PATH}\";" + if [[ -n "${PATH_HELPER_ROOT}" ]] + then + echo "eval \"\$(PATH_HELPER_ROOT=\"${PATH_HELPER_ROOT}\" /usr/libexec/path_helper -s)\"" + else + echo "export PATH=\"${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin\${PATH+:\$PATH}\";" + fi echo "[ -z \"\${MANPATH-}\" ] || export MANPATH=\":\${MANPATH#:}\";" echo "export INFOPATH=\"${HOMEBREW_PREFIX}/share/info:\${INFOPATH:-}\";" ;; From c9ca7e3257f70e7f6cce2a6237137574371b1196 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:34:34 +0800 Subject: [PATCH 2/3] cmd/shellenv: output the result of `path_helper` instead This will save the indirection of `eval`. --- Library/Homebrew/cmd/shellenv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index a4af9b9a7219d..21cab35a263b7 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -50,7 +50,7 @@ homebrew-shellenv() { echo "setenv HOMEBREW_REPOSITORY ${HOMEBREW_REPOSITORY};" if [[ -n "${PATH_HELPER_ROOT}" ]] then - echo "eval \`/usr/bin/env PATH_HELPER_ROOT=\"${PATH_HELPER_ROOT}\" /usr/libexec/path_helper -c\`;" + PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" /usr/libexec/path_helper -c else echo "setenv PATH ${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:\$PATH;" fi @@ -71,7 +71,7 @@ homebrew-shellenv() { echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" if [[ -n "${PATH_HELPER_ROOT}" ]] then - echo "eval \"\$(PATH_HELPER_ROOT=\"${PATH_HELPER_ROOT}\" /usr/libexec/path_helper -s)\"" + PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" /usr/libexec/path_helper -s else echo "export PATH=\"${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin\${PATH+:\$PATH}\";" fi From 9d60472090d8c240997f6963e437f763c94f0bba Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 2 Sep 2024 21:12:36 +0800 Subject: [PATCH 3/3] shellenv: retain user `PATH` This is filtered in `brew`, so we need to manually set this to `HOMEBREW_PATH`. --- Library/Homebrew/cmd/shellenv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index 21cab35a263b7..bd4f915b73a02 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -50,7 +50,7 @@ homebrew-shellenv() { echo "setenv HOMEBREW_REPOSITORY ${HOMEBREW_REPOSITORY};" if [[ -n "${PATH_HELPER_ROOT}" ]] then - PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" /usr/libexec/path_helper -c + PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" PATH="${HOMEBREW_PATH}" /usr/libexec/path_helper -c else echo "setenv PATH ${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:\$PATH;" fi @@ -71,7 +71,7 @@ homebrew-shellenv() { echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" if [[ -n "${PATH_HELPER_ROOT}" ]] then - PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" /usr/libexec/path_helper -s + PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" PATH="${HOMEBREW_PATH}" /usr/libexec/path_helper -s else echo "export PATH=\"${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin\${PATH+:\$PATH}\";" fi