Resolve formulae in brew cleanup.

This commit is contained in:
Markus Reiter 2018-09-11 17:44:18 +02:00
parent ca86f07039
commit 769d89dead
3 changed files with 34 additions and 30 deletions

View File

@ -166,7 +166,7 @@ module Homebrew
else
args.each do |arg|
formula = begin
Formula[arg]
Formulary.resolve(arg)
rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
nil
end

View File

@ -54,35 +54,7 @@ module HomebrewArgvExtension
def resolved_formulae
require "formula"
@resolved_formulae ||= (downcased_unique_named - casks).map do |name|
if name.include?("/") || File.exist?(name)
f = Formulary.factory(name, spec)
if f.any_version_installed?
tab = Tab.for_formula(f)
resolved_spec = spec(nil) || tab.spec
f.active_spec = resolved_spec if f.send(resolved_spec)
f.build = tab
if f.head? && tab.tabfile
k = Keg.new(tab.tabfile.parent)
f.version.update_commit(k.version.version.commit) if k.version.head?
end
end
else
rack = Formulary.to_rack(name)
alias_path = Formulary.factory(name).alias_path
f = Formulary.from_rack(rack, spec(nil), alias_path: alias_path)
end
# If this formula was installed with an alias that has since changed,
# then it was specified explicitly in ARGV. (Using the alias would
# instead have found the new formula.)
#
# Because of this, the user is referring to this specific formula,
# not any formula targetted by the same alias, so in this context
# the formula shouldn't be considered outdated if the alias used to
# install it has changed.
f.follow_installed_alias = false
f
Formulary.resolve(name, spec: spec(nil))
end.uniq(&:name)
end

View File

@ -47,6 +47,38 @@ module Formulary
cache[path] = klass
end
def self.resolve(name, spec: nil)
if name.include?("/") || File.exist?(name)
f = factory(name, *spec)
if f.any_version_installed?
tab = Tab.for_formula(f)
resolved_spec = spec || tab.spec
f.active_spec = resolved_spec if f.send(resolved_spec)
f.build = tab
if f.head? && tab.tabfile
k = Keg.new(tab.tabfile.parent)
f.version.update_commit(k.version.version.commit) if k.version.head?
end
end
else
rack = to_rack(name)
alias_path = factory(name).alias_path
f = from_rack(rack, *spec, alias_path: alias_path)
end
# If this formula was installed with an alias that has since changed,
# then it was specified explicitly in ARGV. (Using the alias would
# instead have found the new formula.)
#
# Because of this, the user is referring to this specific formula,
# not any formula targetted by the same alias, so in this context
# the formula shouldn't be considered outdated if the alias used to
# install it has changed.
f.follow_installed_alias = false
f
end
def self.ensure_utf8_encoding(io)
io.set_encoding(Encoding::UTF_8)
end