diff options
| author | Jack Nagel | 2014-08-02 19:29:59 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2014-08-02 19:29:59 -0500 | 
| commit | 142beddd7a7c374b59e678a7df71e25df13df3e4 (patch) | |
| tree | 70a8208f5d1ec01665b53d445427630d9ee8a26d /Library/Homebrew/cxxstdlib.rb | |
| parent | 90e370d2eff4a2aaf00a4d2659192015fb7d91a4 (diff) | |
| download | brew-142beddd7a7c374b59e678a7df71e25df13df3e4.tar.bz2 | |
Use polymorphism to simplify stdlib compatibility check
Diffstat (limited to 'Library/Homebrew/cxxstdlib.rb')
| -rw-r--r-- | Library/Homebrew/cxxstdlib.rb | 56 | 
1 files changed, 35 insertions, 21 deletions
| diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index 27c03b625..4fcb4bf75 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -1,37 +1,29 @@  require "compilers"  class CxxStdlib -  attr_reader :type, :compiler +  include CompilerConstants -  def initialize(type, compiler) +  def self.create(type, compiler)      if type && ![:libstdcxx, :libcxx].include?(type)        raise ArgumentError, "Invalid C++ stdlib type: #{type}"      end +    klass = GNU_GCC_REGEXP === compiler.to_s ? GnuStdlib : AppleStdlib +    klass.new(type, compiler) +  end + +  attr_reader :type, :compiler +  def initialize(type, compiler)      @type = type      @compiler = compiler.to_sym    end -  def apple_compiler? -    not compiler.to_s =~ CompilerConstants::GNU_GCC_REGEXP -  end - +  # If either package doesn't use C++, all is well +  # libstdc++ and libc++ aren't ever intercompatible +  # libstdc++ is compatible across Apple compilers, but +  # not between Apple and GNU compilers, or between GNU compiler versions    def compatible_with?(other) -    # If either package doesn't use C++, all is well -    return true if type.nil? || other.type.nil? - -    # libstdc++ and libc++ aren't ever intercompatible -    return false unless type == other.type - -    # libstdc++ is compatible across Apple compilers, but -    # not between Apple and GNU compilers, or between GNU compiler versions -    return false if apple_compiler? && !other.apple_compiler? -    if compiler.to_s =~ CompilerConstants::GNU_GCC_REGEXP -      return false unless other.compiler.to_s =~ CompilerConstants::GNU_GCC_REGEXP -      return false unless compiler.to_s[4..6] == other.compiler.to_s[4..6] -    end - -    true +    (type.nil? || other.type.nil?) || type == other.type    end    def check_dependencies(formula, deps) @@ -53,4 +45,26 @@ class CxxStdlib    def type_string      type.to_s.gsub(/cxx$/, 'c++')    end + +  class AppleStdlib < CxxStdlib +    def apple_compiler? +      true +    end + +    def compatible_with?(other) +      super && other.apple_compiler? +    end +  end + +  class GnuStdlib < CxxStdlib +    def apple_compiler? +      false +    end + +    def compatible_with?(other) +      super && +        !other.apple_compiler? && +        compiler.to_s[4..6] == other.compiler.to_s[4..6] +    end +  end  end | 
