Module: SharedEnvExtension Private

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

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.

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 OS::Mac::SharedEnvExtension

#no_fixup_chains_support?, #no_weak_imports_support?

Instance Method Details

#[]=(key, value) ⇒ T.type_parameter(:U)

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.

Overload to allow PATH values.

Parameters:

  • key (String)
  • value (T.all(T.type_parameter(:U), T.nilable(T.any(String, PATH))))

Returns:

  • (T.type_parameter(:U))


11
# File 'extend/ENV/shared.rbi', line 11

def []=(key, value); end

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



86
87
88
89
90
91
92
93
94
95
96
# File 'extend/ENV/shared.rb', line 86

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:



112
113
114
# File 'extend/ENV/shared.rb', line 112

def append_path(key, path)
  self[key] = PATH.new(self[key]).append(path)
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:



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

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:



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

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

#ccString?

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:



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

def cc
  self["CC"]
end

#cflagsString?

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:



165
166
167
# File 'extend/ENV/shared.rb', line 165

def cflags
  self["CFLAGS"]
end

#compilerSymbol, 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:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'extend/ENV/shared.rb', line 206

def compiler
  @compiler ||= if (cc = @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
      compilers = [compiler] + CompilerSelector.compilers
      compiler = CompilerSelector.select_for(@formula, compilers)
    end

    compiler
  elsif @formula
    CompilerSelector.select_for(@formula)
  else
    DevelopmentTools.default_compiler
  end
end

#cppflagsString?

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:



175
176
177
# File 'extend/ENV/shared.rb', line 175

def cppflags
  self["CPPFLAGS"]
end

#cxxString?

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:



160
161
162
# File 'extend/ENV/shared.rb', line 160

def cxx
  self["CXX"]
end

#cxxflagsString?

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:



170
171
172
# File 'extend/ENV/shared.rb', line 170

def cxxflags
  self["CXXFLAGS"]
end

#effective_archSymbol

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:



276
277
278
279
280
281
282
# File 'extend/ENV/shared.rb', line 276

def effective_arch
  if @build_bottle && @bottle_arch
    @bottle_arch.to_sym
  else
    Hardware.oldest_cpu
  end
end

#fcString?

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:



185
186
187
# File 'extend/ENV/shared.rb', line 185

def fc
  self["FC"]
end

#fcflagsString?

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:



195
196
197
# File 'extend/ENV/shared.rb', line 195

def fcflags
  self["FCFLAGS"]
end

#fflagsString?

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:



190
191
192
# File 'extend/ENV/shared.rb', line 190

def fflags
  self["FFLAGS"]
end

#fortranvoid

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.



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'extend/ENV/shared.rb', line 245

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 @fortran_setup_done

  @fortran_setup_done = true

  flags = []

  if fc
    ohai "Building with an alternative Fortran compiler", "This is unsupported."
    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
      flags = FC_FLAG_VARS
    end
  end

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

#ldflagsString?

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:



180
181
182
# File 'extend/ENV/shared.rb', line 180

def ldflags
  self["LDFLAGS"]
end

#make_jobsInteger

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:

  • (Integer)


321
322
323
# File 'extend/ENV/shared.rb', line 321

def make_jobs
  Homebrew::EnvConfig.make_jobs.to_i
end

#permit_arch_flagsvoid

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.



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

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:



99
100
101
102
103
104
105
106
107
108
109
# File 'extend/ENV/shared.rb', line 99

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:



131
132
133
134
135
# File 'extend/ENV/shared.rb', line 131

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:



124
125
126
127
128
# File 'extend/ENV/shared.rb', line 124

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)
end

#refurbish_argsvoid

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.



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

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:



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'extend/ENV/shared.rb', line 138

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_etcHash{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:



65
66
67
68
# File 'extend/ENV/shared.rb', line 65

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:



76
77
78
# File 'extend/ENV/shared.rb', line 76

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)


48
49
50
51
52
53
54
55
56
# File 'extend/ENV/shared.rb', line 48

def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
                            debug_symbols: false)
  @formula = formula
  @cc = cc
  @build_bottle = build_bottle
  @bottle_arch = bottle_arch
  @debug_symbols = debug_symbols
  reset
end