Make options available on the spec objects
This commit is contained in:
parent
fad2e26395
commit
abdff27cd7
@ -8,11 +8,10 @@ class BuildOptions
|
|||||||
attr_accessor :args
|
attr_accessor :args
|
||||||
attr_accessor :universal
|
attr_accessor :universal
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
protected :options
|
|
||||||
|
|
||||||
def initialize args
|
def initialize(args, options)
|
||||||
@args = Options.coerce(args)
|
@args = Options.coerce(args)
|
||||||
@options = Options.new
|
@options = options
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_copy(other)
|
def initialize_copy(other)
|
||||||
@ -31,15 +30,6 @@ class BuildOptions
|
|||||||
@options << Option.new(name, description)
|
@options << Option.new(name, description)
|
||||||
end
|
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
|
def has_option? name
|
||||||
any? { |opt| opt.name == name }
|
any? { |opt| opt.name == name }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,6 +2,7 @@ require 'forwardable'
|
|||||||
require 'resource'
|
require 'resource'
|
||||||
require 'checksum'
|
require 'checksum'
|
||||||
require 'version'
|
require 'version'
|
||||||
|
require 'options'
|
||||||
require 'build_options'
|
require 'build_options'
|
||||||
require 'dependency_collector'
|
require 'dependency_collector'
|
||||||
require 'bottles'
|
require 'bottles'
|
||||||
@ -11,7 +12,7 @@ class SoftwareSpec
|
|||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
attr_reader :name, :owner
|
attr_reader :name, :owner
|
||||||
attr_reader :build, :resources, :patches
|
attr_reader :build, :resources, :patches, :options
|
||||||
attr_reader :dependency_collector
|
attr_reader :dependency_collector
|
||||||
attr_reader :bottle_specification
|
attr_reader :bottle_specification
|
||||||
|
|
||||||
@ -23,10 +24,11 @@ class SoftwareSpec
|
|||||||
def initialize
|
def initialize
|
||||||
@resource = Resource.new
|
@resource = Resource.new
|
||||||
@resources = {}
|
@resources = {}
|
||||||
@build = BuildOptions.new(ARGV.options_only)
|
|
||||||
@dependency_collector = DependencyCollector.new
|
@dependency_collector = DependencyCollector.new
|
||||||
@bottle_specification = BottleSpecification.new
|
@bottle_specification = BottleSpecification.new
|
||||||
@patches = []
|
@patches = []
|
||||||
|
@options = Options.new
|
||||||
|
@build = BuildOptions.new(ARGV.options_only, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def owner= owner
|
def owner= owner
|
||||||
@ -79,7 +81,7 @@ class SoftwareSpec
|
|||||||
|
|
||||||
def depends_on spec
|
def depends_on spec
|
||||||
dep = dependency_collector.add(spec)
|
dep = dependency_collector.add(spec)
|
||||||
build.add_dep_option(dep) if dep
|
add_dep_option(dep) if dep
|
||||||
end
|
end
|
||||||
|
|
||||||
def deps
|
def deps
|
||||||
@ -99,6 +101,16 @@ class SoftwareSpec
|
|||||||
list.each { |p| p.owner = self }
|
list.each { |p| p.owner = self }
|
||||||
patches.concat(list)
|
patches.concat(list)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class HeadSoftwareSpec < SoftwareSpec
|
class HeadSoftwareSpec < SoftwareSpec
|
||||||
|
|||||||
@ -4,11 +4,10 @@ require 'build_options'
|
|||||||
class BuildOptionsTests < Homebrew::TestCase
|
class BuildOptionsTests < Homebrew::TestCase
|
||||||
def setup
|
def setup
|
||||||
args = %w{--with-foo --with-bar --without-qux}
|
args = %w{--with-foo --with-bar --without-qux}
|
||||||
@build = BuildOptions.new(args)
|
opts = Options.new
|
||||||
@build.add("with-foo")
|
opts << Option.new("with-foo") << Option.new("with-bar")
|
||||||
@build.add("with-bar")
|
opts << Option.new("without-baz") << Option.new("without-qux")
|
||||||
@build.add("without-baz")
|
@build = BuildOptions.new(args, opts)
|
||||||
@build.add("without-qux")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_as_flags
|
def test_as_flags
|
||||||
@ -44,13 +43,13 @@ class BuildOptionsTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_copies_do_not_share_underlying_options
|
def test_copies_do_not_share_underlying_options
|
||||||
orig = BuildOptions.new []
|
orig = BuildOptions.new [], Options.new
|
||||||
copy = orig.dup
|
copy = orig.dup
|
||||||
refute_same orig.args, copy.args
|
refute_same orig.options, copy.options
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_copies_do_not_share_underlying_args
|
def test_copies_do_not_share_underlying_args
|
||||||
orig = BuildOptions.new []
|
orig = BuildOptions.new [], Options.new
|
||||||
copy = orig.dup
|
copy = orig.dup
|
||||||
refute_same orig.args, copy.args
|
refute_same orig.args, copy.args
|
||||||
end
|
end
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class SoftwareSpecTests < Homebrew::TestCase
|
|||||||
def test_explicit_options_override_default_dep_option_description
|
def test_explicit_options_override_default_dep_option_description
|
||||||
@spec.option('with-foo', 'blah')
|
@spec.option('with-foo', 'blah')
|
||||||
@spec.depends_on('foo' => :optional)
|
@spec.depends_on('foo' => :optional)
|
||||||
assert_equal 'blah', @spec.build.first.description
|
assert_equal "blah", @spec.options.first.description
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_patch
|
def test_patch
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user