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:
parent
99850fcbda
commit
6193167f58
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user