Hide the options data structure better
This commit is contained in:
parent
abdff27cd7
commit
f4ae1c9e1b
@ -30,10 +30,6 @@ class BuildOptions
|
||||
@options << Option.new(name, description)
|
||||
end
|
||||
|
||||
def has_option? name
|
||||
any? { |opt| opt.name == name }
|
||||
end
|
||||
|
||||
def empty?
|
||||
@options.empty?
|
||||
end
|
||||
@ -57,9 +53,9 @@ class BuildOptions
|
||||
name = val
|
||||
end
|
||||
|
||||
if has_option? "with-#{name}"
|
||||
if option_defined? "with-#{name}"
|
||||
include? "with-#{name}"
|
||||
elsif has_option? "without-#{name}"
|
||||
elsif option_defined? "without-#{name}"
|
||||
not include? "without-#{name}"
|
||||
else
|
||||
false
|
||||
@ -88,19 +84,19 @@ class BuildOptions
|
||||
|
||||
# True if the user requested a universal build.
|
||||
def universal?
|
||||
universal || include?("universal") && has_option?("universal")
|
||||
universal || include?("universal") && option_defined?("universal")
|
||||
end
|
||||
|
||||
# True if the user requested to enable C++11 mode.
|
||||
def cxx11?
|
||||
include?("c++11") && has_option?("c++11")
|
||||
include?("c++11") && option_defined?("c++11")
|
||||
end
|
||||
|
||||
# Request a 32-bit only build.
|
||||
# This is needed for some use-cases though we prefer to build Universal
|
||||
# when a 32-bit version is needed.
|
||||
def build_32_bit?
|
||||
include?("32-bit") && has_option?("32-bit")
|
||||
include?("32-bit") && option_defined?("32-bit")
|
||||
end
|
||||
|
||||
def used_options
|
||||
@ -110,4 +106,10 @@ class BuildOptions
|
||||
def unused_options
|
||||
Options.new(@options - @args)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def option_defined? name
|
||||
@options.include? name
|
||||
end
|
||||
end
|
||||
|
@ -136,7 +136,7 @@ class FormulaAuditor
|
||||
end
|
||||
|
||||
dep.options.reject do |opt|
|
||||
next true if dep_f.build.has_option?(opt.name)
|
||||
next true if dep_f.option_defined?(opt)
|
||||
dep_f.requirements.detect do |r|
|
||||
if r.recommended?
|
||||
opt.name == "with-#{r.name}"
|
||||
|
@ -106,6 +106,10 @@ class Formula
|
||||
active_spec.patches
|
||||
end
|
||||
|
||||
def option_defined?(name)
|
||||
active_spec.option_defined?(name)
|
||||
end
|
||||
|
||||
# if the dir is there, but it's empty we consider it not installed
|
||||
def installed?
|
||||
(dir = installed_prefix).directory? && dir.children.length > 0
|
||||
|
@ -316,8 +316,9 @@ class FormulaInstaller
|
||||
|
||||
def inherited_options_for(dep)
|
||||
inherited_options = Options.new
|
||||
if (options.include?("universal") || f.build.universal?) && !dep.build? && dep.to_formula.build.has_option?("universal")
|
||||
inherited_options << Option.new("universal")
|
||||
u = Option.new("universal")
|
||||
if (options.include?(u) || f.build.universal?) && !dep.build? && dep.to_formula.option_defined?(u)
|
||||
inherited_options << u
|
||||
end
|
||||
inherited_options
|
||||
end
|
||||
|
@ -71,6 +71,10 @@ class SoftwareSpec
|
||||
end
|
||||
end
|
||||
|
||||
def option_defined?(name)
|
||||
options.include?(name)
|
||||
end
|
||||
|
||||
def option name, description=nil
|
||||
name = 'c++11' if name == :cxx11
|
||||
name = name.to_s if Symbol === name
|
||||
@ -105,9 +109,9 @@ class SoftwareSpec
|
||||
def add_dep_option(dep)
|
||||
name = dep.option_name
|
||||
|
||||
if dep.optional? && !options.include?("with-#{name}")
|
||||
if dep.optional? && !option_defined?("with-#{name}")
|
||||
options << Option.new("with-#{name}", "Build with #{name} support")
|
||||
elsif dep.recommended? && !options.include?("without-#{name}")
|
||||
elsif dep.recommended? && !option_defined?("without-#{name}")
|
||||
options << Option.new("without-#{name}", "Build without #{name} support")
|
||||
end
|
||||
end
|
||||
|
@ -15,11 +15,6 @@ class BuildOptionsTests < Homebrew::TestCase
|
||||
@build.as_flags.sort
|
||||
end
|
||||
|
||||
def test_has_option?
|
||||
assert @build.has_option?("with-foo")
|
||||
assert !@build.has_option?("with-qux")
|
||||
end
|
||||
|
||||
def test_include
|
||||
assert_includes @build, "with-foo"
|
||||
refute_includes @build, "with-qux"
|
||||
|
@ -44,7 +44,7 @@ class SoftwareSpecTests < Homebrew::TestCase
|
||||
|
||||
def test_option
|
||||
@spec.option('foo')
|
||||
assert @spec.build.has_option? 'foo'
|
||||
assert @spec.option_defined?("foo")
|
||||
end
|
||||
|
||||
def test_option_raises_when_begins_with_dashes
|
||||
@ -57,7 +57,7 @@ class SoftwareSpecTests < Homebrew::TestCase
|
||||
|
||||
def test_option_accepts_symbols
|
||||
@spec.option(:foo)
|
||||
assert @spec.build.has_option? 'foo'
|
||||
assert @spec.option_defined?("foo")
|
||||
end
|
||||
|
||||
def test_depends_on
|
||||
@ -68,8 +68,8 @@ class SoftwareSpecTests < Homebrew::TestCase
|
||||
def test_dependency_option_integration
|
||||
@spec.depends_on 'foo' => :optional
|
||||
@spec.depends_on 'bar' => :recommended
|
||||
assert @spec.build.has_option?('with-foo')
|
||||
assert @spec.build.has_option?('without-bar')
|
||||
assert @spec.option_defined?("with-foo")
|
||||
assert @spec.option_defined?("without-bar")
|
||||
end
|
||||
|
||||
def test_explicit_options_override_default_dep_option_description
|
||||
|
Loading…
x
Reference in New Issue
Block a user