Make options available on the spec objects

This commit is contained in:
Jack Nagel 2014-07-31 19:37:39 -05:00
parent fad2e26395
commit abdff27cd7
4 changed files with 25 additions and 24 deletions

View File

@ -8,11 +8,10 @@ class BuildOptions
attr_accessor :args
attr_accessor :universal
attr_reader :options
protected :options
def initialize args
def initialize(args, options)
@args = Options.coerce(args)
@options = Options.new
@options = options
end
def initialize_copy(other)
@ -31,15 +30,6 @@ class BuildOptions
@options << Option.new(name, description)
end
def add_dep_option(dep)
name = dep.option_name
if dep.optional? && !has_option?("with-#{name}")
add("with-#{name}", "Build with #{name} support")
elsif dep.recommended? && !has_option?("without-#{name}")
add("without-#{name}", "Build without #{name} support")
end
end
def has_option? name
any? { |opt| opt.name == name }
end

View File

@ -2,6 +2,7 @@ require 'forwardable'
require 'resource'
require 'checksum'
require 'version'
require 'options'
require 'build_options'
require 'dependency_collector'
require 'bottles'
@ -11,7 +12,7 @@ class SoftwareSpec
extend Forwardable
attr_reader :name, :owner
attr_reader :build, :resources, :patches
attr_reader :build, :resources, :patches, :options
attr_reader :dependency_collector
attr_reader :bottle_specification
@ -23,10 +24,11 @@ class SoftwareSpec
def initialize
@resource = Resource.new
@resources = {}
@build = BuildOptions.new(ARGV.options_only)
@dependency_collector = DependencyCollector.new
@bottle_specification = BottleSpecification.new
@patches = []
@options = Options.new
@build = BuildOptions.new(ARGV.options_only, options)
end
def owner= owner
@ -79,7 +81,7 @@ class SoftwareSpec
def depends_on spec
dep = dependency_collector.add(spec)
build.add_dep_option(dep) if dep
add_dep_option(dep) if dep
end
def deps
@ -99,6 +101,16 @@ class SoftwareSpec
list.each { |p| p.owner = self }
patches.concat(list)
end
def add_dep_option(dep)
name = dep.option_name
if dep.optional? && !options.include?("with-#{name}")
options << Option.new("with-#{name}", "Build with #{name} support")
elsif dep.recommended? && !options.include?("without-#{name}")
options << Option.new("without-#{name}", "Build without #{name} support")
end
end
end
class HeadSoftwareSpec < SoftwareSpec

View File

@ -4,11 +4,10 @@ require 'build_options'
class BuildOptionsTests < Homebrew::TestCase
def setup
args = %w{--with-foo --with-bar --without-qux}
@build = BuildOptions.new(args)
@build.add("with-foo")
@build.add("with-bar")
@build.add("without-baz")
@build.add("without-qux")
opts = Options.new
opts << Option.new("with-foo") << Option.new("with-bar")
opts << Option.new("without-baz") << Option.new("without-qux")
@build = BuildOptions.new(args, opts)
end
def test_as_flags
@ -44,13 +43,13 @@ class BuildOptionsTests < Homebrew::TestCase
end
def test_copies_do_not_share_underlying_options
orig = BuildOptions.new []
orig = BuildOptions.new [], Options.new
copy = orig.dup
refute_same orig.args, copy.args
refute_same orig.options, copy.options
end
def test_copies_do_not_share_underlying_args
orig = BuildOptions.new []
orig = BuildOptions.new [], Options.new
copy = orig.dup
refute_same orig.args, copy.args
end

View File

@ -75,7 +75,7 @@ class SoftwareSpecTests < Homebrew::TestCase
def test_explicit_options_override_default_dep_option_description
@spec.option('with-foo', 'blah')
@spec.depends_on('foo' => :optional)
assert_equal 'blah', @spec.build.first.description
assert_equal "blah", @spec.options.first.description
end
def test_patch