diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/brew.h.rb | 27 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 33 |
2 files changed, 33 insertions, 27 deletions
diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb index 875f61be0..0d977ae95 100644 --- a/Library/Homebrew/brew.h.rb +++ b/Library/Homebrew/brew.h.rb @@ -144,31 +144,12 @@ def clean f end -# NOTE this is ugly code, and inefficient too, and can have infinite cycles -# I have no time currently to improve it, feel free to submit a more elegant -# solution. Thanks! --mxcl -def expand_deps fae +def expand_deps ff deps = [] - fae.each do |f| - case f.deps - when String, Array - f.deps.each do |name| - f = Formula.factory name - deps << expand_deps(f) if f.deps # hideous inefficient - deps << f unless f.installed? - end - when Hash - # TODO implement optional and recommended - names = [] - f.deps.each_value {|v| names << v} - ff=names.flatten.collect {|name| Formula.factory name} - deps << expand_deps(ff) - end - deps << f + ff.deps.collect do |f| + deps += expand_deps(Formula.factory(f)) end - - # TODO much more efficient to use a set and not recurse stuff already done - return deps.flatten.uniq + deps << ff end 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 |
