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.
This commit is contained in:
Adam Vandenberg 2013-01-23 00:26:26 -06:00 committed by Jack Nagel
parent 99850fcbda
commit 6193167f58
3 changed files with 30 additions and 0 deletions

View File

@ -40,6 +40,20 @@ class BuildOptions
@args.include? '--' + name @args.include? '--' + name
end 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? def head?
@args.flag? '--HEAD' @args.flag? '--HEAD'
end end

View File

@ -829,6 +829,15 @@ private
# This method is called once by `factory` before creating any instances. # This method is called once by `factory` before creating any instances.
# It allows the DSL to finalize itself, reducing complexity in the constructor. # It allows the DSL to finalize itself, reducing complexity in the constructor.
def finalize_dsl 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 end
end end

View File

@ -27,6 +27,13 @@ class BuildOptionsTests < Test::Unit::TestCase
assert !@build.include?("--with-foo") assert !@build.include?("--with-foo")
end 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 def test_used_options
assert @build.used_options.include?("--with-foo") assert @build.used_options.include?("--with-foo")
assert @build.used_options.include?("--with-bar") assert @build.used_options.include?("--with-bar")