diff options
| author | CNA-Bld | 2015-08-09 22:43:01 +0800 |
|---|---|---|
| committer | Mike McQuaid | 2015-08-10 12:17:26 +0100 |
| commit | 194618beb8261f035f4d0049ee80770a37cad7a6 (patch) | |
| tree | 675a60724156bd57cf9397f0665f7aa3329c39ec /Library/Homebrew | |
| parent | 1a82b2133eed0599df2375b870bfe4cbf28a02aa (diff) | |
| download | brew-194618beb8261f035f4d0049ee80770a37cad7a6.tar.bz2 | |
implement formulary#find_with_priority
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/cmd/info.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/extend/ARGV.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/formulary.rb | 22 |
3 files changed, 32 insertions, 4 deletions
diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 3117ebf2c..854344bd4 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -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)) diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index 133f1062b..5a13230ac 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -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 diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 9ac63d7eb..717395f7c 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -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 |
