Merge pull request #8349 from reitermarkus/doc-cxxstdlib
Refactor and document `CxxStdlib`.
This commit is contained in:
commit
958c5c7f9e
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
require "compilers"
|
require "compilers"
|
||||||
|
|
||||||
|
# Combination of C++ standard library and compiler.
|
||||||
class CxxStdlib
|
class CxxStdlib
|
||||||
include CompilerConstants
|
include CompilerConstants
|
||||||
|
|
||||||
|
# Error for when a formula's dependency was built with a different C++ standard library.
|
||||||
class CompatibilityError < StandardError
|
class CompatibilityError < StandardError
|
||||||
def initialize(formula, dep, stdlib)
|
def initialize(formula, dep, stdlib)
|
||||||
super <<~EOS
|
super <<~EOS
|
||||||
@ -17,8 +19,8 @@ class CxxStdlib
|
|||||||
def self.create(type, compiler)
|
def self.create(type, compiler)
|
||||||
raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type)
|
raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type)
|
||||||
|
|
||||||
klass = (compiler.to_s =~ GNU_GCC_REGEXP) ? GnuStdlib : AppleStdlib
|
apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true
|
||||||
klass.new(type, compiler)
|
CxxStdlib.new(type, compiler, apple_compiler)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_compatibility(formula, deps, keg, compiler)
|
def self.check_compatibility(formula, deps, keg, compiler)
|
||||||
@ -35,9 +37,10 @@ class CxxStdlib
|
|||||||
|
|
||||||
attr_reader :type, :compiler
|
attr_reader :type, :compiler
|
||||||
|
|
||||||
def initialize(type, compiler)
|
def initialize(type, compiler, apple_compiler)
|
||||||
@type = type
|
@type = type
|
||||||
@compiler = compiler.to_sym
|
@compiler = compiler.to_sym
|
||||||
|
@apple_compiler = apple_compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
# If either package doesn't use C++, all is well.
|
# If either package doesn't use C++, all is well.
|
||||||
@ -72,15 +75,7 @@ class CxxStdlib
|
|||||||
"#<#{self.class.name}: #{compiler} #{type}>"
|
"#<#{self.class.name}: #{compiler} #{type}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
class AppleStdlib < CxxStdlib
|
def apple_compiler?
|
||||||
def apple_compiler?
|
@apple_compiler
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class GnuStdlib < CxxStdlib
|
|
||||||
def apple_compiler?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user