2014-07-02 21:57:52 -05:00
|
|
|
require "compilers"
|
|
|
|
|
2013-07-27 00:11:45 -07:00
|
|
|
class CxxStdlib
|
|
|
|
attr_accessor :type, :compiler
|
|
|
|
|
|
|
|
def initialize(type, compiler)
|
2013-10-06 16:59:39 -07:00
|
|
|
if type && ![:libstdcxx, :libcxx].include?(type)
|
2013-07-27 00:11:45 -07:00
|
|
|
raise ArgumentError, "Invalid C++ stdlib type: #{type}"
|
|
|
|
end
|
|
|
|
|
2013-10-06 16:59:39 -07:00
|
|
|
@type = type.to_sym if type
|
2013-07-27 00:11:45 -07:00
|
|
|
@compiler = compiler.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
def apple_compiler?
|
2014-07-02 21:57:52 -05:00
|
|
|
not compiler.to_s =~ CompilerConstants::GNU_GCC_REGEXP
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def compatible_with?(other)
|
2013-10-06 16:59:39 -07:00
|
|
|
# If either package doesn't use C++, all is well
|
|
|
|
return true if type.nil? || other.type.nil?
|
|
|
|
|
2013-07-27 00:11:45 -07:00
|
|
|
# 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?
|
2014-07-02 21:57:52 -05:00
|
|
|
if compiler.to_s =~ CompilerConstants::GNU_GCC_REGEXP
|
|
|
|
return false unless other.compiler.to_s =~ CompilerConstants::GNU_GCC_REGEXP
|
2013-07-27 00:11:45 -07:00
|
|
|
return false unless compiler.to_s[4..6] == other.compiler.to_s[4..6]
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_dependencies(formula, deps)
|
2014-04-21 18:50:22 +01:00
|
|
|
unless formula.class.cxxstdlib.include? :skip
|
2013-10-28 02:16:42 -07:00
|
|
|
deps.each do |dep|
|
|
|
|
# Software is unlikely to link against anything from its
|
|
|
|
# buildtime deps, so it doesn't matter at all if they link
|
|
|
|
# against different C++ stdlibs
|
2014-07-01 21:57:30 -05:00
|
|
|
next if dep.build?
|
2013-10-28 02:16:42 -07:00
|
|
|
|
|
|
|
dep_stdlib = Tab.for_formula(dep.to_formula).cxxstdlib
|
|
|
|
if !compatible_with? dep_stdlib
|
|
|
|
raise IncompatibleCxxStdlibs.new(formula, dep, dep_stdlib, self)
|
|
|
|
end
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def type_string
|
|
|
|
type.to_s.gsub(/cxx$/, 'c++')
|
|
|
|
end
|
|
|
|
end
|