Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 84024e64e3128a9f5ab0cbac19045fb7a8472225 1 parent 62cef23
Adam Vandenberg adamv authored
2  Library/Formula/objective-caml.rb
View
@@ -4,6 +4,8 @@ class ObjectiveCaml <Formula
@url='http://caml.inria.fr/pub/distrib/ocaml-3.11/ocaml-3.11.1.tar.bz2'
@homepage='http://caml.inria.fr/ocaml/index.en.html'
@md5='fe011781f37f6b41fe08e0706969a89e'
+
+ aka :ocaml, 'o-caml'
def install
system "./configure --prefix #{prefix}"
2  Library/Formula/subversion.rb
View
@@ -17,6 +17,8 @@ class Subversion <Formula
url 'http://subversion.tigris.org/downloads/subversion-1.6.6.tar.bz2'
homepage 'http://subversion.tigris.org/'
md5 'e5109da756d74c7d98f683f004a539af'
+
+ aka :svn
# Only need this on Snow Leopard; for Leopard the deps package
# builds it.
7 Library/Homebrew/brew.h.rb
View
@@ -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'
36 Library/Homebrew/formula.rb
View
@@ -52,6 +52,22 @@ def self.read_all
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 @@ def self.factory name
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 @@ def #{attr}(val=nil)
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 @@ def head val=nil, specs=nil
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 ||= []
4 bin/brew
View
@@ -98,7 +98,9 @@ begin
end
when 'search', '-S'
- formulae = (HOMEBREW_REPOSITORY+'Library/Formula').children.sort.map{|f| f.basename('.rb') }
+ require "formula"
+ formulae = Formulary.names with_aliases=true
+
if ARGV.first =~ /^\/(.*)\/$/
puts_columns formulae.grep(Regexp.new($1))
else
Please sign in to comment.
Something went wrong with that request. Please try again.