Restore handling of HOMEBREW_BREW_WRAPPER

This now requires `HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER` to be unset.
If it is set (but only in a `brew.env` file), then we use the new
functionality of checking the path of the parent process.
This commit is contained in:
Carlo Cabrera 2025-08-13 14:37:11 +08:00 committed by Carlo Cabrera
parent 144c7f6edf
commit b7d8072575
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 50 additions and 3 deletions

View File

@ -190,10 +190,54 @@ esac
# Include some helper functions.
source "${HOMEBREW_LIBRARY}/Homebrew/utils/helpers.sh"
# If HOMEBREW_FORCE_BREW_WRAPPER is set, verify that the path to our parent
# process is the same as the value of HOMEBREW_FORCE_BREW_WRAPPER for all
# Require HOMEBREW_BREW_WRAPPER to be set if HOMEBREW_FORCE_BREW_WRAPPER is set
# (and HOMEBREW_NO_FORCE_BREW_WRAPPER and HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER are not set)
# for all non-trivial commands (i.e. not defined above this line e.g. formulae or --cellar).
if [[ -z "${HOMEBREW_NO_FORCE_BREW_WRAPPER:-}" && -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" &&
-z "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" ]]
then
HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW="${HOMEBREW_FORCE_BREW_WRAPPER%/brew}"
if [[ -z "${HOMEBREW_BREW_WRAPPER:-}" ]]
then
# HOMEBREW_ORIGINAL_BREW_FILE set by bin/brew
# shellcheck disable=SC2154
odie <<EOS
conflicting Homebrew wrapper configuration!
HOMEBREW_FORCE_BREW_WRAPPER was set to ${HOMEBREW_FORCE_BREW_WRAPPER}
but HOMEBREW_BREW_WRAPPER was unset.
$(bold "Ensure you run ${HOMEBREW_FORCE_BREW_WRAPPER} directly (not ${HOMEBREW_ORIGINAL_BREW_FILE})")!
Manually setting your PATH can interfere with Homebrew wrappers.
Ensure your shell configuration contains:
eval "\$(${HOMEBREW_BREW_FILE} shellenv)"
or that ${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW} comes before ${HOMEBREW_PREFIX}/bin in your PATH:
export PATH="${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW}:${HOMEBREW_PREFIX}/bin:\$PATH"
EOS
elif [[ "${HOMEBREW_FORCE_BREW_WRAPPER}" != "${HOMEBREW_BREW_WRAPPER}" ]]
then
# HOMEBREW_ORIGINAL_BREW_FILE set by bin/brew
# shellcheck disable=SC2154
odie <<EOS
conflicting Homebrew wrapper configuration!
HOMEBREW_FORCE_BREW_WRAPPER was set to ${HOMEBREW_FORCE_BREW_WRAPPER}
but HOMEBREW_BREW_WRAPPER was set to ${HOMEBREW_BREW_WRAPPER}
$(bold "Ensure you run ${HOMEBREW_FORCE_BREW_WRAPPER} directly (not ${HOMEBREW_ORIGINAL_BREW_FILE})")!
Manually setting your PATH can interfere with Homebrew wrappers.
Ensure your shell configuration contains:
eval "\$(${HOMEBREW_BREW_FILE} shellenv)"
or that ${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW} comes before ${HOMEBREW_PREFIX}/bin in your PATH:
export PATH="${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW}:${HOMEBREW_PREFIX}/bin:\$PATH"
EOS
fi
fi
# If HOMEBREW_FORCE_BREW_WRAPPER and HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER are set,
# verify that the path to our parent process is the same as the value of HOMEBREW_FORCE_BREW_WRAPPER for all
# non-trivial commands (i.e. not defined above this line e.g. formulae or --cellar).
if [[ -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" ]]
if [[ -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" && -n "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" ]]
then
if [[ -n "${HOMEBREW_MACOS:-}" ]]
then

View File

@ -133,6 +133,9 @@ export_homebrew_env_file() {
done <"${env_file}"
}
# We only want to be able to set this in `brew.env` files.
unset HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER
# First, load the system-wide configuration.
export_homebrew_env_file "/etc/homebrew/brew.env"