Module: SystemConfig Private

Extended by:
SystemCommand::Mixin
Includes:
SystemCommand::Mixin
Defined in:
system_config.rb,
extend/os/mac/system_config.rb,
extend/os/linux/system_config.rb

Overview

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.

Helper module for querying information about the system configuration.

Constant Summary collapse

HOST_RUBY_PATH =
"/usr/bin/ruby"

Class Method Summary collapse

Methods included from SystemCommand::Mixin

system_command, system_command!

Class Method Details

.clangObject

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.



17
18
19
20
21
22
23
# File 'system_config.rb', line 17

def clang
  @clang ||= if DevelopmentTools.installed?
    DevelopmentTools.clang_version
  else
    Version::NULL
  end
end

.clang_buildObject

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.



25
26
27
28
29
30
31
# File 'system_config.rb', line 25

def clang_build
  @clang_build ||= if DevelopmentTools.installed?
    DevelopmentTools.clang_build_version
  else
    Version::NULL
  end
end

.cltObject



37
38
39
# File 'extend/os/mac/system_config.rb', line 37

def clt
  @clt ||= MacOS::CLT.version if MacOS::CLT.installed?
end

.core_tap_branchString

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 'system_config.rb', line 64

def core_tap_branch
  CoreTap.instance.git_branch || "(none)"
end

.core_tap_config(out = $stdout) ⇒ 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.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'system_config.rb', line 141

def core_tap_config(out = $stdout)
  if CoreTap.instance.installed?
    out.puts "Core tap origin: #{core_tap_origin}"
    out.puts "Core tap HEAD: #{core_tap_head}"
    out.puts "Core tap last commit: #{core_tap_last_commit}"
    out.puts "Core tap branch: #{core_tap_branch}"
  end

  if (formula_json = Homebrew::API::HOMEBREW_CACHE_API/"formula.jws.json") && formula_json.exist?
    out.puts "Core tap JSON: #{formula_json.mtime.utc.strftime("%d %b %H:%M UTC")}"
  elsif !CoreTap.instance.installed?
    out.puts "Core tap: N/A"
  end
end

.core_tap_headString

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:



54
55
56
# File 'system_config.rb', line 54

def core_tap_head
  CoreTap.instance.git_head || "(none)"
end

.core_tap_last_commitString

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:



59
60
61
# File 'system_config.rb', line 59

def core_tap_last_commit
  CoreTap.instance.git_last_commit || "never"
end

.core_tap_originString

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
# File 'system_config.rb', line 69

def core_tap_origin
  CoreTap.instance.remote
end

.describe_clangString

Returns:



22
23
24
25
26
27
# File 'extend/os/mac/system_config.rb', line 22

def describe_clang
  return "N/A" if clang.null?

  clang_build_info = clang_build.null? ? "(parse error)" : clang_build
  "#{clang} build #{clang_build_info}"
end

.describe_curlString

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:



130
131
132
133
134
135
136
137
138
139
# File 'system_config.rb', line 130

def describe_curl
  out, = system_command(curl_executable, args: ["--version"], verbose: false)

  match_data = /^curl (?<curl_version>[\d.]+)/.match(out)
  if match_data
    "#{match_data[:curl_version]} => #{curl_path}"
  else
    "N/A"
  end
end

.describe_gitString

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:



123
124
125
126
127
# File 'system_config.rb', line 123

def describe_git
  return "N/A" unless Utils::Git.available?

  "#{Utils::Git.version} => #{Utils::Git.path}"
end

.describe_homebrew_rubyString

Returns:



12
13
14
15
16
17
18
19
20
# File 'extend/os/mac/system_config.rb', line 12

def describe_homebrew_ruby
  s = describe_homebrew_ruby_version

  if RUBY_PATH.to_s.match?(%r{^/System/Library/Frameworks/Ruby\.framework/Versions/[12]\.[089]/usr/bin/ruby})
    s
  else
    "#{s} => #{RUBY_PATH}"
  end
end

.describe_homebrew_ruby_versionString

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:



96
97
98
99
100
101
102
103
# File 'system_config.rb', line 96

def describe_homebrew_ruby_version
  case RUBY_VERSION
  when /^1\.[89]/, /^2\.0/
    "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
  else
    RUBY_VERSION
  end
end

.describe_path(path) ⇒ 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.



84
85
86
87
88
89
90
91
92
93
# File 'system_config.rb', line 84

def describe_path(path)
  return "N/A" if path.nil?

  realpath = path.realpath
  if realpath == path
    path
  else
    "#{path} => #{realpath}"
  end
end

.dump_verbose_config(out = $stdout) ⇒ Object Also known as: dump_generic_verbose_config

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.



41
42
43
44
45
46
47
# File 'extend/os/mac/system_config.rb', line 41

def dump_verbose_config(out = $stdout)
  dump_generic_verbose_config(out)
  out.puts "macOS: #{MacOS.full_version}-#{kernel}"
  out.puts "CLT: #{clt || "N/A"}"
  out.puts "Xcode: #{xcode || "N/A"}"
  out.puts "Rosetta 2: #{Hardware::CPU.in_rosetta2?}" if Hardware::CPU.physical_cpu_arm64?
end

.formula_linked_version(formula) ⇒ Object



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

def formula_linked_version(formula)
  return "N/A" unless CoreTap.instance.installed?

  Formulary.factory(formula).any_installed_version || "N/A"
rescue FormulaUnavailableError
  "N/A"
end

.hardwareString?

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:



111
112
113
114
115
# File 'system_config.rb', line 111

def hardware
  return if Hardware::CPU.type == :dunno

  "CPU: #{Hardware.cores_as_words}-core #{Hardware::CPU.bits}-bit #{Hardware::CPU.family}"
end

.headString

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:



39
40
41
# File 'system_config.rb', line 39

def head
  homebrew_repo.head_ref || "(none)"
end

.homebrew_config(out = $stdout) ⇒ 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.



156
157
158
159
160
161
# File 'system_config.rb', line 156

def homebrew_config(out = $stdout)
  out.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}"
  out.puts "ORIGIN: #{origin}"
  out.puts "HEAD: #{head}"
  out.puts "Last commit: #{last_commit}"
end

.homebrew_env_config(out = $stdout) ⇒ 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.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'system_config.rb', line 163

def homebrew_env_config(out = $stdout)
  out.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}"
  {
    HOMEBREW_REPOSITORY: Homebrew::DEFAULT_REPOSITORY,
    HOMEBREW_CELLAR:     Homebrew::DEFAULT_CELLAR,
  }.freeze.each do |key, default|
    value = Object.const_get(key)
    out.puts "#{key}: #{value}" if value.to_s != default.to_s
  end

  Homebrew::EnvConfig::ENVS.each do |env, hash|
    method_name = Homebrew::EnvConfig.env_method_name(env, hash)

    if hash[:boolean]
      out.puts "#{env}: set" if Homebrew::EnvConfig.send(method_name)
      next
    end

    value = Homebrew::EnvConfig.send(method_name)
    next unless value
    next if (default = hash[:default].presence) && value.to_s == default.to_s

    if ENV.sensitive?(env)
      out.puts "#{env}: set"
    else
      out.puts "#{env}: #{value}"
    end
  end
  out.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
end

.homebrew_repoGitRepository

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:



34
35
36
# File 'system_config.rb', line 34

def homebrew_repo
  GitRepository.new(HOMEBREW_REPOSITORY)
end

.host_gcc_versionObject



21
22
23
24
25
26
# File 'extend/os/linux/system_config.rb', line 21

def host_gcc_version
  gcc = Pathname.new "/usr/bin/gcc"
  return "N/A" unless gcc.executable?

  `#{gcc} --version 2>/dev/null`[/ (\d+\.\d+\.\d+)/, 1]
end

.host_glibc_versionObject



14
15
16
17
18
19
# File 'extend/os/linux/system_config.rb', line 14

def host_glibc_version
  version = OS::Linux::Glibc.system_version
  return "N/A" if version.null?

  version
end

.host_ruby_versionObject



36
37
38
39
40
41
# File 'extend/os/linux/system_config.rb', line 36

def host_ruby_version
  out, _, status = system_command(HOST_RUBY_PATH, args: ["-e", "puts RUBY_VERSION"], print_stderr: false)
  return "N/A" unless status.success?

  out
end

.host_software_config(out = $stdout) ⇒ 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.



194
195
196
197
198
# File 'system_config.rb', line 194

def host_software_config(out = $stdout)
  out.puts "Clang: #{describe_clang}"
  out.puts "Git: #{describe_git}"
  out.puts "Curl: #{describe_curl}"
end

.kernelString

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:



118
119
120
# File 'system_config.rb', line 118

def kernel
  `uname -m`.chomp
end

.last_commitString

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:



44
45
46
# File 'system_config.rb', line 44

def last_commit
  homebrew_repo.last_committed || "never"
end

.originString

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:



49
50
51
# File 'system_config.rb', line 49

def origin
  homebrew_repo.origin_url || "(none)"
end

.xcodeObject



29
30
31
32
33
34
35
# File 'extend/os/mac/system_config.rb', line 29

def xcode
  @xcode ||= if MacOS::Xcode.installed?
    xcode = MacOS::Xcode.version.to_s
    xcode += " => #{MacOS::Xcode.prefix}" unless MacOS::Xcode.default_prefix?
    xcode
  end
end