Module: Stdenv Private

Includes:
SharedEnvExtension
Defined in:
extend/os/mac/extend/ENV/std.rb,
extend/os/linux/extend/ENV/std.rb,
extend/ENV/std.rb

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 SharedEnvExtension

#append, #append_path, #append_to_cccfg, #append_to_cflags, #cc, #cflags, #compiler, #cppflags, #cxx, #cxxflags, #effective_arch, #fc, #fcflags, #fflags, #fortran, #ldflags, #no_fixup_chains_support?, #no_weak_imports_support?, #permit_arch_flags, #prepend, #prepend_create_path, #prepend_path, #remove, #remove_cc_etc, #remove_from_cflags

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #ensure_formula_installed!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #paths, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #quiet_system, #redact_secrets, #redirect_stdout, #require?, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_all, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

Instance Method Details

#clangvoid

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.



130
131
132
133
134
135
136
137
138
139
# File 'extend/ENV/std.rb', line 130

def clang
  super
  replace_in_cflags(/-Xarch_#{Hardware::CPU.arch_32_bit} (-march=\S*)/, '\1')
  map = Hardware::CPU.optimization_flags.dup
  if DevelopmentTools.clang_build_version < 700
    # Clang mistakenly enables AES-NI on plain Nehalem
    map[:nehalem] = "-march=nehalem -Xclang -target-feature -Xclang -aes"
  end
  set_cpu_cflags(map)
end

#cxx11void

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.



142
143
144
145
# File 'extend/ENV/std.rb', line 142

def cxx11
  append "CXX", "-std=c++11"
  libcxx
end

#deparallelize(&block) ⇒ T.untyped

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.

Removes the MAKEFLAGS environment variable, causing make to use a single job. This is useful for makefiles with race conditions. When passed a block, MAKEFLAGS is removed only for the duration of the block and is restored after its completion.

Parameters:

  • block (T.proc.returns(T.untyped))

Returns:

  • (T.untyped)


87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'extend/ENV/std.rb', line 87

def deparallelize(&block)
  old = self["MAKEFLAGS"]
  remove "MAKEFLAGS", /-j\d+/
  if block
    begin
      yield
    ensure
      self["MAKEFLAGS"] = old
    end
  end

  old
end

#determine_pkg_config_libdirPATH?

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:



74
75
76
77
78
79
80
81
# File 'extend/ENV/std.rb', line 74

def determine_pkg_config_libdir
  PATH.new(
    HOMEBREW_PREFIX/"lib/pkgconfig",
    HOMEBREW_PREFIX/"share/pkgconfig",
    homebrew_extra_pkg_config_paths,
    "/usr/lib/pkgconfig",
  ).existing
end

#libcxxvoid

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.



148
149
150
# File 'extend/ENV/std.rb', line 148

def libcxx
  append "CXX", "-stdlib=libc++" if compiler == :clang
end

#libxml2Object

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.

Some configure scripts won't find libxml2 without help. This is a no-op with macOS SDK 10.15.4 and later.



100
101
102
103
104
105
106
107
108
# File 'extend/os/mac/extend/ENV/std.rb', line 100

def libxml2
  sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed
  if !sdk
    append "CPPFLAGS", "-I/usr/include/libxml2"
  elsif !Pathname("#{sdk}/usr/include/libxml").directory?
    # Use the includes form the sdk
    append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2"
  end
end

#macosxsdk(version = nil, formula: nil, testing_formula: false) ⇒ Object

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.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'extend/os/mac/extend/ENV/std.rb', line 66

def macosxsdk(version = nil, formula: nil, testing_formula: false)
  # Sets all needed `lib` and `include` dirs to `CFLAGS`, `CPPFLAGS`, `LDFLAGS`.
  remove_macosxsdk
  min_version = version || MacOS.version
  append_to_cflags("-mmacosx-version-min=#{min_version}")
  self["CPATH"] = "#{HOMEBREW_PREFIX}/include"
  prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"

  sdk = if formula
    MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula)
  else
    MacOS.sdk(version)
  end
  return if !MacOS.sdk_root_needed? && sdk&.source != :xcode

  Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
  sdk = sdk.path

  # Extra setup to support Xcode 4.3+ without CLT.
  self["SDKROOT"] = sdk
  # Tell clang/gcc where system include's are:
  append_path "CPATH", "#{sdk}/usr/include"
  # The -isysroot is needed, too, because of the Frameworks
  append_to_cflags "-isysroot#{sdk}"
  append "CPPFLAGS", "-isysroot#{sdk}"
  # And the linker needs to find sdk/usr/lib
  append "LDFLAGS", "-isysroot#{sdk}"
  # Needed to build cmake itself and perhaps some cmake projects:
  append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr"
  append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
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)


153
154
155
# File 'extend/ENV/std.rb', line 153

def make_jobs
  Homebrew::EnvConfig.make_jobs.to_i
end

#no_fixup_chainsObject

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.



114
115
116
# File 'extend/os/mac/extend/ENV/std.rb', line 114

def no_fixup_chains
  append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support?
end

#no_weak_importsObject

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.



110
111
112
# File 'extend/os/mac/extend/ENV/std.rb', line 110

def no_weak_imports
  append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support?
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.

This method does nothing in Stdenv since there is no argument refurbishment.



159
# File 'extend/ENV/std.rb', line 159

def refurbish_args; end

#remove_macosxsdk(version = nil) ⇒ Object

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'extend/os/mac/extend/ENV/std.rb', line 43

def remove_macosxsdk(version = nil)
  # Clear all `lib` and `include` dirs from `CFLAGS`, `CPPFLAGS`, `LDFLAGS` that were
  # previously added by `macosxsdk`.
  remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/)
  delete("CPATH")
  remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"

  sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed(version)
  return unless sdk

  delete("SDKROOT")
  remove_from_cflags "-isysroot#{sdk}"
  remove "CPPFLAGS", "-isysroot#{sdk}"
  remove "LDFLAGS", "-isysroot#{sdk}"
  if HOMEBREW_PREFIX.to_s == "/usr/local"
    delete("CMAKE_PREFIX_PATH")
  else
    # It was set in `setup_build_environment`, so we have to restore it here.
    self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s
  end
  remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
end

#setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) ⇒ void Also known as: generic_setup_build_environment

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)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'extend/os/mac/extend/ENV/std.rb', line 23

def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
                            debug_symbols: false)
  generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:,
                                  testing_formula:, debug_symbols:)

  append "LDFLAGS", "-Wl,-headerpad_max_install_names"

  # `sed` is strict and errors out when it encounters files with mixed character sets.
  delete("LC_ALL")
  self["LC_CTYPE"] = "C"

  # Add `lib` and `include` etc. from the current `macosxsdk` to compiler flags:
  macosxsdk(formula: @formula, testing_formula:)

  return unless MacOS::Xcode.without_clt?

  append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin"
  append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin"
end