aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula.rb
diff options
context:
space:
mode:
authorMax Howell2009-09-18 19:16:39 +0100
committerMax Howell2009-09-21 18:27:48 +0100
commit68108e109839a901313b9933cbb1e3202aed90cf (patch)
tree124d204c43534f4e8171c5d278d4cb09d46f06a2 /Library/Homebrew/formula.rb
parent0d1ec9641403ea2de9588ffdb22b68a23e6c2547 (diff)
downloadhomebrew-68108e109839a901313b9933cbb1e3202aed90cf.tar.bz2
Dependency resolution with fancy syntax
Is it a DSL? No. But people call it that apparently. To add a dependency: class Doe <Formula depends_on 'ray' depends_on 'mee' => :optional depends_on 'far' => :recommended depends_on Sew.new end Sew would be a formula you have defined in this Formula file. This is useful, eg. see Python's formula. Formula specified in this fashion cannot be linked into the HOMEBREW_PREFIX, they are considered private libraries. This allows you to create custom installations that are very specific to your formula. More features to come, like specifying versions
Diffstat (limited to 'Library/Homebrew/formula.rb')
-rw-r--r--Library/Homebrew/formula.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 9c5123545..a4bebdd2b 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -114,8 +114,6 @@ class Formula
# :p2 => ['http://moo.com/patch5', 'http://moo.com/patch6']
# }
def patches; [] end
- # reimplement and specify dependencies
- def deps; end
# sometimes the clean process breaks things, return true to skip anything
def skip_clean? path; false end
@@ -157,6 +155,7 @@ class Formula
end
def self.factory name
+ return name if name.kind_of? Formula
require self.path(name)
return eval(self.class(name)).new(name)
rescue LoadError
@@ -167,6 +166,10 @@ class Formula
HOMEBREW_PREFIX+'Library'+'Formula'+"#{name.downcase}.rb"
end
+ def deps
+ self.class.deps or []
+ end
+
protected
# Pretty titles the command and buffers stdout/stderr
# Throws if there's an error
@@ -280,9 +283,31 @@ private
end
class <<self
- attr_reader :url, :version, :homepage, :head
+ attr_reader :url, :version, :homepage, :head, :deps
attr_reader *CHECKSUM_TYPES
- end
+
+ def depends_on name, *args
+ @deps ||= []
+
+ case name
+ when String
+ # noop
+ when Hash
+ name = name.keys.first # indeed, we only support one mapping
+ when Symbol
+ name = name.to_s
+ when Formula
+ @deps << name
+ return # we trust formula dev to not dupe their own instantiations
+ else
+ raise "Unsupported type #{name.class}"
+ end
+
+ # we get duplicates because every new fork of this process repeats this
+ # step for some reason I am not sure about
+ @deps << name unless @deps.include? name
+ end
+ end
end
# see ack.rb for an example usage