Module: SharedEnvExtension Private

Extended by:
T::Helpers
Includes:
CompilerConstants, OS::Linux::SharedEnvExtension, OS::Mac::SharedEnvExtension, Utils::Output::Mixin
Included in:
EnvActivation, Stdenv, Superenv
Defined in:
extend/ENV/shared.rb,
extend/ENV/state.rb

Overview

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

Homebrew extends Ruby's ENV to make our code more readable. Implemented in SharedEnvExtension and either Superenv or Stdenv (depending on the build mode).

Constant Summary

Constants included from CompilerConstants

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

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Instance Method Details

#append(keys, value, separator = " ") ⇒ 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.

This method returns an undefined value.

Parameters:



103
104
105
106
107
108
109
110
111
112
113
# File 'extend/ENV/shared.rb', line 103

def append(keys, value, separator = " ")
  value = value.to_s
  Array(keys).each do |key|
    old_value = self[key]
    self[key] = if old_value.blank?
      value
    else
      old_value + separator + value
    end
  end
end

#append_path(key, path) ⇒ 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.

This method returns an undefined value.

Parameters:



129
130
131
# File 'extend/ENV/shared.rb', line 129

def append_path(key, path)
  self[key] = PATH.new(self[key]).append(path).to_s
end

#append_to_cccfg(value) ⇒ 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.

This method returns an undefined value.

Parameters:



98
99
100
# File 'extend/ENV/shared.rb', line 98

def append_to_cccfg(value)
  append("HOMEBREW_CCCFG", value, "")
end

#append_to_cflags(newflags) ⇒ 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.

This method returns an undefined value.

Parameters:



88
89
90
# File 'extend/ENV/shared.rb', line 88

def append_to_cflags(newflags)
  append(CC_FLAG_VARS, newflags)
end

#append_to_rustflags(rustflags) ⇒ 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.

This method returns an undefined value.

Parameters:



134
135
136
# File 'extend/ENV/shared.rb', line 134

def append_to_rustflags(rustflags)
  append("HOMEBREW_RUSTFLAGS", rustflags)
end

#bottle_arch ⇒ String?

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:



45
# File 'extend/ENV/shared.rb', line 45

def bottle_arch = build_environment_state.bottle_arch

#build_bottle? ⇒ Boolean

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:

  • (Boolean)


70
# File 'extend/ENV/shared.rb', line 70

def build_bottle? = build_environment_state.build_bottle == true

#cc ⇒ String?

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:



177
178
179
# File 'extend/ENV/shared.rb', line 177

def cc
  self["CC"]
end

#cflags ⇒ String?

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:



187
188
189
# File 'extend/ENV/shared.rb', line 187

def cflags
  self["CFLAGS"]
end

#compiler ⇒ Symbol, String

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.

Outputs the current compiler.

# Do something only for the system clang
if ENV.compiler == :clang
  # modify CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS in one go:
  ENV.append_to_cflags "-I ./missing/includes"
end

Returns:



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'extend/ENV/shared.rb', line 228

def compiler
  compiler = build_environment_state.compiler
  return compiler if compiler

  state = build_environment_state(writable: true)
  state.compiler = if (cc = state.cc)
    warn_about_non_apple_gcc(cc) if cc.match?(GNU_GCC_REGEXP)

    fetch_compiler(cc, "--cc")
  elsif (cc = homebrew_cc)
    warn_about_non_apple_gcc(cc) if cc.match?(GNU_GCC_REGEXP)

    compiler = fetch_compiler(cc, "HOMEBREW_CC")

    if (formula = state.formula)
      compilers = [compiler] + CompilerSelector.compilers
      compiler = CompilerSelector.select_for(formula, compilers, testing_formula: state.testing_formula)
    end

    compiler
  elsif (formula = state.formula)
    CompilerSelector.select_for(formula, testing_formula: state.testing_formula)
  else
    DevelopmentTools.default_compiler
  end
end

#cppflags ⇒ String?

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:



197
198
199
# File 'extend/ENV/shared.rb', line 197

def cppflags
  self["CPPFLAGS"]
end

#cxx ⇒ String?

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:



182
183
184
# File 'extend/ENV/shared.rb', line 182

def cxx
  self["CXX"]
end

#cxxflags ⇒ String?

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:



192
193
194
# File 'extend/ENV/shared.rb', line 192

def cxxflags
  self["CXXFLAGS"]
end

#debug_symbols? ⇒ Boolean

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:

  • (Boolean)


73
# File 'extend/ENV/shared.rb', line 73

def debug_symbols? = build_environment_state.debug_symbols == true

#effective_arch ⇒ 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:



308
309
310
311
312
313
314
# File 'extend/ENV/shared.rb', line 308

def effective_arch
  if build_bottle? && (arch = bottle_arch)
    arch.to_sym
  else
    Hardware.oldest_cpu
  end
end

#fc ⇒ String?

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:



207
208
209
# File 'extend/ENV/shared.rb', line 207

def fc
  self["FC"]
end

#fcflags ⇒ String?

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:



217
218
219
# File 'extend/ENV/shared.rb', line 217

def fcflags
  self["FCFLAGS"]
end

#fflags ⇒ String?

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:



212
213
214
# File 'extend/ENV/shared.rb', line 212

def fflags
  self["FFLAGS"]
end

#fortran ⇒ 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.

This method returns an undefined value.



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'extend/ENV/shared.rb', line 277

def fortran
  # Ignore repeated calls to this function as it will misleadingly warn about
  # building with an alternative Fortran compiler without optimization flags,
  # despite it often being the Homebrew-provided one set up in the first call.
  return if build_environment_state.fortran_setup_done

  build_environment_state(writable: true).fortran_setup_done = true

  flags = []

  if fc
    opoo "Building with an unsupported Fortran compiler"
    self["F77"] ||= fc
  else
    if (gfortran = which("gfortran", (HOMEBREW_PREFIX/"bin").to_s))
      ohai "Using Homebrew-provided Fortran compiler"
    elsif (gfortran = which("gfortran", PATH.new(ORIGINAL_PATHS)))
      ohai "Using a Fortran compiler found at #{gfortran}"
    end
    if gfortran
      puts "This may be changed by setting the `$FC` environment variable."
      self["FC"] = self["F77"] = gfortran.to_s
      flags = FC_FLAG_VARS
    end
  end

  flags.each { |key| self[key] = cflags }
  set_cpu_flags(flags)
end

#ldflags ⇒ String?

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:



202
203
204
# File 'extend/ENV/shared.rb', line 202

def ldflags
  self["LDFLAGS"]
end

#make_jobs ⇒ Integer

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:



354
355
356
# File 'extend/ENV/shared.rb', line 354

def make_jobs
  Homebrew::EnvConfig.make_jobs.to_i
end

#permit_arch_flags ⇒ 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.

This method returns an undefined value.



351
# File 'extend/ENV/shared.rb', line 351

def permit_arch_flags; end

#prepend(keys, value, separator = " ") ⇒ 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.

This method returns an undefined value.

Parameters:



116
117
118
119
120
121
122
123
124
125
126
# File 'extend/ENV/shared.rb', line 116

def prepend(keys, value, separator = " ")
  value = value.to_s
  Array(keys).each do |key|
    old_value = self[key]
    self[key] = if old_value.blank?
      value
    else
      value + separator + old_value
    end
  end
end

#prepend_create_path(key, path) ⇒ 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.

This method returns an undefined value.

Parameters:



153
154
155
156
157
# File 'extend/ENV/shared.rb', line 153

def prepend_create_path(key, path)
  path = Pathname(path)
  path.mkpath
  prepend_path key, path
end

#prepend_path(key, path) ⇒ 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.

This method returns an undefined value.

Prepends a directory to PATH. Is the formula struggling to find the pkgconfig file? Point it to it. This is done automatically for keg-only formulae.

ENV.prepend_path "PKG_CONFIG_PATH", "#{Formula["glib"].opt_lib}/pkgconfig"

Prepending a system path such as /usr/bin is a no-op so that requirements don't accidentally override superenv shims or formulae's bin directories.

ENV.prepend_path "PATH", which("emacs").dirname

Parameters:



146
147
148
149
150
# File 'extend/ENV/shared.rb', line 146

def prepend_path(key, path)
  return if %w[/usr/bin /bin /usr/sbin /sbin].include? path.to_s

  self[key] = PATH.new(self[key]).prepend(path).to_s
end

#refurbish_args ⇒ 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.

This method returns an undefined value.



359
# File 'extend/ENV/shared.rb', line 359

def refurbish_args; end

#remove(keys, value) ⇒ 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.

This method returns an undefined value.

Parameters:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'extend/ENV/shared.rb', line 160

def remove(keys, value)
  return if value.nil?

  Array(keys).each do |key|
    old_value = self[key]
    next if old_value.nil?

    new_value = old_value.sub(value, "")
    if new_value.empty?
      delete(key)
    else
      self[key] = new_value
    end
  end
end

#remove_cc_etc ⇒ Hash{String => String, nil}

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:



82
83
84
85
# File 'extend/ENV/shared.rb', line 82

def remove_cc_etc
  keys = %w[CC CXX OBJC OBJCXX LD CPP CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS LDFLAGS CPPFLAGS]
  keys.to_h { |key| [key, delete(key)] }
end

#remove_from_cflags(val) ⇒ 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.

This method returns an undefined value.

Parameters:



93
94
95
# File 'extend/ENV/shared.rb', line 93

def remove_from_cflags(val)
  remove CC_FLAG_VARS, val
end

#setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) ⇒ 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.

This method returns an undefined value.

Parameters:

  • formula (Formula, nil) (defaults to: nil)
  • cc (String, nil) (defaults to: nil)
  • build_bottle (Boolean, nil) (defaults to: false)
  • bottle_arch (String, nil) (defaults to: nil)
  • testing_formula (Boolean) (defaults to: false)
  • debug_symbols (Boolean, nil) (defaults to: false)


57
58
59
60
61
62
63
64
65
66
67
# File 'extend/ENV/shared.rb', line 57

def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
                            debug_symbols: false)
  state = build_environment_state(writable: true)
  state.formula = formula
  state.cc = cc
  state.build_bottle = build_bottle
  state.bottle_arch = bottle_arch
  state.debug_symbols = debug_symbols
  state.testing_formula = testing_formula
  reset
end