Class: CompilerSelector Private

Inherits:
Object show all
Includes:
CompilerConstants
Defined in:
compilers.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Class for selecting a compiler for a formula.

Defined Under Namespace

Classes: Compiler

Constant Summary collapse

COMPILER_PRIORITY =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let({
  clang: [:clang, :llvm_clang, :gnu],
  gcc:   [:gnu, :gcc, :llvm_clang, :clang],
}.freeze, T::Hash[Symbol, T::Array[Symbol]])

Constants included from CompilerConstants

CompilerConstants::COMPILERS, CompilerConstants::COMPILER_SYMBOL_MAP, CompilerConstants::GNU_GCC_REGEXP, CompilerConstants::GNU_GCC_VERSIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula, versions, compilers) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



152
153
154
155
156
157
# File 'compilers.rb', line 152

def initialize(formula, versions, compilers)
  @formula = formula
  @failures = T.let(formula.compiler_failures, T::Array[CompilerFailure])
  @versions = versions
  @compilers = compilers
end

Instance Attribute Details

#compilersArray<Symbol> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



143
144
145
# File 'compilers.rb', line 143

def compilers
  @compilers
end

#failuresArray<CompilerFailure> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



137
138
139
# File 'compilers.rb', line 137

def failures
  @failures
end

#formulaFormula, SoftwareSpec (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



134
135
136
# File 'compilers.rb', line 134

def formula
  @formula
end

#versionsT.class_of(DevelopmentTools) (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



140
141
142
# File 'compilers.rb', line 140

def versions
  @versions
end

Class Method Details

.compilersArray<Symbol>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



129
130
131
# File 'compilers.rb', line 129

def self.compilers
  COMPILER_PRIORITY.fetch(DevelopmentTools.default_compiler)
end

.preferred_gccString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



166
167
168
# File 'compilers.rb', line 166

def self.preferred_gcc
  "gcc"
end

.select_for(formula, compilers = nil, testing_formula: false) ⇒ String, Symbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



118
119
120
121
122
123
124
125
126
# File 'compilers.rb', line 118

def self.select_for(formula, compilers = nil, testing_formula: false)
  if compilers.nil? && DevelopmentTools.default_compiler == :clang
    deps = formula.deps.filter_map do |dep|
      dep.name if dep.required? || (testing_formula && dep.test?) || (!testing_formula && dep.build?)
    end
    compilers = [:clang, :gnu, :llvm_clang] if deps.none?("llvm") && deps.any?(/^gcc(@\d+)?$/)
  end
  new(formula, DevelopmentTools, compilers || self.compilers).compiler
end

Instance Method Details

#compilerString, Symbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

Raises:



160
161
162
163
# File 'compilers.rb', line 160

def compiler
  find_compiler { |c| return c.name unless fails_with?(c) }
  raise CompilerSelectionError, formula
end