aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dependencies.rb
diff options
context:
space:
mode:
authorJack Nagel2013-01-23 00:26:26 -0600
committerJack Nagel2013-01-26 12:14:46 -0600
commit55681ca2019a5d52dc4982c64f65fca5a4bc974d (patch)
treeda89af3d2b818e11ad51cb459d6a55d02add394d /Library/Homebrew/dependencies.rb
parentd0161091d8a020652f046fc92db06570cf017376 (diff)
downloadbrew-55681ca2019a5d52dc4982c64f65fca5a4bc974d.tar.bz2
Dependency.expand_dependencies
Move Formula.expand_dependencies into the Dependency class, and extend it to allow arbitrary filters to be applied when enumerating deps. When supplied with a block, expand_dependencies will yield a [dependent, dependency] pair for each dependency, allowing callers to filter out dependencies that may not be applicable or useful in a given situation. Deps can be skipped by simple calling Dependency.prune in the block, e.g.: Dependency.expand_dependencies do |f, dep| Dependency.prune if dep.to_formula.installed? end The return value of the method is the filtered list. If no block is supplied, a default filter that omits optional or recommended deps based on what the dependent formula has requested is applied. Formula#recursive_dependencies is now implemented on top of this, allowing FormulaInstaller to exact detailed control over what deps are installed. `brew missing` and `brew upgrade` can learn to use this to apply the installed options set when expanding dependencies. Move Formula.expand_deps and Formula#recursive_deps into compat, because these methods do not respect the new optional and recommended tags and thus should no longer be used.
Diffstat (limited to 'Library/Homebrew/dependencies.rb')
-rw-r--r--Library/Homebrew/dependencies.rb26
1 files changed, 26 insertions, 0 deletions
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.