Merge pull request #12087 from Rylan12/api-head-install-fixes

install: fix `HEAD` installations with `HOMEBREW_INSTALL_FROM_API`
This commit is contained in:
Mike McQuaid 2021-09-21 09:43:33 +01:00 committed by GitHub
commit a3e652e8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View File

@ -98,7 +98,8 @@ 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 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 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? elsif f.alias_changed? && !f.latest_formula.latest_version_installed?
latest = f.latest_formula latest = f.latest_formula

View File

@ -160,6 +160,7 @@ module Homebrew
if ENV["HOMEBREW_INSTALL_FROM_API"].present? if ENV["HOMEBREW_INSTALL_FROM_API"].present?
formulae_to_install.map! do |formula| formulae_to_install.map! do |formula|
next formula if formula.head?
next formula if formula.tap.present? && !formula.core_formula? next formula if formula.tap.present? && !formula.core_formula?
next formula unless Homebrew::API::Bottle.available?(formula.name) next formula unless Homebrew::API::Bottle.available?(formula.name)

View File

@ -310,7 +310,12 @@ class Formula
# The path that was specified to find this formula. # The path that was specified to find this formula.
def specified_path def specified_path
alias_path || path default_specified_path = alias_path || path
return default_specified_path if default_specified_path.presence&.exist?
return local_bottle_path if local_bottle_path.presence&.exist?
default_specified_path
end end
# The name specified to find this formula. # The name specified to find this formula.
@ -523,7 +528,7 @@ class Formula
# exists and is not empty. # exists and is not empty.
# @private # @private
def latest_version_installed? 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)) (latest_pkg_version = Homebrew::API::Versions.latest_formula_version(name))
prefix latest_pkg_version prefix latest_pkg_version
else else
@ -1343,7 +1348,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 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 Homebrew::API::Versions.latest_formula_version(name) || pkg_version
else else
pkg_version pkg_version

View File

@ -287,7 +287,7 @@ module FormulaCellarChecks
def check_cpuid_instruction(formula) def check_cpuid_instruction(formula)
return unless formula.prefix.directory? return unless formula.prefix.directory?
# TODO: add methods to `utils/ast` to allow checking for method use # 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/".brew/#{formula.name}.rb").read.include? "ENV.runtime_cpu_detection"
# Checking for `cpuid` only makes sense on Intel: # Checking for `cpuid` only makes sense on Intel:
# https://en.wikipedia.org/wiki/CPUID # https://en.wikipedia.org/wiki/CPUID
return unless Hardware::CPU.intel? return unless Hardware::CPU.intel?

View File

@ -41,7 +41,7 @@ class Tab < OpenStruct
"source" => { "source" => {
"path" => formula.specified_path.to_s, "path" => formula.specified_path.to_s,
"tap" => formula.tap&.name, "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, "spec" => formula.active_spec_sym.to_s,
"versions" => { "versions" => {
"stable" => formula.stable&.version.to_s, "stable" => formula.stable&.version.to_s,
@ -52,6 +52,9 @@ class Tab < OpenStruct
"built_on" => DevelopmentTools.build_system_info, "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) new(attributes)
end end