2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-07-02 21:57:52 -05:00
|
|
|
require "compilers"
|
|
|
|
|
2020-08-14 03:39:31 +02:00
|
|
|
# Combination of C++ standard library and compiler.
|
2013-07-27 00:11:45 -07:00
|
|
|
class CxxStdlib
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
include CompilerConstants
|
2013-07-27 00:11:45 -07:00
|
|
|
|
2020-08-14 03:39:31 +02:00
|
|
|
# Error for when a formula's dependency was built with a different C++ standard library.
|
2014-08-22 22:36:58 -05:00
|
|
|
class CompatibilityError < StandardError
|
|
|
|
def initialize(formula, dep, stdlib)
|
2017-10-15 02:28:32 +02:00
|
|
|
super <<~EOS
|
2015-05-27 21:33:11 +08:00
|
|
|
#{formula.full_name} dependency #{dep.name} was built with a different C++ standard
|
2014-08-22 22:36:58 -05:00
|
|
|
library (#{stdlib.type_string} from #{stdlib.compiler}). This may cause problems at runtime.
|
2018-06-06 23:34:19 -04:00
|
|
|
EOS
|
2014-08-22 22:36:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
def self.create(type, compiler)
|
2020-12-01 17:04:59 +00:00
|
|
|
raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type)
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2021-04-02 12:38:39 +01:00
|
|
|
CxxStdlib.new(type, compiler)
|
2014-08-22 22:18:03 -05:00
|
|
|
end
|
|
|
|
|
2014-08-02 19:29:59 -05:00
|
|
|
attr_reader :type, :compiler
|
2013-07-27 00:11:45 -07:00
|
|
|
|
2021-04-02 12:38:39 +01: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
|
|
|
|
|
|
|
|
def type_string
|
2015-08-03 13:09:07 +01:00
|
|
|
type.to_s.gsub(/cxx$/, "c++")
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|
2014-08-02 19:29:59 -05:00
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(String) }
|
2014-08-03 15:28:26 -05:00
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{compiler} #{type}>"
|
|
|
|
end
|
2013-07-27 00:11:45 -07:00
|
|
|
end
|