Fix HOMEBREW_*BREW_WRAPPER behaviour

- handle reading from variables that may not be defined yet
- avoid unnecessary handling of defined variables
- fix incorrect `env_config.rbi` file entry
- add `HOMEBREW_NO_FORCE_BREW_WRAPPER` to disable
  `HOMEBREW_FORCE_BREW_WRAPPER` functionality if needed
This commit is contained in:
Mike McQuaid 2025-01-08 14:04:18 +00:00
parent cbf92f31a8
commit bb74d26a93
No known key found for this signature in database
3 changed files with 13 additions and 5 deletions

View File

@ -182,8 +182,9 @@ esac
source "${HOMEBREW_LIBRARY}/Homebrew/utils/helpers.sh"
# Require HOMEBREW_BREW_WRAPPER to be set if HOMEBREW_FORCE_BREW_WRAPPER is set
# for all non-trivial commands (i.e. not run above).
if [[ -n "${HOMEBREW_FORCE_BREW_WRAPPER}" ]]
# (and HOMEBREW_NO_FORCE_BREW_WRAPPER is 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:-}" ]]
then
if [[ -z "${HOMEBREW_BREW_WRAPPER:-}" ]]
then
@ -195,7 +196,7 @@ but HOMEBREW_BREW_WRAPPER was unset. This indicates that you are running
directly but should instead run
${HOMEBREW_FORCE_BREW_WRAPPER}
EOS
elif [[ "${HOMEBREW_FORCE_BREW_WRAPPER:-}" != "${HOMEBREW_BREW_WRAPPER:-}" ]]
elif [[ "${HOMEBREW_FORCE_BREW_WRAPPER}" != "${HOMEBREW_BREW_WRAPPER}" ]]
then
odie <<EOS
HOMEBREW_FORCE_BREW_WRAPPER was set to

View File

@ -376,6 +376,10 @@ module Homebrew
description: "If set, do not print any hints about changing Homebrew's behaviour with environment variables.",
boolean: true,
},
HOMEBREW_NO_FORCE_BREW_WRAPPER: {
description: "If set, disables `HOMEBREW_FORCE_BREW_WRAPPER` behaviour, even if set.",
boolean: true,
},
HOMEBREW_NO_GITHUB_API: {
description: "If set, do not use the GitHub API, e.g. for searches or fetching relevant issues " \
"after a failed install.",

View File

@ -142,8 +142,8 @@ module Homebrew::EnvConfig
sig { returns(T::Boolean) }
def force_api_auto_update?; end
sig { returns(T::Boolean) }
def force_brew_wrapper?; end
sig { returns(T.nilable(::String)) }
def force_brew_wrapper; end
sig { returns(T::Boolean) }
def force_brewed_ca_certificates?; end
@ -238,6 +238,9 @@ module Homebrew::EnvConfig
sig { returns(T::Boolean) }
def no_env_hints?; end
sig { returns(T::Boolean) }
def no_force_brew_wrapper?; end
sig { returns(T::Boolean) }
def no_github_api?; end