aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2013-01-23 00:26:26 -0600
committerJack Nagel2013-01-26 12:14:45 -0600
commit6193167f5878bbc09b3417dc2b836be3b10d5b1e (patch)
tree7f38512a2e8e572d60a5cfbc830d6d73db29488a /Library
parent99850fcbda131cf7ec9699fa306feaa2a97e248f (diff)
downloadbrew-6193167f5878bbc09b3417dc2b836be3b10d5b1e.tar.bz2
Add support for optional and recommended deps
Optional deps are not installed by default but generate a corresponding "with-foo" option for the formula. Recommended deps _are_ installed by default, and generate a corresponding "without-foo" option.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/build_options.rb14
-rw-r--r--Library/Homebrew/formula.rb9
-rw-r--r--Library/Homebrew/test/test_build_options.rb7
3 files changed, 30 insertions, 0 deletions
diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb
index d0b1f0469..440e3ba78 100644
--- a/Library/Homebrew/build_options.rb
+++ b/Library/Homebrew/build_options.rb
@@ -40,6 +40,20 @@ class BuildOptions
@args.include? '--' + name
end
+ def with? name
+ if has_option? "with-#{name}"
+ include? "with-#{name}"
+ elsif has_option? "without-#{name}"
+ not include? "without-#{name}"
+ else
+ false
+ end
+ end
+
+ def without? name
+ not with? name
+ end
+
def head?
@args.flag? '--HEAD'
end
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 1b65efb46..fa4841dd7 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -829,6 +829,15 @@ private
# This method is called once by `factory` before creating any instances.
# It allows the DSL to finalize itself, reducing complexity in the constructor.
def finalize_dsl
+ # Synthesize options for optional dependencies
+ dependencies.deps.select(&:optional?).each do |dep|
+ option "with-#{dep.name}", "Build with #{dep.name} support"
+ end
+
+ # Synthesize options for recommended dependencies
+ dependencies.deps.select(&:recommended?).each do |dep|
+ option "without-#{dep.name}", "Build without #{dep.name} support"
+ end
end
end
end
diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb
index c0ed28d1e..cc73b28b1 100644
--- a/Library/Homebrew/test/test_build_options.rb
+++ b/Library/Homebrew/test/test_build_options.rb
@@ -27,6 +27,13 @@ class BuildOptionsTests < Test::Unit::TestCase
assert !@build.include?("--with-foo")
end
+ def test_with_without
+ assert @build.with?("foo")
+ assert @build.with?("bar")
+ assert @build.with?("baz")
+ assert @build.without?("qux")
+ end
+
def test_used_options
assert @build.used_options.include?("--with-foo")
assert @build.used_options.include?("--with-bar")