Move HOMEBREW_NO_INSTALL_FROM_API defaults to shell

This commit is contained in:
Bo Anderson 2023-02-24 13:25:18 +00:00
parent ba8fd26755
commit e86a8c2477
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
24 changed files with 102 additions and 101 deletions

View File

@ -24,6 +24,25 @@ else
HOMEBREW_CELLAR="${HOMEBREW_PREFIX}/Cellar" HOMEBREW_CELLAR="${HOMEBREW_PREFIX}/Cellar"
fi fi
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"
HOMEBREW_LINUX_DEFAULT_REPOSITORY="${HOMEBREW_LINUX_DEFAULT_PREFIX}/Homebrew"
HOMEBREW_GENERIC_DEFAULT_PREFIX="/usr/local"
HOMEBREW_GENERIC_DEFAULT_REPOSITORY="${HOMEBREW_GENERIC_DEFAULT_PREFIX}/Homebrew"
if [[ -n "${HOMEBREW_MACOS}" && "${HOMEBREW_PROCESSOR}" == "arm64" ]]
then
HOMEBREW_DEFAULT_PREFIX="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
HOMEBREW_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY}"
elif [[ -n "${HOMEBREW_LINUX}" ]]
then
HOMEBREW_DEFAULT_PREFIX="${HOMEBREW_LINUX_DEFAULT_PREFIX}"
HOMEBREW_DEFAULT_REPOSITORY="${HOMEBREW_LINUX_DEFAULT_REPOSITORY}"
else
HOMEBREW_DEFAULT_PREFIX="${HOMEBREW_GENERIC_DEFAULT_PREFIX}"
HOMEBREW_DEFAULT_REPOSITORY="${HOMEBREW_GENERIC_DEFAULT_REPOSITORY}"
fi
if [[ -n "${HOMEBREW_MACOS}" ]] if [[ -n "${HOMEBREW_MACOS}" ]]
then then
HOMEBREW_DEFAULT_CACHE="${HOME}/Library/Caches/Homebrew" HOMEBREW_DEFAULT_CACHE="${HOME}/Library/Caches/Homebrew"
@ -448,6 +467,17 @@ case "$*" in
;; ;;
esac esac
# TODO: bump version when new macOS is released or announced
# and also update references in docs/Installation.md,
# https://github.com/Homebrew/install/blob/HEAD/install.sh and
# MacOSVersions::SYMBOLS
HOMEBREW_MACOS_NEWEST_UNSUPPORTED="14"
# TODO: bump version when new macOS is released and also update
# references in docs/Installation.md and
# https://github.com/Homebrew/install/blob/HEAD/install.sh
HOMEBREW_MACOS_OLDEST_SUPPORTED="11"
HOMEBREW_MACOS_OLDEST_ALLOWED="10.11"
if [[ -n "${HOMEBREW_MACOS}" ]] if [[ -n "${HOMEBREW_MACOS}" ]]
then then
HOMEBREW_PRODUCT="Homebrew" HOMEBREW_PRODUCT="Homebrew"
@ -467,6 +497,10 @@ then
# Intentionally set this variable by exploding another. # Intentionally set this variable by exploding another.
# shellcheck disable=SC2086,SC2183 # shellcheck disable=SC2086,SC2183
printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_VERSION//./ } printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_VERSION//./ }
# shellcheck disable=SC2248
printf -v HOMEBREW_MACOS_OLDEST_SUPPORTED_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_OLDEST_SUPPORTED//./ }
# shellcheck disable=SC2248
printf -v HOMEBREW_MACOS_OLDEST_ALLOWED_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_OLDEST_ALLOWED//./ }
# Don't include minor versions for Big Sur and later. # Don't include minor versions for Big Sur and later.
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -gt "110000" ]] if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -gt "110000" ]]
@ -477,7 +511,7 @@ then
fi fi
# Refuse to run on pre-El Capitan # Refuse to run on pre-El Capitan
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "101100" ]] if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "${HOMEBREW_MACOS_OLDEST_ALLOWED_NUMERIC}" ]]
then then
printf "ERROR: Your version of macOS (%s) is too old to run Homebrew!\\n" "${HOMEBREW_MACOS_VERSION}" >&2 printf "ERROR: Your version of macOS (%s) is too old to run Homebrew!\\n" "${HOMEBREW_MACOS_VERSION}" >&2
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "100700" ]] if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "100700" ]]
@ -524,6 +558,12 @@ then
# shellcheck disable=SC2034 # shellcheck disable=SC2034
HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH="1" HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH="1"
fi fi
# Don't support API at this time for older macOS versions.
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "${HOMEBREW_MACOS_OLDEST_SUPPORTED_NUMERIC}" ]]
then
export HOMEBREW_NO_INSTALL_FROM_API=1
fi
else else
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew" HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew"
[[ -n "${HOMEBREW_LINUX}" ]] && HOMEBREW_OS_VERSION="$(lsb_release -s -d 2>/dev/null)" [[ -n "${HOMEBREW_LINUX}" ]] && HOMEBREW_OS_VERSION="$(lsb_release -s -d 2>/dev/null)"
@ -596,6 +636,12 @@ Your Git executable: $(unset git && type -p "${HOMEBREW_GIT}")"
fi fi
fi fi
# Generic OS or non-default prefix: API not supported.
if [[ (-z "${HOMEBREW_MACOS}" && -z "${HOMEBREW_LINUX}") || "${HOMEBREW_PREFIX}" != "${HOMEBREW_DEFAULT_PREFIX}" ]]
then
export HOMEBREW_NO_INSTALL_FROM_API=1
fi
setup_ca_certificates() { setup_ca_certificates() {
if [[ -n "${HOMEBREW_FORCE_BREWED_CA_CERTIFICATES}" && -f "${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" ]] if [[ -n "${HOMEBREW_FORCE_BREWED_CA_CERTIFICATES}" && -f "${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" ]]
then then
@ -638,6 +684,14 @@ HOMEBREW_CURL_SPEED_LIMIT=100
HOMEBREW_CURL_SPEED_TIME=5 HOMEBREW_CURL_SPEED_TIME=5
export HOMEBREW_VERSION export HOMEBREW_VERSION
export HOMEBREW_MACOS_ARM_DEFAULT_PREFIX
export HOMEBREW_LINUX_DEFAULT_PREFIX
export HOMEBREW_GENERIC_DEFAULT_PREFIX
export HOMEBREW_DEFAULT_PREFIX
export HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY
export HOMEBREW_LINUX_DEFAULT_REPOSITORY
export HOMEBREW_GENERIC_DEFAULT_REPOSITORY
export HOMEBREW_DEFAULT_REPOSITORY
export HOMEBREW_DEFAULT_CACHE export HOMEBREW_DEFAULT_CACHE
export HOMEBREW_CACHE export HOMEBREW_CACHE
export HOMEBREW_DEFAULT_LOGS export HOMEBREW_DEFAULT_LOGS
@ -661,6 +715,9 @@ export HOMEBREW_PRODUCT
export HOMEBREW_OS_VERSION export HOMEBREW_OS_VERSION
export HOMEBREW_MACOS_VERSION export HOMEBREW_MACOS_VERSION
export HOMEBREW_MACOS_VERSION_NUMERIC export HOMEBREW_MACOS_VERSION_NUMERIC
export HOMEBREW_MACOS_NEWEST_UNSUPPORTED
export HOMEBREW_MACOS_OLDEST_SUPPORTED
export HOMEBREW_MACOS_OLDEST_ALLOWED
export HOMEBREW_USER_AGENT export HOMEBREW_USER_AGENT
export HOMEBREW_USER_AGENT_CURL export HOMEBREW_USER_AGENT_CURL
export HOMEBREW_API_DEFAULT_DOMAIN export HOMEBREW_API_DEFAULT_DOMAIN

View File

@ -597,7 +597,7 @@ module Cask
return return
end end
return if min_os_string <= MacOS::Version::OLDEST_ALLOWED return if min_os_string <= HOMEBREW_MACOS_OLDEST_ALLOWED
cask_min_os = cask.depends_on.macos&.version cask_min_os = cask.depends_on.macos&.version

View File

@ -272,7 +272,7 @@ module Cask
alias == eql? alias == eql?
def to_h def to_h
if loaded_from_api && Homebrew::EnvConfig.install_from_api? if loaded_from_api && !Homebrew::EnvConfig.no_install_from_api?
json_cask = Homebrew::API::Cask.all_casks[token] json_cask = Homebrew::API::Cask.all_casks[token]
return api_to_local_hash(Homebrew::API.merge_variations(json_cask)) return api_to_local_hash(Homebrew::API.merge_variations(json_cask))
end end
@ -313,7 +313,7 @@ module Cask
end end
def to_hash_with_variations def to_hash_with_variations
if loaded_from_api && Homebrew::EnvConfig.install_from_api? if loaded_from_api && !Homebrew::EnvConfig.no_install_from_api?
return api_to_local_hash(Homebrew::API::Cask.all_casks[token]) return api_to_local_hash(Homebrew::API::Cask.all_casks[token])
end end

View File

@ -215,7 +215,7 @@ module Cask
FLIGHT_STANZAS = [:preflight, :postflight, :uninstall_preflight, :uninstall_postflight].freeze FLIGHT_STANZAS = [:preflight, :postflight, :uninstall_preflight, :uninstall_postflight].freeze
def self.can_load?(ref) def self.can_load?(ref)
return false unless Homebrew::EnvConfig.install_from_api? return false if Homebrew::EnvConfig.no_install_from_api?
return false unless ref.is_a?(String) return false unless ref.is_a?(String)
return false unless ref.match?(HOMEBREW_MAIN_TAP_CASK_REGEX) return false unless ref.match?(HOMEBREW_MAIN_TAP_CASK_REGEX)

View File

@ -158,7 +158,7 @@ module Homebrew
next unless name =~ HOMEBREW_TAP_FORMULA_REGEX next unless name =~ HOMEBREW_TAP_FORMULA_REGEX
tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))
next if (tap.core_tap? || tap == "homebrew/cask") && EnvConfig.install_from_api? next if (tap.core_tap? || tap == "homebrew/cask") && !EnvConfig.no_install_from_api?
tap.install unless tap.installed? tap.install unless tap.installed?
end end

View File

@ -25,9 +25,9 @@ module Homebrew
args = untap_args.parse args = untap_args.parse
args.named.to_installed_taps.each do |tap| args.named.to_installed_taps.each do |tap|
odie "Untapping #{tap} is not allowed" if tap.core_tap? && !Homebrew::EnvConfig.install_from_api? odie "Untapping #{tap} is not allowed" if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api?
if !Homebrew::EnvConfig.install_from_api? || (!tap.core_tap? && tap != "homebrew/cask") if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && tap != "homebrew/cask")
installed_tap_formulae = Formula.installed.select { |formula| formula.tap == tap } installed_tap_formulae = Formula.installed.select { |formula| formula.tap == tap }
installed_tap_casks = Cask::Caskroom.casks.select { |cask| cask.tap == tap } installed_tap_casks = Cask::Caskroom.casks.select { |cask| cask.tap == tap }

View File

@ -146,7 +146,7 @@ module Homebrew
end end
# Check if we can parse the JSON and do any Ruby-side follow-up. # Check if we can parse the JSON and do any Ruby-side follow-up.
if Homebrew::EnvConfig.install_from_api? unless Homebrew::EnvConfig.no_install_from_api?
Homebrew::API::Formula.write_names_and_aliases Homebrew::API::Formula.write_names_and_aliases
Homebrew::API::Cask.write_names Homebrew::API::Cask.write_names
end end
@ -161,7 +161,7 @@ module Homebrew
updated_taps = [] updated_taps = []
Tap.each do |tap| Tap.each do |tap|
next unless tap.git? next unless tap.git?
next if (tap.core_tap? || tap == "homebrew/cask") && Homebrew::EnvConfig.install_from_api? next if (tap.core_tap? || tap == "homebrew/cask") && !Homebrew::EnvConfig.no_install_from_api?
if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? && if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? &&
Settings.read("linuxbrewmigrated") != "true" Settings.read("linuxbrewmigrated") != "true"
@ -275,7 +275,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 unless Homebrew::EnvConfig.no_install_from_api?
return if Homebrew::EnvConfig.automatically_set_no_install_from_api? return if Homebrew::EnvConfig.automatically_set_no_install_from_api?
core_tap = CoreTap.instance core_tap = CoreTap.instance

View File

@ -2,8 +2,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
DEFAULT_PREFIX = HOMEBREW_DEFAULT_PREFIX DEFAULT_PREFIX = ENV.fetch("HOMEBREW_DEFAULT_PREFIX").freeze
DEFAULT_REPOSITORY = HOMEBREW_DEFAULT_REPOSITORY DEFAULT_REPOSITORY = ENV.fetch("HOMEBREW_DEFAULT_REPOSITORY").freeze
end end
require "extend/os/default_prefix"

View File

@ -327,7 +327,7 @@ module Homebrew
end end
def without_api(&block) def without_api(&block)
return yield unless Homebrew::EnvConfig.install_from_api? return yield if Homebrew::EnvConfig.no_install_from_api?
with_env(HOMEBREW_NO_INSTALL_FROM_API: "1", HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API: "1", &block) with_env(HOMEBREW_NO_INSTALL_FROM_API: "1", HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API: "1", &block)
end end

View File

@ -522,7 +522,7 @@ module Homebrew
def check_coretap_integrity def check_coretap_integrity
coretap = CoreTap.instance coretap = CoreTap.instance
unless coretap.installed? unless coretap.installed?
return if EnvConfig.install_from_api? return unless EnvConfig.no_install_from_api?
CoreTap.ensure_installed! CoreTap.ensure_installed!
end end
@ -821,7 +821,7 @@ module Homebrew
deleted_formulae = kegs.map do |keg| deleted_formulae = kegs.map do |keg|
next if Formulary.tap_paths(keg.name).any? next if Formulary.tap_paths(keg.name).any?
if !CoreTap.instance.installed? && EnvConfig.install_from_api? if !CoreTap.instance.installed? && !EnvConfig.no_install_from_api?
# Formulae installed with HOMEBREW_INSTALL_FROM_API should not count as deleted formulae # Formulae installed with HOMEBREW_INSTALL_FROM_API should not count as deleted formulae
# but may not have a tap listed in their tab # but may not have a tap listed in their tab
tap = Tab.for_keg(keg).tap tap = Tab.for_keg(keg).tap

View File

@ -499,13 +499,5 @@ module Homebrew
def automatically_set_no_install_from_api? def automatically_set_no_install_from_api?
ENV["HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API"].present? ENV["HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API"].present?
end end
sig { returns(T::Boolean) }
def install_from_api?
return false if OS.unsupported_configuration?
return false unless Homebrew.default_prefix?
ENV["HOMEBREW_NO_INSTALL_FROM_API"].blank?
end
end end
end end

View File

@ -1,8 +0,0 @@
# typed: true
# frozen_string_literal: true
if OS.mac?
require "extend/os/mac/default_prefix"
elsif OS.linux?
require "extend/os/linux/default_prefix"
end

View File

@ -1,10 +0,0 @@
# typed: true
# frozen_string_literal: true
module Homebrew
remove_const(:DEFAULT_PREFIX)
DEFAULT_PREFIX = HOMEBREW_LINUX_DEFAULT_PREFIX
remove_const(:DEFAULT_REPOSITORY)
DEFAULT_REPOSITORY = HOMEBREW_LINUX_DEFAULT_REPOSITORY
end

View File

@ -121,7 +121,7 @@ module Homebrew
end end
def check_linuxbrew_core def check_linuxbrew_core
return if Homebrew::EnvConfig.install_from_api? return unless Homebrew::EnvConfig.no_install_from_api?
return unless CoreTap.instance.linuxbrew_core? return unless CoreTap.instance.linuxbrew_core?
<<~EOS <<~EOS

View File

@ -1,17 +0,0 @@
# typed: true
# frozen_string_literal: true
require "simulate_system"
module Homebrew
if Hardware::CPU.arm? || Homebrew::SimulateSystem.simulating_or_running_on_linux?
remove_const(:DEFAULT_PREFIX)
remove_const(:DEFAULT_REPOSITORY)
DEFAULT_PREFIX, DEFAULT_REPOSITORY = if Hardware::CPU.arm?
[HOMEBREW_MACOS_ARM_DEFAULT_PREFIX, HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY]
elsif Homebrew::SimulateSystem.simulating_or_running_on_linux?
[HOMEBREW_LINUX_DEFAULT_PREFIX, HOMEBREW_LINUX_DEFAULT_REPOSITORY]
end
end
end

View File

@ -4,7 +4,7 @@
class Tap 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 unless Homebrew::EnvConfig.no_install_from_api?
return false if Homebrew::EnvConfig.automatically_set_no_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)

View File

@ -2202,7 +2202,7 @@ class Formula
hash = to_hash hash = to_hash
# Take from API, merging in local install status. # Take from API, merging in local install status.
if self.class.loaded_from_api && Homebrew::EnvConfig.install_from_api? if self.class.loaded_from_api && !Homebrew::EnvConfig.no_install_from_api?
json_formula = Homebrew::API::Formula.all_formulae[name].dup json_formula = Homebrew::API::Formula.all_formulae[name].dup
json_formula["name"] = hash["name"] json_formula["name"] = hash["name"]
json_formula["installed"] = hash["installed"] json_formula["installed"] = hash["installed"]

View File

@ -748,7 +748,7 @@ module Formulary
when URL_START_REGEX when URL_START_REGEX
return FromUrlLoader.new(ref, from: from) return FromUrlLoader.new(ref, from: from)
when HOMEBREW_TAP_FORMULA_REGEX when HOMEBREW_TAP_FORMULA_REGEX
if ref.start_with?("homebrew/core/") && Homebrew::EnvConfig.install_from_api? if ref.start_with?("homebrew/core/") && !Homebrew::EnvConfig.no_install_from_api?
name = ref.split("/", 3).last name = ref.split("/", 3).last
return FormulaAPILoader.new(name) if Homebrew::API::Formula.all_formulae.key?(name) return FormulaAPILoader.new(name) if Homebrew::API::Formula.all_formulae.key?(name)
return AliasAPILoader.new(name) if Homebrew::API::Formula.all_aliases.key?(name) return AliasAPILoader.new(name) if Homebrew::API::Formula.all_aliases.key?(name)
@ -760,7 +760,7 @@ module Formulary
pathname_ref = Pathname.new(ref) pathname_ref = Pathname.new(ref)
return FromPathLoader.new(ref) if File.extname(ref) == ".rb" && pathname_ref.expand_path.exist? return FromPathLoader.new(ref) if File.extname(ref) == ".rb" && pathname_ref.expand_path.exist?
if Homebrew::EnvConfig.install_from_api? unless Homebrew::EnvConfig.no_install_from_api?
return FormulaAPILoader.new(ref) if Homebrew::API::Formula.all_formulae.key?(ref) return FormulaAPILoader.new(ref) if Homebrew::API::Formula.all_formulae.key?(ref)
return AliasAPILoader.new(ref) if Homebrew::API::Formula.all_aliases.key?(ref) return AliasAPILoader.new(ref) if Homebrew::API::Formula.all_aliases.key?(ref)
end end

View File

@ -59,14 +59,18 @@ HOMEBREW_USER_AGENT_FAKE_SAFARI =
"(KHTML, like Gecko) Version/10.0.3 Safari/602.4.8" "(KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
HOMEBREW_GITHUB_PACKAGES_AUTH = ENV.fetch("HOMEBREW_GITHUB_PACKAGES_AUTH").freeze HOMEBREW_GITHUB_PACKAGES_AUTH = ENV.fetch("HOMEBREW_GITHUB_PACKAGES_AUTH").freeze
HOMEBREW_DEFAULT_PREFIX = "/usr/local" HOMEBREW_DEFAULT_PREFIX = ENV.fetch("HOMEBREW_GENERIC_DEFAULT_PREFIX").freeze
HOMEBREW_DEFAULT_REPOSITORY = "#{HOMEBREW_DEFAULT_PREFIX}/Homebrew" HOMEBREW_DEFAULT_REPOSITORY = ENV.fetch("HOMEBREW_GENERIC_DEFAULT_REPOSITORY").freeze
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX = "/opt/homebrew" HOMEBREW_MACOS_ARM_DEFAULT_PREFIX = ENV.fetch("HOMEBREW_MACOS_ARM_DEFAULT_PREFIX").freeze
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY = HOMEBREW_MACOS_ARM_DEFAULT_PREFIX HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY = ENV.fetch("HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY").freeze
HOMEBREW_LINUX_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew" HOMEBREW_LINUX_DEFAULT_PREFIX = ENV.fetch("HOMEBREW_LINUX_DEFAULT_PREFIX").freeze
HOMEBREW_LINUX_DEFAULT_REPOSITORY = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Homebrew" HOMEBREW_LINUX_DEFAULT_REPOSITORY = ENV.fetch("HOMEBREW_LINUX_DEFAULT_REPOSITORY").freeze
HOMEBREW_PREFIX_PLACEHOLDER = "$HOMEBREW_PREFIX" HOMEBREW_PREFIX_PLACEHOLDER = "$HOMEBREW_PREFIX"
HOMEBREW_MACOS_NEWEST_UNSUPPORTED = ENV.fetch("HOMEBREW_MACOS_NEWEST_UNSUPPORTED").freeze
HOMEBREW_MACOS_OLDEST_SUPPORTED = ENV.fetch("HOMEBREW_MACOS_OLDEST_SUPPORTED").freeze
HOMEBREW_MACOS_OLDEST_ALLOWED = ENV.fetch("HOMEBREW_MACOS_OLDEST_ALLOWED").freeze
HOMEBREW_PULL_API_REGEX = HOMEBREW_PULL_API_REGEX =
%r{https://api\.github\.com/repos/([\w-]+)/([\w-]+)?/pulls/(\d+)}.freeze %r{https://api\.github\.com/repos/([\w-]+)/([\w-]+)?/pulls/(\d+)}.freeze
HOMEBREW_PULL_OR_COMMIT_URL_REGEX = HOMEBREW_PULL_OR_COMMIT_URL_REGEX =

View File

@ -13,21 +13,6 @@ module OS
class Version < ::Version class Version < ::Version
extend T::Sig extend T::Sig
# TODO: bump version when new macOS is released or announced
# and also update references in docs/Installation.md,
# https://github.com/Homebrew/install/blob/HEAD/install.sh and
# MacOSVersions::SYMBOLS
NEWEST_UNSUPPORTED = "14"
private_constant :NEWEST_UNSUPPORTED
# TODO: bump version when new macOS is released and also update
# references in docs/Installation.md and
# https://github.com/Homebrew/install/blob/HEAD/install.sh
OLDEST_SUPPORTED = "11"
private_constant :OLDEST_SUPPORTED
OLDEST_ALLOWED = "10.11"
sig { params(version: Symbol).returns(T.attached_class) } sig { params(version: Symbol).returns(T.attached_class) }
def self.from_symbol(version) def self.from_symbol(version)
str = MacOSVersions::SYMBOLS.fetch(version) { raise MacOSVersionError, version } str = MacOSVersions::SYMBOLS.fetch(version) { raise MacOSVersionError, version }
@ -79,12 +64,12 @@ module OS
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def outdated_release? def outdated_release?
self < OLDEST_SUPPORTED self < HOMEBREW_MACOS_OLDEST_SUPPORTED
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def prerelease? def prerelease?
self >= NEWEST_UNSUPPORTED self >= HOMEBREW_MACOS_NEWEST_UNSUPPORTED
end end
# For {OS::Mac::Version} compatibility. # For {OS::Mac::Version} compatibility.

View File

@ -43,7 +43,7 @@ class MacOSRequirement < Requirement
end end
# Otherwise fallback to the oldest allowed if comparator is >=. # Otherwise fallback to the oldest allowed if comparator is >=.
MacOS::Version.new(MacOS::Version::OLDEST_ALLOWED) if comparator == ">=" MacOS::Version.new(HOMEBREW_MACOS_OLDEST_ALLOWED) if comparator == ">="
end end
@comparator = comparator @comparator = comparator

View File

@ -137,7 +137,7 @@ module Homebrew
c.sub(%r{^homebrew/cask.*/}, "") c.sub(%r{^homebrew/cask.*/}, "")
end end
if !Tap.fetch("homebrew/cask").installed? && Homebrew::EnvConfig.install_from_api? if !Tap.fetch("homebrew/cask").installed? && !Homebrew::EnvConfig.no_install_from_api?
cask_tokens += Homebrew::API::Cask.all_casks.keys cask_tokens += Homebrew::API::Cask.all_casks.keys
end end

View File

@ -723,7 +723,7 @@ class Tap
# @private # @private
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def should_report_analytics? def should_report_analytics?
return Homebrew::EnvConfig.install_from_api? && official? unless installed? return !Homebrew::EnvConfig.no_install_from_api? && official? unless installed?
!private? !private?
end end
@ -859,7 +859,7 @@ class CoreTap < Tap
sig { void } sig { void }
def self.ensure_installed! def self.ensure_installed!
return if instance.installed? return if instance.installed?
return if Homebrew::EnvConfig.install_from_api? return unless Homebrew::EnvConfig.no_install_from_api?
return if Homebrew::EnvConfig.automatically_set_no_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.
@ -870,7 +870,7 @@ class CoreTap < Tap
sig { returns(String) } sig { returns(String) }
def remote def remote
super if installed? || !Homebrew::EnvConfig.install_from_api? super if installed? || Homebrew::EnvConfig.no_install_from_api?
Homebrew::EnvConfig.core_git_remote Homebrew::EnvConfig.core_git_remote
end end
@ -893,7 +893,7 @@ class CoreTap < Tap
# @private # @private
sig { params(manual: T::Boolean).void } sig { params(manual: T::Boolean).void }
def uninstall(manual: false) def uninstall(manual: false)
raise "Tap#uninstall is not available for CoreTap" unless Homebrew::EnvConfig.install_from_api? raise "Tap#uninstall is not available for CoreTap" if Homebrew::EnvConfig.no_install_from_api?
super super
end end
@ -988,7 +988,7 @@ class CoreTap < Tap
# @private # @private
sig { returns(T::Array[String]) } sig { returns(T::Array[String]) }
def aliases def aliases
return super if installed? || !Homebrew::EnvConfig.install_from_api? return super if installed? || Homebrew::EnvConfig.no_install_from_api?
Homebrew::API::Formula.all_aliases.keys Homebrew::API::Formula.all_aliases.keys
end end
@ -996,7 +996,7 @@ class CoreTap < Tap
# @private # @private
sig { returns(T::Array[String]) } sig { returns(T::Array[String]) }
def formula_names def formula_names
return super if installed? || !Homebrew::EnvConfig.install_from_api? return super if installed? || Homebrew::EnvConfig.no_install_from_api?
Homebrew::API::Formula.all_formulae.keys Homebrew::API::Formula.all_formulae.keys
end end

View File

@ -28,8 +28,8 @@ describe Cask::CaskLoader::FromAPILoader, :cask do
context "when not using the API" do context "when not using the API" do
before do before do
allow(Homebrew::EnvConfig) allow(Homebrew::EnvConfig)
.to receive(:install_from_api?) .to receive(:no_install_from_api?)
.and_return(false) .and_return(true)
end end
it "returns false" do it "returns false" do
@ -40,8 +40,8 @@ describe Cask::CaskLoader::FromAPILoader, :cask do
context "when using the API" do context "when using the API" do
before do before do
allow(Homebrew::EnvConfig) allow(Homebrew::EnvConfig)
.to receive(:install_from_api?) .to receive(:no_install_from_api?)
.and_return(true) .and_return(false)
end end
it "returns true for valid token" do it "returns true for valid token" do