diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb index d0b1f04693..440e3ba782 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 1b65efb463..fa4841dd78 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 c0ed28d1e7..cc73b28b19 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")