diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/build_options.rb | 14 | ||||
| -rw-r--r-- | Library/Homebrew/software_spec.rb | 18 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_build_options.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_software_spec.rb | 2 |
4 files changed, 25 insertions, 24 deletions
diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb index 85c53c354..b46fb7c4f 100644 --- a/Library/Homebrew/build_options.rb +++ b/Library/Homebrew/build_options.rb @@ -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 diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 97a97969c..fcede796c 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -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 diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb index 95388a0ea..b73108bff 100644 --- a/Library/Homebrew/test/test_build_options.rb +++ b/Library/Homebrew/test/test_build_options.rb @@ -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 diff --git a/Library/Homebrew/test/test_software_spec.rb b/Library/Homebrew/test/test_software_spec.rb index 313a502e0..02f586569 100644 --- a/Library/Homebrew/test/test_software_spec.rb +++ b/Library/Homebrew/test/test_software_spec.rb @@ -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 |
