diff options
| author | Jack Nagel | 2014-07-31 19:37:39 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2014-07-31 19:59:09 -0500 | 
| commit | 4226386ef99e71c149b0bb45cba4dca5c52e6054 (patch) | |
| tree | 056a0f0c368624863600201081c7cd63e3d10c4d | |
| parent | 1b182b422bedeb0cd12f6634a692399242e140fd (diff) | |
| download | homebrew-4226386ef99e71c149b0bb45cba4dca5c52e6054.tar.bz2 | |
Hide the options data structure better
| -rw-r--r-- | Library/Homebrew/build_options.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/audit.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/software_spec.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_build_options.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_software_spec.rb | 8 | 
7 files changed, 29 insertions, 23 deletions
| diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb index b46fb7c4f..07f12ab11 100644 --- a/Library/Homebrew/build_options.rb +++ b/Library/Homebrew/build_options.rb @@ -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 diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index 31e0b0da8..3660ad259 100644 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -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}" diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 8d5fb3146..6907406b5 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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 diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 21fa8148e..b10846a0c 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -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 diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index fcede796c..88370e0fa 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -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 diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb index b73108bff..11b3145ba 100644 --- a/Library/Homebrew/test/test_build_options.rb +++ b/Library/Homebrew/test/test_build_options.rb @@ -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" diff --git a/Library/Homebrew/test/test_software_spec.rb b/Library/Homebrew/test/test_software_spec.rb index 02f586569..26bfd4aff 100644 --- a/Library/Homebrew/test/test_software_spec.rb +++ b/Library/Homebrew/test/test_software_spec.rb @@ -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 | 
