Improve homebrew/{core,cask} autotapping.

Don't automatically tap these when running a developer command that's
not using the API.

Fixes #14606
This commit is contained in:
Mike McQuaid 2023-02-14 09:54:24 +00:00
parent ed79381155
commit 4c8ed77302
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
6 changed files with 37 additions and 25 deletions

View File

@ -41,7 +41,7 @@ Metrics/PerceivedComplexity:
Metrics/MethodLength: Metrics/MethodLength:
Max: 232 Max: 232
Metrics/ModuleLength: Metrics/ModuleLength:
Max: 473 Max: 475
Exclude: Exclude:
# TODO: extract more of the bottling logic # TODO: extract more of the bottling logic
- "dev-cmd/bottle.rb" - "dev-cmd/bottle.rb"

View File

@ -782,6 +782,8 @@ if [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${HOMEBREW_COMMAND}.sh" ]] ||
then then
export HOMEBREW_DEVELOPER_COMMAND="1" export HOMEBREW_DEVELOPER_COMMAND="1"
if [[ -z "${HOMEBREW_NO_INSTALL_FROM_API}" ]]
then
NO_INSTALL_FROM_API_COMMANDS=( NO_INSTALL_FROM_API_COMMANDS=(
audit audit
bottle bottle
@ -805,10 +807,12 @@ then
if check-array-membership "${HOMEBREW_COMMAND}" "${NO_INSTALL_FROM_API_COMMANDS[@]}" if check-array-membership "${HOMEBREW_COMMAND}" "${NO_INSTALL_FROM_API_COMMANDS[@]}"
then then
export HOMEBREW_NO_INSTALL_FROM_API=1 export HOMEBREW_NO_INSTALL_FROM_API=1
export HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API=1
fi fi
unset NO_INSTALL_FROM_API_COMMANDS unset NO_INSTALL_FROM_API_COMMANDS
fi fi
fi
if [[ -n "${HOMEBREW_DEVELOPER_COMMAND}" && -z "${HOMEBREW_DEVELOPER}" ]] if [[ -n "${HOMEBREW_DEVELOPER_COMMAND}" && -z "${HOMEBREW_DEVELOPER}" ]]
then then

View File

@ -271,6 +271,7 @@ module Homebrew
def install_core_tap_if_necessary def install_core_tap_if_necessary
return if ENV["HOMEBREW_UPDATE_TEST"] return if ENV["HOMEBREW_UPDATE_TEST"]
return if Homebrew::EnvConfig.install_from_api? return if Homebrew::EnvConfig.install_from_api?
return if Homebrew::EnvConfig.automatically_set_no_install_from_api?
core_tap = CoreTap.instance core_tap = CoreTap.instance
return if core_tap.installed? return if core_tap.installed?

View File

@ -489,6 +489,11 @@ module Homebrew
cask_opts.include?("--require-sha") cask_opts.include?("--require-sha")
end end
sig { returns(T::Boolean) }
def automatically_set_no_install_from_api?
ENV["HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API"].present?
end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def install_from_api? def install_from_api?
return false if OS.unsupported_configuration? return false if OS.unsupported_configuration?

View File

@ -5,6 +5,7 @@ class Tap
def self.install_default_cask_tap_if_necessary(force: false) def self.install_default_cask_tap_if_necessary(force: false)
return false if default_cask_tap.installed? return false if default_cask_tap.installed?
return false if Homebrew::EnvConfig.install_from_api? return false if Homebrew::EnvConfig.install_from_api?
return false if Homebrew::EnvConfig.automatically_set_no_install_from_api?
return false if !force && Tap.untapped_official_taps.include?(default_cask_tap.name) return false if !force && Tap.untapped_official_taps.include?(default_cask_tap.name)
default_cask_tap.install default_cask_tap.install

View File

@ -796,6 +796,7 @@ class CoreTap < Tap
def self.ensure_installed! def self.ensure_installed!
return if instance.installed? return if instance.installed?
return if Homebrew::EnvConfig.install_from_api? return if Homebrew::EnvConfig.install_from_api?
return if Homebrew::EnvConfig.automatically_set_no_install_from_api?
# Tests override homebrew-core locations and we don't want to auto-tap in them. # Tests override homebrew-core locations and we don't want to auto-tap in them.
return if ENV["HOMEBREW_TESTS"] return if ENV["HOMEBREW_TESTS"]