implement formulary#find_with_priority

This commit is contained in:
CNA-Bld 2015-08-09 22:43:01 +08:00 committed by Mike McQuaid
parent 1a82b2133e
commit 194618beb8
3 changed files with 32 additions and 4 deletions

View File

@ -29,7 +29,11 @@ module Homebrew
ARGV.named.each_with_index do |f, i|
puts unless i == 0
begin
info_formula Formulary.factory(f)
if f.include?("/") || File.exist?(f)
info_formula Formulary.factory(f)
else
info_formula Formulary.find_with_priority(f)
end
rescue FormulaUnavailableError
# No formula with this name, try a blacklist lookup
if (blacklist = blacklisted?(f))

View File

@ -13,7 +13,13 @@ module HomebrewArgvExtension
def formulae
require "formula"
@formulae ||= (downcased_unique_named - casks).map { |name| Formulary.factory(name, spec) }
@formulae ||= (downcased_unique_named - casks).map do |name|
if name.include?("/") || File.exist?(name)
Formulary.factory(name, spec)
else
Formulary.find_with_priority(name, spec)
end
end
end
def resolved_formulae

View File

@ -250,9 +250,9 @@ class Formulary
Pathname.new("#{HOMEBREW_LIBRARY}/Formula/#{name.downcase}.rb")
end
def self.tap_paths(name)
def self.tap_paths(name, taps=Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"])
name = name.downcase
Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"].map do |tap|
taps.map do |tap|
Pathname.glob([
"#{tap}Formula/#{name}.rb",
"#{tap}HomebrewFormula/#{name}.rb",
@ -260,4 +260,22 @@ class Formulary
]).detect(&:file?)
end.compact
end
def self.find_with_priority(ref, spec=:stable)
possible_pinned_tap_formulae = tap_paths(ref, Dir["#{HOMEBREW_LIBRARY}/PinnedTaps/*/*/"]).map(&:realpath)
if possible_pinned_tap_formulae.size > 1
raise TapFormulaAmbiguityError.new(ref, possible_pinned_tap_formulae)
elsif possible_pinned_tap_formulae.size == 1
selected_formula = factory(possible_pinned_tap_formulae.first, spec)
if core_path(ref).file?
opoo <<-EOS.undent
#{ref} is provided by core, but is now shadowed by #{selected_formula.full_name}.
To refer to the core formula, use Homebrew/homebrew/#{ref} instead.
EOS
end
selected_formula
else
factory(ref, spec)
end
end
end