Load formulae from their aliases using the API
This commit is contained in:
parent
1b3f5980be
commit
e8f2d8f6c5
@ -26,7 +26,7 @@ module Homebrew
|
|||||||
Homebrew::API.fetch "#{formula_api_path}/#{name}.json"
|
Homebrew::API.fetch "#{formula_api_path}/#{name}.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Array) }
|
sig { returns(Hash) }
|
||||||
def all_formulae
|
def all_formulae
|
||||||
@all_formulae ||= begin
|
@all_formulae ||= begin
|
||||||
curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json]
|
curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json]
|
||||||
@ -37,11 +37,23 @@ module Homebrew
|
|||||||
|
|
||||||
json_formulae = JSON.parse(cached_formula_json_file.read)
|
json_formulae = JSON.parse(cached_formula_json_file.read)
|
||||||
|
|
||||||
|
@all_aliases = {}
|
||||||
json_formulae.to_h do |json_formula|
|
json_formulae.to_h do |json_formula|
|
||||||
|
json_formula["aliases"].each do |alias_name|
|
||||||
|
@all_aliases[alias_name] = json_formula["name"]
|
||||||
|
end
|
||||||
|
|
||||||
[json_formula["name"], json_formula.except("name")]
|
[json_formula["name"], json_formula.except("name")]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Hash) }
|
||||||
|
def all_aliases
|
||||||
|
all_formulae if @all_aliases.blank?
|
||||||
|
|
||||||
|
@all_aliases
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1165,7 +1165,7 @@ class FormulaInstaller
|
|||||||
|
|
||||||
if pour_bottle?(output_warning: true)
|
if pour_bottle?(output_warning: true)
|
||||||
formula.fetch_bottle_tab
|
formula.fetch_bottle_tab
|
||||||
elsif Homebrew::EnvConfig.install_from_api?
|
elsif formula.core_formula? && Homebrew::EnvConfig.install_from_api?
|
||||||
odie "Unable to build #{formula.name} from source with HOMEBREW_INSTALL_FROM_API."
|
odie "Unable to build #{formula.name} from source with HOMEBREW_INSTALL_FROM_API."
|
||||||
else
|
else
|
||||||
formula.fetch_patches
|
formula.fetch_patches
|
||||||
|
|||||||
@ -529,6 +529,14 @@ module Formulary
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Load aliases from the API.
|
||||||
|
class AliasAPILoader < FormulaAPILoader
|
||||||
|
def initialize(alias_name)
|
||||||
|
super Homebrew::API::Formula.all_aliases[alias_name]
|
||||||
|
@alias_path = Formulary.core_alias_path(alias_name).to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return a {Formula} instance for the given reference.
|
# Return a {Formula} instance for the given reference.
|
||||||
# `ref` is a string containing:
|
# `ref` is a string containing:
|
||||||
#
|
#
|
||||||
@ -655,6 +663,7 @@ module Formulary
|
|||||||
if ref.start_with?("homebrew/core/") && Homebrew::EnvConfig.install_from_api?
|
if ref.start_with?("homebrew/core/") && Homebrew::EnvConfig.install_from_api?
|
||||||
name = ref.split("/", 3).last
|
name = ref.split("/", 3).last
|
||||||
return FormulaAPILoader.new(name) if Homebrew::API::Formula.all_formulae.key?(name)
|
return FormulaAPILoader.new(name) if Homebrew::API::Formula.all_formulae.key?(name)
|
||||||
|
return AliasAPILoader.new(name) if Homebrew::API::Formula.all_aliases.key?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
return TapLoader.new(ref, from: from)
|
return TapLoader.new(ref, from: from)
|
||||||
@ -662,14 +671,15 @@ module Formulary
|
|||||||
|
|
||||||
return FromPathLoader.new(ref) if File.extname(ref) == ".rb" && Pathname.new(ref).expand_path.exist?
|
return FromPathLoader.new(ref) if File.extname(ref) == ".rb" && Pathname.new(ref).expand_path.exist?
|
||||||
|
|
||||||
if Homebrew::EnvConfig.install_from_api? && Homebrew::API::Formula.all_formulae.key?(ref)
|
if Homebrew::EnvConfig.install_from_api?
|
||||||
return FormulaAPILoader.new(ref)
|
return FormulaAPILoader.new(ref) if Homebrew::API::Formula.all_formulae.key?(ref)
|
||||||
|
return AliasAPILoader.new(ref) if Homebrew::API::Formula.all_aliases.key?(ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
formula_with_that_name = core_path(ref)
|
formula_with_that_name = core_path(ref)
|
||||||
return FormulaLoader.new(ref, formula_with_that_name) if formula_with_that_name.file?
|
return FormulaLoader.new(ref, formula_with_that_name) if formula_with_that_name.file?
|
||||||
|
|
||||||
possible_alias = CoreTap.instance.alias_dir/ref
|
possible_alias = core_alias_path(ref)
|
||||||
return AliasLoader.new(possible_alias) if possible_alias.file?
|
return AliasLoader.new(possible_alias) if possible_alias.file?
|
||||||
|
|
||||||
possible_tap_formulae = tap_paths(ref)
|
possible_tap_formulae = tap_paths(ref)
|
||||||
@ -705,6 +715,10 @@ module Formulary
|
|||||||
CoreTap.instance.formula_dir/"#{name.to_s.downcase}.rb"
|
CoreTap.instance.formula_dir/"#{name.to_s.downcase}.rb"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.core_alias_path(name)
|
||||||
|
CoreTap.instance.alias_dir/name.to_s.downcase
|
||||||
|
end
|
||||||
|
|
||||||
def self.tap_paths(name, taps = Dir[HOMEBREW_LIBRARY/"Taps/*/*/"])
|
def self.tap_paths(name, taps = Dir[HOMEBREW_LIBRARY/"Taps/*/*/"])
|
||||||
name = name.to_s.downcase
|
name = name.to_s.downcase
|
||||||
taps.map do |tap|
|
taps.map do |tap|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user