Class: CxxStdlib

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

Overview

Combination of C++ standard library and compiler.

Defined Under Namespace

Classes: CompatibilityError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, compiler, apple_compiler) ⇒ CxxStdlib

Returns a new instance of CxxStdlib.


40
41
42
43
44
# File 'Library/Homebrew/cxxstdlib.rb', line 40

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

Instance Attribute Details

#compilerObject (readonly)

Returns the value of attribute compiler


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

def compiler
  @compiler
end

#typeObject (readonly)

Returns the value of attribute type


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

def type
  @type
end

Class Method Details

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


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

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)

19
20
21
22
23
24
# File 'Library/Homebrew/cxxstdlib.rb', line 19

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

  apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true
  CxxStdlib.new(type, compiler, apple_compiler)
end

Instance Method Details

#apple_compiler?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'Library/Homebrew/cxxstdlib.rb', line 78

def apple_compiler?
  @apple_compiler
end

#check_dependencies(formula, deps) ⇒ Object


59
60
61
62
63
64
65
66
67
68
# File 'Library/Homebrew/cxxstdlib.rb', line 59

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)

50
51
52
53
54
55
56
57
# File 'Library/Homebrew/cxxstdlib.rb', line 50

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


74
75
76
# File 'Library/Homebrew/cxxstdlib.rb', line 74

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

#type_stringObject


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

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