Module: SharedEnvExtension
- 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
-
#append(keys, value, separator = " ") ⇒ void
-
#append_path(key, path) ⇒ void
-
#append_to_cccfg(value) ⇒ void
-
#append_to_cflags(newflags) ⇒ void
-
#cc ⇒ String?
-
#cflags ⇒ String?
-
#compiler ⇒ Symbol, String
Outputs the current compiler.
-
#cppflags ⇒ String?
-
#cxx ⇒ String?
-
#cxxflags ⇒ String?
-
#fc ⇒ String?
-
#fcflags ⇒ String?
-
#fflags ⇒ String?
-
#fortran ⇒ void
-
#ldflags ⇒ String?
-
#no_fixup_chains_support? ⇒ Boolean
-
#no_weak_imports_support? ⇒ Boolean
-
#permit_arch_flags ⇒ void
-
#prepend(keys, value, separator = " ") ⇒ void
-
#prepend_create_path(key, path) ⇒ void
-
#prepend_path(key, path) ⇒ void
Prepends a directory to
PATH
. -
#remove(keys, value) ⇒ void
-
#remove_cc_etc ⇒ Hash{String => String}
-
#remove_from_cflags(val) ⇒ void
Instance Method Details
#append(keys, value, separator = " ") ⇒ void
This method returns an undefined value.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'extend/ENV/shared.rb', line 85 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.
111 112 113 |
# File 'extend/ENV/shared.rb', line 111 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.
80 81 82 |
# File 'extend/ENV/shared.rb', line 80 def append_to_cccfg(value) append("HOMEBREW_CCCFG", value, "") end |
#append_to_cflags(newflags) ⇒ void
This method returns an undefined value.
70 71 72 |
# File 'extend/ENV/shared.rb', line 70 def append_to_cflags(newflags) append(CC_FLAG_VARS, newflags) end |
#compiler ⇒ Symbol, String
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'extend/ENV/shared.rb', line 205 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 |
#cppflags ⇒ String?
174 175 176 |
# File 'extend/ENV/shared.rb', line 174 def cppflags self["CPPFLAGS"] end |
#cxxflags ⇒ String?
169 170 171 |
# File 'extend/ENV/shared.rb', line 169 def cxxflags self["CXXFLAGS"] end |
#fcflags ⇒ String?
194 195 196 |
# File 'extend/ENV/shared.rb', line 194 def fcflags self["FCFLAGS"] end |
#fortran ⇒ void
This method returns an undefined value.
244 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 |
# File 'extend/ENV/shared.rb', line 244 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 |
#ldflags ⇒ String?
179 180 181 |
# File 'extend/ENV/shared.rb', line 179 def ldflags self["LDFLAGS"] end |
#no_fixup_chains_support? ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'extend/os/mac/extend/ENV/shared.rb', line 37 def no_fixup_chains_support? return false if MacOS.version <= :catalina # NOTE: `-version_details` is supported in Xcode 10.2 at the earliest. ld_version_details = JSON.parse(Utils.safe_popen_read("/usr/bin/ld", "-version_details")) ld_version = Version.parse(ld_version_details["version"]) # This is supported starting Xcode 13, which ships ld64-711. # https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes # https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2 ld_version >= 711 end |
#no_weak_imports_support? ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'extend/os/mac/extend/ENV/shared.rb', line 27 def no_weak_imports_support? return false if compiler != :clang return false if !MacOS::Xcode.version.null? && MacOS::Xcode.version < "8.0" return false if !MacOS::CLT.version.null? && MacOS::CLT.version < "8.0" true end |
#permit_arch_flags ⇒ void
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 returns an undefined value.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'extend/ENV/shared.rb', line 98 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.
130 131 132 133 134 |
# File 'extend/ENV/shared.rb', line 130 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
123 124 125 126 127 |
# File 'extend/ENV/shared.rb', line 123 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.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'extend/ENV/shared.rb', line 137 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}
64 65 66 67 |
# File 'extend/ENV/shared.rb', line 64 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 returns an undefined value.
75 76 77 |
# File 'extend/ENV/shared.rb', line 75 def remove_from_cflags(val) remove CC_FLAG_VARS, val end |