Class: DevelopmentTools

Inherits:
Object show all
Defined in:
extend/os/linux/development_tools.rb,
extend/os/mac/development_tools.rb,
development_tools.rb

Overview

Helper class for gathering information about development tools.

Class Method Summary collapse

Class Method Details

.build_system_infoHash{String => String, nil} Also known as: generic_build_system_info

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:



77
78
79
80
81
82
83
84
# File 'extend/os/mac/development_tools.rb', line 77

def build_system_info
  build_info = {
    "xcode"          => MacOS::Xcode.version.to_s.presence,
    "clt"            => MacOS::CLT.version.to_s.presence,
    "preferred_perl" => MacOS.preferred_perl_version,
  }
  generic_build_system_info.merge build_info
end

.ca_file_handles_most_https_certificates?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)


143
144
145
146
147
# File 'development_tools.rb', line 143

def ca_file_handles_most_https_certificates?
  # The system CA file is too old for some modern HTTPS certificates on
  # older OS versions.
  ENV["HOMEBREW_SYSTEM_CA_CERTIFICATES_TOO_OLD"].nil?
end

.ca_file_substitution_required?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)


155
156
157
158
# File 'development_tools.rb', line 155

def ca_file_substitution_required?
  (!ca_file_handles_most_https_certificates? || ENV["HOMEBREW_FORCE_BREWED_CA_CERTIFICATES"].present?) &&
    !(HOMEBREW_PREFIX/"etc/ca-certificates/cert.pem").exist?
end

.clang_build_versionVersion

Get the Clang build version.

Returns:



77
78
79
80
81
82
83
84
85
# File 'development_tools.rb', line 77

def clang_build_version
  @clang_build_version ||= if (path = locate("clang")) &&
                              (build_version = `#{path} --version`[
%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2])
    Version.new build_version
  else
    Version::NULL
  end
end

.clang_versionVersion

Get the Clang version.

Returns:



64
65
66
67
68
69
70
71
# File 'development_tools.rb', line 64

def clang_version
  @clang_version ||= if (path = locate("clang")) &&
                        (build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1])
    Version.new build_version
  else
    Version::NULL
  end
end

.clear_version_cachevoid

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.



122
123
124
125
# File 'development_tools.rb', line 122

def clear_version_cache
  @clang_version = @clang_build_version = nil
  @gcc_version = {}
end

.curl_handles_most_https_certificates?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)


50
51
52
53
54
# File 'extend/os/mac/development_tools.rb', line 50

def curl_handles_most_https_certificates?
  # The system Curl is too old for some modern HTTPS certificates on
  # older macOS versions.
  ENV["HOMEBREW_SYSTEM_CURL_TOO_OLD"].nil?
end

.curl_substitution_required?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)


161
162
163
# File 'development_tools.rb', line 161

def curl_substitution_required?
  !curl_handles_most_https_certificates? && !HOMEBREW_BREWED_CURL_PATH.exist?
end

.custom_installation_instructionsString

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:



69
70
71
72
73
74
# File 'extend/os/mac/development_tools.rb', line 69

def custom_installation_instructions
  <<~EOS
    Install GNU's GCC:
      brew install gcc
  EOS
end

.default_compilerSymbol

Get the default C compiler.

Returns:



33
34
35
# File 'extend/os/mac/development_tools.rb', line 33

def default_compiler
  :clang
end

.gcc_version(cc) ⇒ Version

This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Get the GCC version.

Parameters:

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'development_tools.rb', line 107

def gcc_version(cc)
  (@gcc_version ||= {}).fetch(cc) do
    path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc
    path = locate(cc) unless path.exist?
    version = if path &&
                 (build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1])
      Version.new build_version
    else
      Version::NULL
    end
    @gcc_version[cc] = version
  end
end

.generic_locateObject



8
# File 'extend/os/mac/development_tools.rb', line 8

alias generic_locate locate

.insecure_download_warning(resource) ⇒ 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.

Parameters:

Returns:



45
46
47
48
49
50
# File 'development_tools.rb', line 45

def insecure_download_warning(resource)
  package = curl_handles_most_https_certificates? ? "ca-certificates" : "curl"
  "Using `--insecure` with curl to download #{resource} because we need it to run " \
    "`brew install #{package}` in order to download securely from now on. " \
    "Checksums will still be verified."
end

.installation_instructionsString

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:



64
65
66
# File 'extend/os/mac/development_tools.rb', line 64

def installation_instructions
  MacOS::CLT.installation_instructions
end

.installed?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.

Checks if the user has any developer tools installed, either via Xcode or the CLT. Convenient for guarding against formula builds when building is impossible.

Returns:

  • (Boolean)


28
29
30
# File 'extend/os/mac/development_tools.rb', line 28

def installed?
  MacOS::Xcode.installed? || MacOS::CLT.installed?
end

.ld64_versionVersion

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:



38
39
40
41
42
43
44
45
46
47
# File 'extend/os/mac/development_tools.rb', line 38

def ld64_version
  @ld64_version ||= begin
    json = Utils.popen_read("/usr/bin/ld", "-version_details")
    if $CHILD_STATUS.success?
      Version.parse(JSON.parse(json)["version"])
    else
      Version::NULL
    end
  end
end

.llvm_clang_build_versionVersion

Get the LLVM Clang build version.

Returns:



91
92
93
94
95
96
97
98
99
100
101
# File 'development_tools.rb', line 91

def llvm_clang_build_version
  @llvm_clang_build_version ||= begin
    path = Formulary.factory("llvm").opt_prefix/"bin/clang"
    if path.executable? &&
       (build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1])
      Version.new build_version
    else
      Version::NULL
    end
  end
end

.locate(tool) ⇒ Pathname?

Locate a development tool.

Parameters:

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'extend/os/mac/development_tools.rb', line 13

def locate(tool)
  (@locate ||= {}).fetch(tool) do |key|
    @locate[key] = if (located_tool = generic_locate(tool))
      located_tool
    else
      path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool, err: :close).chomp
      Pathname.new(path) if File.executable?(path)
    end
  end
end

.needs_build_formulae?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)


128
129
130
# File 'development_tools.rb', line 128

def needs_build_formulae?
  needs_libc_formula? || needs_compiler_formula?
end

.needs_compiler_formula?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)


35
36
37
38
39
40
41
42
43
44
# File 'extend/os/linux/development_tools.rb', line 35

def needs_compiler_formula?
  return @needs_compiler_formula if defined? @needs_compiler_formula

  gcc = "/usr/bin/gcc"
  @needs_compiler_formula = if File.exist?(gcc)
    gcc_version(gcc) < OS::LINUX_GCC_CI_VERSION
  else
    true
  end
end

.needs_libc_formula?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)


28
29
30
31
32
# File 'extend/os/linux/development_tools.rb', line 28

def needs_libc_formula?
  return @needs_libc_formula if defined? @needs_libc_formula

  @needs_libc_formula = OS::Linux::Glibc.below_ci_version?
end

.subversion_handles_most_https_certificates?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)


57
58
59
60
61
# File 'extend/os/mac/development_tools.rb', line 57

def subversion_handles_most_https_certificates?
  # The system Subversion is too old for some HTTPS certificates on
  # older macOS versions.
  MacOS.version >= :sierra
end