diff options
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/compat/compatibility.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/dependencies.rb | 26 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 30 |
3 files changed, 45 insertions, 26 deletions
diff --git a/Library/Homebrew/compat/compatibility.rb b/Library/Homebrew/compat/compatibility.rb index f0d6ab0b1..67f540844 100644 --- a/Library/Homebrew/compat/compatibility.rb +++ b/Library/Homebrew/compat/compatibility.rb @@ -99,6 +99,21 @@ class Formula val.nil? ? @bottle_sha1 : @bottle_sha1 = val end end + + # These methods return lists of Formula objects. + # They are eprecated in favor of Dependency::expand_dependencies + # and Formula#recursive_dependencies, which return lists of + # Dependency objects instead. + def self.expand_deps f + f.deps.map do |dep| + f_dep = Formula.factory dep.to_s + expand_deps(f_dep) << f_dep + end + end + + def recursive_deps + Formula.expand_deps(self).flatten.uniq + end end class UnidentifiedFormula < Formula diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index dd51a2131..5762ac82e 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -177,6 +177,32 @@ class Dependency def requested? ARGV.formulae.include?(to_formula) rescue false end + + # Expand the dependencies of f recursively, optionally yielding + # [f, dep] to allow callers to apply arbitrary filters to the list. + # The default filter, which is used when a block is not supplied, + # omits optionals and recommendeds based on what the dependent has + # asked for. + def self.expand(dependent, &block) + dependent.deps.map do |dep| + prune = catch(:prune) do + if block_given? + yield dependent, dep + elsif dep.optional? || dep.recommended? + Dependency.prune unless dependent.build.with?(dep.name) + end + end + + next if prune + + expand(dep.to_formula, &block) << dep + end.flatten.compact.uniq + end + + # Used to prune dependencies when calling expand_dependencies with a block. + def self.prune + throw(:prune, true) + end end # A base class for non-formula requirements needed by formulae. diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9801e0c47..e5b5d58fc 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -457,32 +457,10 @@ class Formula requirements.select { |r| r.is_a? ConflictRequirement } end - # for Formula objects - def self.expand_deps f - f.deps.map do |dep| - f_dep = Formula.factory dep.to_s - expand_deps(f_dep) << f_dep - end - end - - # for Dependency objects - def self.expand_dependencies f - f.deps.map do |dep| - f_dep = Formula.factory dep.to_s - expand_dependencies(f_dep) << dep - end - end - - # deps are in an installable order - # which means if a depends on b then b will be ordered before a in this list - def recursive_deps - Formula.expand_deps(self).flatten.uniq - end - - # Like recursive_deps, but returns a list of Dependency objects instead - # of Formula objects. - def recursive_dependencies - Formula.expand_dependencies(self).flatten.uniq + # Returns a list of Dependency objects in an installable order, which + # means if a depends on b then b will be ordered before a in this list + def recursive_dependencies(&block) + Dependency.expand(self, &block) end # The full set of Requirements for this formula's dependency tree. |
