Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Add alias support to formulae
Browse files Browse the repository at this point in the history
* 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
adamv committed Nov 19, 2009
1 parent 62cef23 commit 84024e6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Library/Formula/objective-caml.rb
Expand Up @@ -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}"
Expand Down
2 changes: 2 additions & 0 deletions Library/Formula/subversion.rb
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions Library/Homebrew/brew.h.rb
Expand Up @@ -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'
Expand Down
36 changes: 34 additions & 2 deletions Library/Homebrew/formula.rb
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -418,14 +442,22 @@ 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
@specs = specs
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 ||= []
Expand Down
4 changes: 3 additions & 1 deletion bin/brew
Expand Up @@ -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
Expand Down

0 comments on commit 84024e6

Please sign in to comment.