brew/Library/Homebrew/cxxstdlib.rb

44 lines
1.0 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
require "compilers"
2020-08-14 03:39:31 +02:00
# Combination of C++ standard library and compiler.
class CxxStdlib
2020-10-20 12:03:48 +02:00
extend T::Sig
include CompilerConstants
2020-08-14 03:39:31 +02:00
# Error for when a formula's dependency was built with a different C++ standard library.
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
library (#{stdlib.type_string} from #{stdlib.compiler}). This may cause problems at runtime.
2018-06-06 23:34:19 -04:00
EOS
end
end
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
CxxStdlib.new(type, compiler)
end
attr_reader :type, :compiler
def initialize(type, compiler)
@type = type
@compiler = compiler.to_sym
end
def type_string
type.to_s.gsub(/cxx$/, "c++")
end
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
end