2014-07-02 21:57:52 -05:00
|
|
|
require "compilers"
|
|
|
|
|
2013-07-27 00:11:45 -07:00
|
|
|
class CxxStdlib
|
2014-08-02 19:29:59 -05:00
|
|
|
include CompilerConstants
|
2013-07-27 00:11:45 -07:00
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
def self.create(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
|
2014-08-02 19:29:59 -05:00
|
|
|
klass = GNU_GCC_REGEXP === compiler.to_s ? GnuStdlib : AppleStdlib
|
|
|
|
klass.new(type, compiler)
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :type, :compiler
|
2013-07-27 00:11:45 -07:00
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
def initialize(type, compiler)
|
2014-08-02 19:29:58 -05:00
|
|
|
@type = type
|
2013-07-27 00:11:45 -07:00
|
|
|
@compiler = compiler.to_sym
|
|
|
|
end
|
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
# 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
|
2013-07-27 00:11:45 -07:00
|
|
|
def compatible_with?(other)
|
2014-08-02 20:03:42 -05:00
|
|
|
return true if type.nil? || other.type.nil?
|
|
|
|
|
|
|
|
return false unless type == other.type
|
|
|
|
|
2014-08-02 20:09:42 -05:00
|
|
|
apple_compiler? && other.apple_compiler? ||
|
|
|
|
!other.apple_compiler? && compiler.to_s[4..6] == other.compiler.to_s[4..6]
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_dependencies(formula, deps)
|
2014-07-06 15:51:43 -05:00
|
|
|
unless formula.skip_cxxstdlib_check?
|
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
|
2014-08-02 19:29:59 -05:00
|
|
|
|
2014-08-03 15:28:26 -05:00
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{compiler} #{type}>"
|
|
|
|
end
|
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
class AppleStdlib < CxxStdlib
|
|
|
|
def apple_compiler?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class GnuStdlib < CxxStdlib
|
|
|
|
def apple_compiler?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|