Module: SystemConfig Private

Defined in:
Library/Homebrew/system_config.rb,
Library/Homebrew/extend/os/mac/system_config.rb,
Library/Homebrew/extend/os/linux/system_config.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper module for querying information about the system configuration.

Class Method Summary collapse

Class Method Details

.clangObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
16
17
18
19
# File 'Library/Homebrew/system_config.rb', line 13

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

.clang_buildObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


21
22
23
24
25
26
27
# File 'Library/Homebrew/system_config.rb', line 21

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

.cltObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


35
36
37
# File 'Library/Homebrew/extend/os/mac/system_config.rb', line 35

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

.core_tap_branchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


49
50
51
# File 'Library/Homebrew/system_config.rb', line 49

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

.core_tap_headObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


41
42
43
# File 'Library/Homebrew/system_config.rb', line 41

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

.core_tap_last_commitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


45
46
47
# File 'Library/Homebrew/system_config.rb', line 45

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

.core_tap_originObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


53
54
55
# File 'Library/Homebrew/system_config.rb', line 53

def core_tap_origin
  CoreTap.instance.remote || "(none)"
end

.describe_curlObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


106
107
108
109
110
111
112
113
114
# File 'Library/Homebrew/system_config.rb', line 106

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

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

.describe_gitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


100
101
102
103
104
# File 'Library/Homebrew/system_config.rb', line 100

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

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

.describe_homebrew_rubyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


77
78
79
# File 'Library/Homebrew/system_config.rb', line 77

def describe_homebrew_ruby
  "#{describe_homebrew_ruby_version} => #{RUBY_PATH}"
end

.describe_homebrew_ruby_versionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


68
69
70
71
72
73
74
75
# File 'Library/Homebrew/system_config.rb', line 68

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

.describe_javaObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


91
92
93
94
95
96
97
98
# File 'Library/Homebrew/system_config.rb', line 91

def describe_java
  return "N/A" unless which "java"

  _, err, status = system_command("java", args: ["-version"], print_stderr: false)
  return "N/A" unless status.success?

  err[/java version "([\d._]+)"/, 1] || "N/A"
end

.describe_path(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


57
58
59
60
61
62
63
64
65
66
# File 'Library/Homebrew/system_config.rb', line 57

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

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

.dump_generic_verbose_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'Library/Homebrew/system_config.rb', line 177

def dump_verbose_config(f = $stdout)
  f.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}"
  f.puts "ORIGIN: #{origin}"
  f.puts "HEAD: #{head}"
  f.puts "Last commit: #{last_commit}"
  if CoreTap.instance.installed?
    f.puts "Core tap ORIGIN: #{core_tap_origin}"
    f.puts "Core tap HEAD: #{core_tap_head}"
    f.puts "Core tap last commit: #{core_tap_last_commit}"
    f.puts "Core tap branch: #{core_tap_branch}"
  else
    f.puts "Core tap: N/A"
  end
  f.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)
    f.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]
      f.puts "#{env}: set" if Homebrew::EnvConfig.send(method_name)
      next
    end

    value = Homebrew::EnvConfig.send(method_name)
    next unless value

    if (default = hash[:default].presence)
      next if value.to_s == default.to_s
    end

    if ENV.sensitive?(env)
      f.puts "#{env}: set"
    else
      f.puts "#{env}: #{value}"
    end
  end

  f.puts hardware if hardware
  f.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
  f.print "Clang: "
  if clang.null?
    f.puts "N/A"
  else
    f.print "#{clang} build "
    if clang_build.null?
      f.puts "(parse error)"
    else
      f.puts clang_build
    end
  end
  f.puts "Git: #{describe_git}"
  f.puts "Curl: #{describe_curl}"
  f.puts "Java: #{describe_java}" if describe_java != "N/A"
end

.dump_verbose_config(out = $stdout) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'Library/Homebrew/system_config.rb', line 116

def dump_verbose_config(f = $stdout)
  f.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}"
  f.puts "ORIGIN: #{origin}"
  f.puts "HEAD: #{head}"
  f.puts "Last commit: #{last_commit}"
  if CoreTap.instance.installed?
    f.puts "Core tap ORIGIN: #{core_tap_origin}"
    f.puts "Core tap HEAD: #{core_tap_head}"
    f.puts "Core tap last commit: #{core_tap_last_commit}"
    f.puts "Core tap branch: #{core_tap_branch}"
  else
    f.puts "Core tap: N/A"
  end
  f.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)
    f.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]
      f.puts "#{env}: set" if Homebrew::EnvConfig.send(method_name)
      next
    end

    value = Homebrew::EnvConfig.send(method_name)
    next unless value

    if (default = hash[:default].presence)
      next if value.to_s == default.to_s
    end

    if ENV.sensitive?(env)
      f.puts "#{env}: set"
    else
      f.puts "#{env}: #{value}"
    end
  end

  f.puts hardware if hardware
  f.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
  f.print "Clang: "
  if clang.null?
    f.puts "N/A"
  else
    f.print "#{clang} build "
    if clang_build.null?
      f.puts "(parse error)"
    else
      f.puts clang_build
    end
  end
  f.puts "Git: #{describe_git}"
  f.puts "Curl: #{describe_curl}"
  f.puts "Java: #{describe_java}" if describe_java != "N/A"
end

.formula_linked_version(formula) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


22
23
24
25
26
27
28
# File 'Library/Homebrew/extend/os/linux/system_config.rb', line 22

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

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

.hardwareObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


81
82
83
84
85
# File 'Library/Homebrew/system_config.rb', line 81

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

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

.headObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


29
30
31
# File 'Library/Homebrew/system_config.rb', line 29

def head
  HOMEBREW_REPOSITORY.git_head || "(none)"
end

.host_gcc_versionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


8
9
10
11
12
13
# File 'Library/Homebrew/extend/os/linux/system_config.rb', line 8

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

  version
end

.kernelObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


87
88
89
# File 'Library/Homebrew/system_config.rb', line 87

def kernel
  `uname -m`.chomp
end

.last_commitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


33
34
35
# File 'Library/Homebrew/system_config.rb', line 33

def last_commit
  HOMEBREW_REPOSITORY.git_last_commit || "never"
end

.originObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


37
38
39
# File 'Library/Homebrew/system_config.rb', line 37

def origin
  HOMEBREW_REPOSITORY.git_origin || "(none)"
end

.xcodeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


27
28
29
30
31
32
33
# File 'Library/Homebrew/extend/os/mac/system_config.rb', line 27

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

.xquartzObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


39
40
41
# File 'Library/Homebrew/extend/os/mac/system_config.rb', line 39

def xquartz
  @xquartz ||= "#{MacOS::XQuartz.version} => #{describe_path(MacOS::XQuartz.prefix)}" if MacOS::XQuartz.installed?
end