Module: SharedEnvExtension

Extended by:
T::Sig
Included in:
Stdenv, Superenv
Defined in:
extend/os/mac/extend/ENV/shared.rb,
extend/os/linux/extend/ENV/shared.rb,
extend/ENV/shared.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#append(keys, value, separator = " ") ⇒ void

This method returns an undefined value.

Parameters:



82
83
84
85
86
87
88
89
90
91
92
# File 'extend/ENV/shared.rb', line 82

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 returns an undefined value.

Parameters:



108
109
110
# File 'extend/ENV/shared.rb', line 108

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

#append_to_cccfg(value) ⇒ void

This method returns an undefined value.

Parameters:



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

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

#append_to_cflags(newflags) ⇒ void

This method returns an undefined value.

Parameters:



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

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

#ccString?

Returns:



151
152
153
# File 'extend/ENV/shared.rb', line 151

def cc
  self["CC"]
end

#cflagsString?

Returns:



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

def cflags
  self["CFLAGS"]
end

#compilerSymbol, String

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:



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'extend/ENV/shared.rb', line 202

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?

Returns:



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

def cppflags
  self["CPPFLAGS"]
end

#cxxString?

Returns:



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

def cxx
  self["CXX"]
end

#cxxflagsString?

Returns:



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

def cxxflags
  self["CXXFLAGS"]
end

#fcString?

Returns:



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

def fc
  self["FC"]
end

#fcflagsString?

Returns:



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

def fcflags
  self["FCFLAGS"]
end

#fflagsString?

Returns:



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

def fflags
  self["FFLAGS"]
end

#fortranvoid

This method returns an undefined value.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'extend/ENV/shared.rb', line 254

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?

Returns:



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

def ldflags
  self["LDFLAGS"]
end

#ncurses_definevoid

This method returns an undefined value.

Snow Leopard defines an NCURSES value the opposite of most distros.



243
244
245
# File 'extend/ENV/shared.rb', line 243

def ncurses_define
  odisabled "ENV.ncurses_define"
end

#no_weak_imports_support?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'extend/os/mac/extend/ENV/shared.rb', line 8

def no_weak_imports_support?
  return false unless compiler == :clang

  return false if MacOS::Xcode.version && MacOS::Xcode.version < "8.0"
  return false if MacOS::CLT.version && MacOS::CLT.version < "8.0"

  true
end

#permit_arch_flagsvoid

This method returns an undefined value.



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

def permit_arch_flags; end

#permit_weak_importsvoid

This method returns an undefined value.



331
332
333
# File 'extend/ENV/shared.rb', line 331

def permit_weak_imports
  odisabled "ENV.permit_weak_imports"
end

#prepend(keys, value, separator = " ") ⇒ void

This method returns an undefined value.

Parameters:



95
96
97
98
99
100
101
102
103
104
105
# File 'extend/ENV/shared.rb', line 95

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 returns an undefined value.

Parameters:



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

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

#prepend_path(key, path) ⇒ void

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:



120
121
122
123
124
# File 'extend/ENV/shared.rb', line 120

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

#remove(keys, value) ⇒ void

This method returns an undefined value.

Parameters:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'extend/ENV/shared.rb', line 134

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}

Returns:



61
62
63
64
# File 'extend/ENV/shared.rb', line 61

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

#remove_from_cflags(val) ⇒ void

This method returns an undefined value.

Parameters:



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

def remove_from_cflags(val)
  remove CC_FLAG_VARS, val
end