Include core formulae from API in Formula.all
.
This is needed to allow `Formula.all` to behave as expected when using the API. Let's also (immediately, because it's broken) deprecate the `CoreTap#formula_files` method. Fixes #15122
This commit is contained in:
parent
043b9512e4
commit
cd414bd95f
@ -1827,12 +1827,6 @@ class Formula
|
||||
CoreTap.instance.formula_names
|
||||
end
|
||||
|
||||
# an array of all core {Formula} files
|
||||
# @private
|
||||
def self.core_files
|
||||
CoreTap.instance.formula_files
|
||||
end
|
||||
|
||||
# an array of all tap {Formula} names
|
||||
# @private
|
||||
def self.tap_names
|
||||
@ -1851,12 +1845,6 @@ class Formula
|
||||
@names ||= (core_names + tap_names.map { |name| name.split("/").last }).uniq.sort
|
||||
end
|
||||
|
||||
# an array of all {Formula} files
|
||||
# @private
|
||||
def self.files
|
||||
@files ||= core_files + tap_files
|
||||
end
|
||||
|
||||
# an array of all {Formula} names, which the tap formulae have the fully-qualified name
|
||||
# @private
|
||||
def self.full_names
|
||||
@ -1872,11 +1860,11 @@ class Formula
|
||||
odeprecated "Formula#all without --all or HOMEBREW_EVAL_ALL"
|
||||
end
|
||||
|
||||
files.map do |file|
|
||||
Formulary.factory(file)
|
||||
(core_names + tap_files).map do |name_or_file|
|
||||
Formulary.factory(name_or_file)
|
||||
rescue FormulaUnavailableError, FormulaUnreadableError => e
|
||||
# Don't let one broken formula break commands. But do complain.
|
||||
onoe "Failed to import: #{file}"
|
||||
onoe "Failed to import: #{name_or_file}"
|
||||
$stderr.puts e
|
||||
|
||||
nil
|
||||
|
@ -514,11 +514,17 @@ class Tap
|
||||
def self.formula_files_by_name(tap)
|
||||
cache_key = "formula_files_by_name_#{tap}"
|
||||
cache.fetch(cache_key) do |key|
|
||||
cache[key] = tap.formula_files.each_with_object({}) do |file, hash|
|
||||
# If there's more than one file with the same basename: intentionally
|
||||
# ignore the later ones here.
|
||||
hash[file.basename.to_s] ||= file
|
||||
end
|
||||
cache[key] = tap.formula_files_by_name
|
||||
end
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { returns(T::Hash[String, Pathname]) }
|
||||
def formula_files_by_name
|
||||
formula_files.each_with_object({}) do |file, hash|
|
||||
# If there's more than one file with the same basename: intentionally
|
||||
# ignore the later ones here.
|
||||
hash[file.basename.to_s] ||= file
|
||||
end
|
||||
end
|
||||
|
||||
@ -1011,6 +1017,14 @@ class CoreTap < Tap
|
||||
Homebrew::API::Formula.all_aliases.keys
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { returns(T::Array[Pathname]) }
|
||||
def formula_files
|
||||
return super if Homebrew::EnvConfig.no_install_from_api? || installed?
|
||||
|
||||
raise TapUnavailableError, name
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { returns(T::Array[String]) }
|
||||
def formula_names
|
||||
@ -1018,6 +1032,27 @@ class CoreTap < Tap
|
||||
|
||||
Homebrew::API::Formula.all_formulae.keys
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { returns(T::Hash[String, Pathname]) }
|
||||
def formula_files_by_name
|
||||
return super if Homebrew::EnvConfig.no_install_from_api?
|
||||
|
||||
formula_names.each_with_object({}) do |name, hash|
|
||||
# If there's more than one file with the same basename: intentionally
|
||||
# ignore the later ones here.
|
||||
hash[name] ||= sharded_formula_path(name)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# @private
|
||||
sig { params(name: String).returns(Pathname) }
|
||||
def sharded_formula_path(name)
|
||||
# TODO: add sharding logic.
|
||||
formula_dir/"#{name}.rb"
|
||||
end
|
||||
end
|
||||
|
||||
# Permanent configuration per {Tap} using `git-config(1)`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user