diff options
| author | Adam Vandenberg | 2009-11-16 15:31:15 -0800 |
|---|---|---|
| committer | Adam Vandenberg | 2009-11-19 14:03:07 -0800 |
| commit | 95e398ab130b1edd5346b74e684c30f02ce61e62 (patch) | |
| tree | 7731c3702c4cabdaa126f5ebd3714e6d86a02d2e /Library | |
| parent | af29299f37417f436f6fb0a612578abb3edfd21b (diff) | |
| download | brew-95e398ab130b1edd5346b74e684c30f02ce61e62.tar.bz2 | |
Add alias support to formulae
* brew install will find an aliased formula
* aliases are searched against
* warn when creating a new formula that has an existing alias.
If Subversion has an alias "svn", then warn when the user tries to
create a new formula "svn". The formula can still be created, though
the user should make sure it's not a duplicate of the existing
aliased one.
Subversion and Objective-Caml formulas get some alises here, so we have
something to test against.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/brew.h.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 36 |
2 files changed, 41 insertions, 2 deletions
diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb index d8ab4305e..b0b795999 100644 --- a/Library/Homebrew/brew.h.rb +++ b/Library/Homebrew/brew.h.rb @@ -29,6 +29,13 @@ def __make url, name path = Formula.path name raise "#{path} already exists" if path.exist? + + # Check if a formula aliased to this name exists. + already_aka = Formulary.find_alias name + if already_aka != nil + opoo "Formula #{already_aka} is aliased to #{name}." + puts "Please check if you are creating a duplicate." + end template=<<-EOS require 'formula' diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 0cc084705..029aef77c 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -52,6 +52,22 @@ class Formulary yield name, klass end end + + def self.get_aliases + aliases = {} + Formulary.read_all do |name, klass| + aka = klass.aliases + next if aka == nil + + aka.each {|item| aliases[item.to_s] = name } + end + return aliases + end + + def self.find_alias name + aliases = Formulary.get_aliases + return aliases[name] + end end @@ -225,7 +241,15 @@ class Formula require name name = path.stem else - require self.path(name) + begin + require self.path(name) + rescue LoadError => e + # Couldn't find formula 'name', so look for an alias. + real_name = Formulary.find_alias name + raise e if real_name == nil + puts "#{name} is an alias for #{real_name}" + name = real_name + end end begin klass_name =self.class_s(name) @@ -418,7 +442,7 @@ private end end - attr_rw :url, :version, :homepage, :specs, :deps, *CHECKSUM_TYPES + attr_rw :url, :version, :homepage, :specs, :deps, :aliases, *CHECKSUM_TYPES def head val=nil, specs=nil if specs @@ -426,6 +450,14 @@ private end val.nil? ? @head : @head = val end + + def aka *args + @aliases ||= [] + + args.each do |item| + @aliases << item.to_s + end + end def depends_on name, *args @deps ||= [] |
