diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index d2c449823e..17f52b1f68 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -98,7 +98,8 @@ module Homebrew if verbose? outdated_kegs = f.outdated_kegs(fetch_head: args.fetch_HEAD?) - current_version = if ENV["HOMEBREW_INSTALL_FROM_API"].present? && (f.core_formula? || f.tap.blank?) + current_version = if !f.head? && ENV["HOMEBREW_INSTALL_FROM_API"].present? && + (f.core_formula? || f.tap.blank?) Homebrew::API::Versions.latest_formula_version(f.name)&.to_s || f.pkg_version.to_s elsif f.alias_changed? && !f.latest_formula.latest_version_installed? latest = f.latest_formula diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 8182bb8e87..715bd8f859 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -160,6 +160,7 @@ module Homebrew if ENV["HOMEBREW_INSTALL_FROM_API"].present? formulae_to_install.map! do |formula| + next formula if formula.head? next formula if formula.tap.present? && !formula.core_formula? next formula unless Homebrew::API::Bottle.available?(formula.name) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index e4d3929b99..da242fcbf8 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -77,6 +77,10 @@ class Formula # e.g. `this-formula` attr_reader :name + # The path to the alias that was used to identify this {Formula}. + # e.g. `/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/another-name-for-this-formula` + attr_reader :bottle_path + # The path to the alias that was used to identify this {Formula}. # e.g. `/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/another-name-for-this-formula` attr_reader :alias_path @@ -308,9 +312,20 @@ class Formula full_name_with_optional_tap(installed_alias_name) end + def prefix_formula_file + return unless prefix.directory? + + prefix/".brew/#{name}.rb" + end + # The path that was specified to find this formula. def specified_path - alias_path || path + default_specified_path = alias_path || path + + return default_specified_path if default_specified_path.present? && default_specified_path.exist? + return local_bottle_path if local_bottle_path.present? && local_bottle_path.exist? + + default_specified_path end # The name specified to find this formula. @@ -523,7 +538,7 @@ class Formula # exists and is not empty. # @private def latest_version_installed? - latest_prefix = if ENV["HOMEBREW_INSTALL_FROM_API"].present? && + latest_prefix = if !head? && ENV["HOMEBREW_INSTALL_FROM_API"].present? && (latest_pkg_version = Homebrew::API::Versions.latest_formula_version(name)) prefix latest_pkg_version else @@ -1343,7 +1358,7 @@ class Formula Formula.cache[:outdated_kegs][cache_key] ||= begin all_kegs = [] current_version = T.let(false, T::Boolean) - latest_version = if ENV["HOMEBREW_INSTALL_FROM_API"].present? && (core_formula? || tap.blank?) + latest_version = if !head? && ENV["HOMEBREW_INSTALL_FROM_API"].present? && (core_formula? || tap.blank?) Homebrew::API::Versions.latest_formula_version(name) || pkg_version else pkg_version diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 721baa0696..ee08ec7fd6 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -287,7 +287,7 @@ module FormulaCellarChecks def check_cpuid_instruction(formula) return unless formula.prefix.directory? # TODO: add methods to `utils/ast` to allow checking for method use - return unless formula.path.read.include? "ENV.runtime_cpu_detection" + return unless formula.prefix_formula_file.read.include? "ENV.runtime_cpu_detection" # Checking for `cpuid` only makes sense on Intel: # https://en.wikipedia.org/wiki/CPUID return unless Hardware::CPU.intel? diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index 7ce6b00c08..8dba8022f6 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -41,7 +41,7 @@ class Tab < OpenStruct "source" => { "path" => formula.specified_path.to_s, "tap" => formula.tap&.name, - "tap_git_head" => formula.tap&.git_head, + "tap_git_head" => nil, # Filled in later if possible "spec" => formula.active_spec_sym.to_s, "versions" => { "stable" => formula.stable&.version.to_s, @@ -52,6 +52,9 @@ class Tab < OpenStruct "built_on" => DevelopmentTools.build_system_info, } + # We can only get `tap_git_head` if the tap is installed locally + attributes["source"]["tap_git_head"] = formula.tap.git_head if formula.tap&.installed? + new(attributes) end