Prioritize installing from JSON if env var is set
This commit is contained in:
		
							parent
							
								
									68c2be5c17
								
							
						
					
					
						commit
						1e34b69cd4
					
				@ -45,18 +45,18 @@ module Homebrew
 | 
			
		||||
      # the formula and prints a warning unless `only` is specified.
 | 
			
		||||
      sig {
 | 
			
		||||
        params(
 | 
			
		||||
          only:               T.nilable(Symbol),
 | 
			
		||||
          ignore_unavailable: T.nilable(T::Boolean),
 | 
			
		||||
          method:             T.nilable(Symbol),
 | 
			
		||||
          uniq:               T::Boolean,
 | 
			
		||||
          load_from_json:     T::Boolean,
 | 
			
		||||
          only:                     T.nilable(Symbol),
 | 
			
		||||
          ignore_unavailable:       T.nilable(T::Boolean),
 | 
			
		||||
          method:                   T.nilable(Symbol),
 | 
			
		||||
          uniq:                     T::Boolean,
 | 
			
		||||
          prefer_loading_from_json: T::Boolean,
 | 
			
		||||
        ).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,
 | 
			
		||||
                                load_from_json: false)
 | 
			
		||||
                                prefer_loading_from_json: false)
 | 
			
		||||
        @to_formulae_and_casks ||= {}
 | 
			
		||||
        @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,
 | 
			
		||||
               TapFormulaUnreadableError, TapFormulaClassUnavailableError,
 | 
			
		||||
               Cask::CaskUnreadableError
 | 
			
		||||
@ -90,10 +90,14 @@ module Homebrew
 | 
			
		||||
        end.uniq.freeze
 | 
			
		||||
      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
 | 
			
		||||
 | 
			
		||||
        if only != :cask
 | 
			
		||||
          if prefer_loading_from_json && ENV["HOMEBREW_JSON_CORE"].present? && BottleAPI.bottle_available?(name)
 | 
			
		||||
            BottleAPI.fetch_bottles(name)
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          begin
 | 
			
		||||
            formula = case method
 | 
			
		||||
            when nil, :factory
 | 
			
		||||
@ -123,12 +127,6 @@ module Homebrew
 | 
			
		||||
            # The formula was found, but there's a problem with its implementation
 | 
			
		||||
            unreadable_error ||= 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
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
@ -154,10 +154,8 @@ module Homebrew
 | 
			
		||||
      EOS
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    allow_loading_from_json = ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed?
 | 
			
		||||
 | 
			
		||||
    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) }
 | 
			
		||||
    rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e
 | 
			
		||||
      retry if Tap.install_default_cask_tap_if_necessary(force: args.cask?)
 | 
			
		||||
 | 
			
		||||
@ -92,14 +92,14 @@ module Homebrew
 | 
			
		||||
        if verbose?
 | 
			
		||||
          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.name} (#{latest.pkg_version})"
 | 
			
		||||
          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.
 | 
			
		||||
            "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
 | 
			
		||||
            f.pkg_version.to_s
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
@ -85,11 +85,11 @@ module Homebrew
 | 
			
		||||
  def reinstall
 | 
			
		||||
    args = reinstall_args.parse
 | 
			
		||||
 | 
			
		||||
    if ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed?
 | 
			
		||||
    if ENV["HOMEBREW_JSON_CORE"].present?
 | 
			
		||||
      args.named.each do |name|
 | 
			
		||||
        formula = Formulary.factory(name)
 | 
			
		||||
        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)
 | 
			
		||||
 | 
			
		||||
        BottleAPI.fetch_bottles(name)
 | 
			
		||||
 | 
			
		||||
@ -160,9 +160,9 @@ module Homebrew
 | 
			
		||||
      puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if ENV["HOMEBREW_JSON_CORE"].present? && !CoreTap.instance.installed?
 | 
			
		||||
    if ENV["HOMEBREW_JSON_CORE"].present?
 | 
			
		||||
      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)
 | 
			
		||||
 | 
			
		||||
        BottleAPI.fetch_bottles(formula.name)
 | 
			
		||||
 | 
			
		||||
@ -1326,7 +1326,7 @@ class Formula
 | 
			
		||||
    Formula.cache[:outdated_kegs][cache_key] ||= begin
 | 
			
		||||
      all_kegs = []
 | 
			
		||||
      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
 | 
			
		||||
      else
 | 
			
		||||
        pkg_version
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user