Merge pull request #15434 from reitermarkus/formula-loaded-from-api

Add `Formula#loaded_from_api?`.
This commit is contained in:
Markus Reiter 2023-05-16 11:07:06 +02:00 committed by GitHub
commit 34dd47d7d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 7 deletions

View File

@ -427,6 +427,12 @@ class Formula
# @see .version
delegate version: :active_spec
# Whether this formula was loaded using the formulae.brew.sh API
# @!method loaded_from_api?
# @private
# @see .loaded_from_api?
delegate loaded_from_api?: :"self.class"
def update_head_version
return unless head?
return unless head.downloader.is_a?(VCSDownloadStrategy)
@ -2238,7 +2244,7 @@ class Formula
hash = to_hash
# Take from API, merging in local install status.
if self.class.loaded_from_api && !Homebrew::EnvConfig.no_install_from_api?
if loaded_from_api? && !Homebrew::EnvConfig.no_install_from_api?
json_formula = Homebrew::API::Formula.all_formulae[name].dup
return json_formula.merge(
hash.slice("name", "installed", "linked_keg", "pinned", "outdated"),
@ -2758,6 +2764,7 @@ class Formula
@skip_clean_paths = Set.new
@link_overwrite_paths = Set.new
@allowed_missing_libraries = Set.new
@loaded_from_api = false
end
end
@ -2784,7 +2791,7 @@ class Formula
# Whether this formula was loaded using the formulae.brew.sh API
# @private
attr_accessor :loaded_from_api
attr_predicate :loaded_from_api?
# Whether this formula contains OS/arch-specific blocks
# (e.g. `on_macos`, `on_arm`, `on_monterey :or_older`, `on_system :linux, macos: :big_sur_or_newer`).

View File

@ -3,6 +3,8 @@
# This file provides definitions for Forwardable#delegate, which is currently not supported by Sorbet.
class Formula
sig { returns(T::Boolean) }
def loaded_from_api?; end
def bottle_defined?; end
def bottle_tag?(tag = nil); end
def bottled?(tag = nil); end

View File

@ -1191,7 +1191,7 @@ on_request: installed_on_request?, options: options)
if pour_bottle?(output_warning: true)
formula.fetch_bottle_tab
else
@formula = Homebrew::API::Formula.source_download(formula) if formula.class.loaded_from_api
@formula = Homebrew::API::Formula.source_download(formula) if formula.loaded_from_api?
formula.fetch_patches
formula.resources.each(&:fetch)
@ -1227,7 +1227,7 @@ on_request: installed_on_request?, options: options)
tab.unused_options = []
tab.built_as_bottle = true
tab.poured_from_bottle = true
tab.loaded_from_api = formula.class.loaded_from_api
tab.loaded_from_api = formula.loaded_from_api?
tab.installed_as_dependency = installed_as_dependency?
tab.installed_on_request = installed_on_request?
tab.time = Time.now.to_i

View File

@ -136,7 +136,7 @@ module Formulary
mod.const_set(:BUILD_FLAGS, flags)
class_s = Formulary.class_s(name)
class_name = class_s(name)
json_formula = Homebrew::API::Formula.all_formulae[name]
json_formula = Homebrew::API.merge_variations(json_formula)
@ -147,6 +147,8 @@ module Formulary
end
klass = Class.new(::Formula) do
@loaded_from_api = true
desc json_formula["desc"]
homepage json_formula["homepage"]
license SPDX.string_to_license_expression(json_formula["license"])
@ -311,8 +313,7 @@ module Formulary
end
end
T.cast(klass, T.class_of(Formula)).loaded_from_api = true
mod.const_set(class_s, klass)
mod.const_set(class_name, klass)
cache[:api] ||= {}
cache[:api][name] = klass