Prioritize installing from JSON if env var is set

This commit is contained in:
Rylan Polster 2021-07-12 03:23:42 -04:00
parent 68c2be5c17
commit 1e34b69cd4
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
6 changed files with 21 additions and 25 deletions

View File

@ -49,14 +49,14 @@ module Homebrew
ignore_unavailable: T.nilable(T::Boolean), ignore_unavailable: T.nilable(T::Boolean),
method: T.nilable(Symbol), method: T.nilable(Symbol),
uniq: T::Boolean, uniq: T::Boolean,
load_from_json: T::Boolean, prefer_loading_from_json: T::Boolean,
).returns(T::Array[T.any(Formula, Keg, Cask::Cask)]) ).returns(T::Array[T.any(Formula, Keg, Cask::Cask)])
} }
def to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: nil, uniq: true, def to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: nil, uniq: true,
load_from_json: false) prefer_loading_from_json: false)
@to_formulae_and_casks ||= {} @to_formulae_and_casks ||= {}
@to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name| @to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name|
load_formula_or_cask(name, only: only, method: method, load_from_json: load_from_json) load_formula_or_cask(name, only: only, method: method, prefer_loading_from_json: prefer_loading_from_json)
rescue FormulaUnreadableError, FormulaClassUnavailableError, rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError, TapFormulaUnreadableError, TapFormulaClassUnavailableError,
Cask::CaskUnreadableError Cask::CaskUnreadableError
@ -90,10 +90,14 @@ module Homebrew
end.uniq.freeze end.uniq.freeze
end end
def load_formula_or_cask(name, only: nil, method: nil, load_from_json: false) def load_formula_or_cask(name, only: nil, method: nil, prefer_loading_from_json: false)
unreadable_error = nil unreadable_error = nil
if only != :cask if only != :cask
if prefer_loading_from_json && ENV["HOMEBREW_JSON_CORE"].present? && BottleAPI.bottle_available?(name)
BottleAPI.fetch_bottles(name)
end
begin begin
formula = case method formula = case method
when nil, :factory when nil, :factory
@ -123,12 +127,6 @@ module Homebrew
# The formula was found, but there's a problem with its implementation # The formula was found, but there's a problem with its implementation
unreadable_error ||= e unreadable_error ||= e
rescue NoSuchKegError, FormulaUnavailableError => e rescue NoSuchKegError, FormulaUnavailableError => e
if load_from_json && ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed? &&
BottleAPI.bottle_available?(name)
BottleAPI.fetch_bottles(name)
retry
end
raise e if only == :formula raise e if only == :formula
end end
end end

View File

@ -154,10 +154,8 @@ module Homebrew
EOS EOS
end end
allow_loading_from_json = ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed?
begin begin
formulae, casks = args.named.to_formulae_and_casks(load_from_json: allow_loading_from_json) formulae, casks = args.named.to_formulae_and_casks(prefer_loading_from_json: true)
.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) } .partition { |formula_or_cask| formula_or_cask.is_a?(Formula) }
rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e
retry if Tap.install_default_cask_tap_if_necessary(force: args.cask?) retry if Tap.install_default_cask_tap_if_necessary(force: args.cask?)

View File

@ -92,14 +92,14 @@ module Homebrew
if verbose? if verbose?
outdated_kegs = f.outdated_kegs(fetch_head: args.fetch_HEAD?) outdated_kegs = f.outdated_kegs(fetch_head: args.fetch_HEAD?)
current_version = if f.alias_changed? && !f.latest_formula.latest_version_installed? current_version = if ENV["HOMEBREW_JSON_CORE"].present? && (f.core_formula? || f.tap.blank?)
BottleAPI.latest_pkg_version(f.name)&.to_s || f.pkg_version.to_s
elsif f.alias_changed? && !f.latest_formula.latest_version_installed?
latest = f.latest_formula latest = f.latest_formula
"#{latest.name} (#{latest.pkg_version})" "#{latest.name} (#{latest.pkg_version})"
elsif f.head? && outdated_kegs.any? { |k| k.version.to_s == f.pkg_version.to_s } elsif f.head? && outdated_kegs.any? { |k| k.version.to_s == f.pkg_version.to_s }
# There is a newer HEAD but the version number has not changed. # There is a newer HEAD but the version number has not changed.
"latest HEAD" "latest HEAD"
elsif f.tap.blank? && ENV["HOMEBREW_JSON_CORE"].present?
BottleAPI.latest_pkg_version(f.name)&.to_s || f.pkg_version.to_s
else else
f.pkg_version.to_s f.pkg_version.to_s
end end

View File

@ -85,11 +85,11 @@ module Homebrew
def reinstall def reinstall
args = reinstall_args.parse args = reinstall_args.parse
if ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed? if ENV["HOMEBREW_JSON_CORE"].present?
args.named.each do |name| args.named.each do |name|
formula = Formulary.factory(name) formula = Formulary.factory(name)
next unless formula.any_version_installed? next unless formula.any_version_installed?
next if formula.tap.present? next if formula.tap.present? && !formula.core_formula?
next unless BottleAPI.bottle_available?(name) next unless BottleAPI.bottle_available?(name)
BottleAPI.fetch_bottles(name) BottleAPI.fetch_bottles(name)

View File

@ -160,9 +160,9 @@ module Homebrew
puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", " puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
end end
if ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed? if ENV["HOMEBREW_JSON_CORE"].present?
formulae_to_install.map! do |formula| formulae_to_install.map! do |formula|
next formula if formula.tap.present? next formula if formula.tap.present? && !formula.core_formula?
next formula unless BottleAPI.bottle_available?(formula.name) next formula unless BottleAPI.bottle_available?(formula.name)
BottleAPI.fetch_bottles(formula.name) BottleAPI.fetch_bottles(formula.name)

View File

@ -1326,7 +1326,7 @@ class Formula
Formula.cache[:outdated_kegs][cache_key] ||= begin Formula.cache[:outdated_kegs][cache_key] ||= begin
all_kegs = [] all_kegs = []
current_version = T.let(false, T::Boolean) current_version = T.let(false, T::Boolean)
latest_version = if tap.blank? && ENV["HOMEBREW_JSON_CORE"].present? latest_version = if ENV["HOMEBREW_JSON_CORE"].present? && (core_formula? || tap.blank?)
BottleAPI.latest_pkg_version(name) || pkg_version BottleAPI.latest_pkg_version(name) || pkg_version
else else
pkg_version pkg_version