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