Better support for brew install <url>
Brews installed via URL are now checked from the cache when
other commands are run. This allows for instance:
brew install <vim-url>
brew info vim
This commit is contained in:
parent
c92ed8eb04
commit
5d5a8ed32f
@ -350,7 +350,9 @@ class Formula
|
|||||||
|
|
||||||
def self.canonical_name name
|
def self.canonical_name name
|
||||||
formula_with_that_name = HOMEBREW_REPOSITORY+"Library/Formula/#{name}.rb"
|
formula_with_that_name = HOMEBREW_REPOSITORY+"Library/Formula/#{name}.rb"
|
||||||
possible_alias = HOMEBREW_REPOSITORY+"Library/Aliases"+name
|
possible_alias = HOMEBREW_REPOSITORY+"Library/Aliases/#{name}"
|
||||||
|
possible_cached_formula = HOMEBREW_CACHE_FORMULA+"#{name}.rb"
|
||||||
|
|
||||||
if name.include? "/"
|
if name.include? "/"
|
||||||
# Don't resolve paths or URLs
|
# Don't resolve paths or URLs
|
||||||
name
|
name
|
||||||
@ -358,6 +360,8 @@ class Formula
|
|||||||
name
|
name
|
||||||
elsif possible_alias.file?
|
elsif possible_alias.file?
|
||||||
possible_alias.realpath.basename('.rb').to_s
|
possible_alias.realpath.basename('.rb').to_s
|
||||||
|
elsif possible_cached_formula.file?
|
||||||
|
possible_cached_formula.to_s
|
||||||
else
|
else
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
@ -371,26 +375,25 @@ class Formula
|
|||||||
if name =~ %r[(https?|ftp)://]
|
if name =~ %r[(https?|ftp)://]
|
||||||
url = name
|
url = name
|
||||||
name = Pathname.new(name).basename
|
name = Pathname.new(name).basename
|
||||||
target_file = (HOMEBREW_CACHE+"Formula"+name)
|
target_file = HOMEBREW_CACHE_FORMULA+name
|
||||||
name = name.basename(".rb").to_s
|
name = name.basename(".rb").to_s
|
||||||
|
|
||||||
(HOMEBREW_CACHE+"Formula").mkpath
|
HOMEBREW_CACHE_FORMULA.mkpath
|
||||||
FileUtils.rm target_file, :force => true
|
FileUtils.rm target_file, :force => true
|
||||||
curl url, '-o', target_file
|
curl url, '-o', target_file
|
||||||
|
|
||||||
require target_file
|
require target_file
|
||||||
install_type = :from_url
|
install_type = :from_url
|
||||||
else
|
else
|
||||||
# Check if this is a name or pathname
|
name = Formula.canonical_name(name)
|
||||||
|
# If name was a path or mapped to a cached formula
|
||||||
if name.include? "/"
|
if name.include? "/"
|
||||||
# For paths, just require the path
|
|
||||||
require name
|
require name
|
||||||
path = Pathname.new(name)
|
path = Pathname.new(name)
|
||||||
name = path.stem
|
name = path.stem
|
||||||
install_type = :from_path
|
install_type = :from_path
|
||||||
target_file = path.to_s
|
target_file = path.to_s
|
||||||
else
|
else
|
||||||
name = Formula.canonical_name(name)
|
|
||||||
# For names, map to the path and then require
|
# For names, map to the path and then require
|
||||||
require Formula.path(name)
|
require Formula.path(name)
|
||||||
install_type = :from_name
|
install_type = :from_name
|
||||||
@ -400,7 +403,9 @@ class Formula
|
|||||||
begin
|
begin
|
||||||
klass_name = self.class_s(name)
|
klass_name = self.class_s(name)
|
||||||
klass = Object.const_get klass_name
|
klass = Object.const_get klass_name
|
||||||
rescue NameError
|
rescue NameError => e
|
||||||
|
puts "NameError"
|
||||||
|
puts e
|
||||||
# TODO really this text should be encoded into the exception
|
# TODO really this text should be encoded into the exception
|
||||||
# and only shown if the UI deems it correct to show it
|
# and only shown if the UI deems it correct to show it
|
||||||
onoe "class \"#{klass_name}\" expected but not found in #{name}.rb"
|
onoe "class \"#{klass_name}\" expected but not found in #{name}.rb"
|
||||||
@ -410,7 +415,9 @@ class Formula
|
|||||||
|
|
||||||
return klass.new(name) if install_type == :from_name
|
return klass.new(name) if install_type == :from_name
|
||||||
return klass.new(name, target_file)
|
return klass.new(name, target_file)
|
||||||
rescue LoadError
|
rescue LoadError => e
|
||||||
|
puts "LoadError"
|
||||||
|
puts e
|
||||||
raise FormulaUnavailableError.new(name)
|
raise FormulaUnavailableError.new(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,9 @@ else
|
|||||||
Pathname.new("~/Library/Caches/Homebrew").expand_path
|
Pathname.new("~/Library/Caches/Homebrew").expand_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Where brews installed via URL are cached
|
||||||
|
HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula"
|
||||||
|
|
||||||
if not defined? HOMEBREW_BREW_FILE
|
if not defined? HOMEBREW_BREW_FILE
|
||||||
HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] || `which brew`.chomp
|
HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] || `which brew`.chomp
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user