Class: CxxStdlib

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/cxxstdlib.rb

Direct Known Subclasses

AppleStdlib, GnuStdlib

Defined Under Namespace

Classes: AppleStdlib, CompatibilityError, GnuStdlib

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, compiler) ⇒ CxxStdlib

Returns a new instance of CxxStdlib



38
39
40
41
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 38

def initialize(type, compiler)
  @type = type
  @compiler = compiler.to_sym
end

Instance Attribute Details

#compilerObject (readonly)

Returns the value of attribute compiler



36
37
38
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 36

def compiler
  @compiler
end

#typeObject (readonly)

Returns the value of attribute type



36
37
38
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 36

def type
  @type
end

Class Method Details

.check_compatibility(formula, deps, keg, compiler) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 24

def self.check_compatibility(formula, deps, keg, compiler)
  return if formula.skip_cxxstdlib_check?

  stdlib = create(keg.detect_cxx_stdlibs.first, compiler)

  begin
    stdlib.check_dependencies(formula, deps)
  rescue CompatibilityError => e
    opoo e.message
  end
end

.create(type, compiler) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 17

def self.create(type, compiler)
  raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type)

  klass = (compiler.to_s =~ GNU_GCC_REGEXP) ? GnuStdlib : AppleStdlib
  klass.new(type, compiler)
end

Instance Method Details

#check_dependencies(formula, deps) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 56

def check_dependencies(formula, deps)
  deps.each do |dep|
    # Software is unlikely to link against libraries from build-time deps, so
    # it doesn't matter if they link against different C++ stdlibs.
    next if dep.build?

    dep_stdlib = Tab.for_formula(dep.to_formula).cxxstdlib
    raise CompatibilityError.new(formula, dep, dep_stdlib) unless compatible_with? dep_stdlib
  end
end

#compatible_with?(other) ⇒ Boolean

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.

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 47

def compatible_with?(other)
  return true if type.nil? || other.type.nil?

  return false unless type == other.type

  apple_compiler? && other.apple_compiler? ||
    !other.apple_compiler? && compiler.to_s[4..6] == other.compiler.to_s[4..6]
end

#inspectObject



71
72
73
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 71

def inspect
  "#<#{self.class.name}: #{compiler} #{type}>"
end

#type_stringObject



67
68
69
# File 'brew/Library/Homebrew/cxxstdlib.rb', line 67

def type_string
  type.to_s.gsub(/cxx$/, "c++")
end