Class: SystemConfig

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/system_config.rb,
brew/Library/Homebrew/extend/os/mac/system_config.rb,
brew/Library/Homebrew/extend/os/linux/system_config.rb

Class Method Summary collapse

Class Method Details

.clangObject



11
12
13
14
15
16
17
# File 'brew/Library/Homebrew/system_config.rb', line 11

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

.clang_buildObject



19
20
21
22
23
24
25
# File 'brew/Library/Homebrew/system_config.rb', line 19

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

.cltObject



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

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

.clt_headersObject



44
45
46
# File 'brew/Library/Homebrew/extend/os/mac/system_config.rb', line 44

def clt_headers
  @clt_headers ||= MacOS::CLT.headers_version if MacOS::CLT.headers_installed?
end

.core_tap_headObject



39
40
41
# File 'brew/Library/Homebrew/system_config.rb', line 39

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

.core_tap_last_commitObject



43
44
45
# File 'brew/Library/Homebrew/system_config.rb', line 43

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

.core_tap_originObject



47
48
49
# File 'brew/Library/Homebrew/system_config.rb', line 47

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

.describe_curlObject



100
101
102
103
104
105
106
107
108
# File 'brew/Library/Homebrew/system_config.rb', line 100

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



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

def describe_git
  return "N/A" unless Utils.git_available?

  "#{Utils.git_version} => #{Utils.git_path}"
end

.describe_homebrew_rubyObject



71
72
73
# File 'brew/Library/Homebrew/system_config.rb', line 71

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

.describe_homebrew_ruby_versionObject



62
63
64
65
66
67
68
69
# File 'brew/Library/Homebrew/system_config.rb', line 62

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



85
86
87
88
89
90
91
92
# File 'brew/Library/Homebrew/system_config.rb', line 85

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



51
52
53
54
55
56
57
58
59
60
# File 'brew/Library/Homebrew/system_config.rb', line 51

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



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
238
239
240
241
242
243
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
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'brew/Library/Homebrew/system_config.rb', line 198

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}"
  else
    f.puts "Core tap: N/A"
  end
  defaults_hash = {
    HOMEBREW_PREFIX:        Homebrew::DEFAULT_PREFIX,
    HOMEBREW_REPOSITORY:    Homebrew::DEFAULT_REPOSITORY,
    HOMEBREW_CELLAR:        Homebrew::DEFAULT_CELLAR,
    HOMEBREW_CACHE:         "#{ENV["HOME"]}/Library/Caches/Homebrew",
    HOMEBREW_LOGS:          "#{ENV["HOME"]}/Library/Logs/Homebrew",
    HOMEBREW_TEMP:          ENV["HOMEBREW_SYSTEM_TEMP"],
    HOMEBREW_RUBY_WARNINGS: "-W0",
  }.freeze
  boring_keys = %w[
    HOMEBREW_BROWSER
    HOMEBREW_EDITOR

    HOMEBREW_ANALYTICS_ID
    HOMEBREW_ANALYTICS_USER_UUID
    HOMEBREW_AUTO_UPDATE_CHECKED
    HOMEBREW_BOTTLE_DEFAULT_DOMAIN
    HOMEBREW_BOTTLE_DOMAIN
    HOMEBREW_BREW_FILE
    HOMEBREW_COMMAND_DEPTH
    HOMEBREW_CURL
    HOMEBREW_DISPLAY
    HOMEBREW_GIT
    HOMEBREW_GIT_CONFIG_FILE
    HOMEBREW_LIBRARY
    HOMEBREW_MACOS_VERSION
    HOMEBREW_MACOS_VERSION_NUMERIC
    HOMEBREW_MINIMUM_GIT_VERSION
    HOMEBREW_RUBY_PATH
    HOMEBREW_SYSTEM
    HOMEBREW_SYSTEM_TEMP
    HOMEBREW_OS_VERSION
    HOMEBREW_PATH
    HOMEBREW_PROCESSOR
    HOMEBREW_PRODUCT
    HOMEBREW_USER_AGENT
    HOMEBREW_USER_AGENT_CURL
    HOMEBREW_VERSION
  ].freeze
  f.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}"
  [:HOMEBREW_CELLAR, :HOMEBREW_CACHE, :HOMEBREW_LOGS, :HOMEBREW_REPOSITORY,
   :HOMEBREW_TEMP].each do |key|
    value = Object.const_get(key)
    f.puts "#{key}: #{value}" if defaults_hash[key] != value.to_s
  end
  if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s
    f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}"
  end
  unless ENV["HOMEBREW_ENV"]
    ENV.sort.each do |key, value|
      next unless key.start_with?("HOMEBREW_")
      next if key.start_with?("HOMEBREW_BUNDLE_")
      next if boring_keys.include?(key)
      next if defaults_hash[key.to_sym]

      value = "set" if ENV.sensitive?(key)
      f.puts "#{key}: #{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



110
111
112
113
114
115
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'brew/Library/Homebrew/system_config.rb', line 110

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}"
  else
    f.puts "Core tap: N/A"
  end
  defaults_hash = {
    HOMEBREW_PREFIX:        Homebrew::DEFAULT_PREFIX,
    HOMEBREW_REPOSITORY:    Homebrew::DEFAULT_REPOSITORY,
    HOMEBREW_CELLAR:        Homebrew::DEFAULT_CELLAR,
    HOMEBREW_CACHE:         "#{ENV["HOME"]}/Library/Caches/Homebrew",
    HOMEBREW_LOGS:          "#{ENV["HOME"]}/Library/Logs/Homebrew",
    HOMEBREW_TEMP:          ENV["HOMEBREW_SYSTEM_TEMP"],
    HOMEBREW_RUBY_WARNINGS: "-W0",
  }.freeze
  boring_keys = %w[
    HOMEBREW_BROWSER
    HOMEBREW_EDITOR

    HOMEBREW_ANALYTICS_ID
    HOMEBREW_ANALYTICS_USER_UUID
    HOMEBREW_AUTO_UPDATE_CHECKED
    HOMEBREW_BOTTLE_DEFAULT_DOMAIN
    HOMEBREW_BOTTLE_DOMAIN
    HOMEBREW_BREW_FILE
    HOMEBREW_COMMAND_DEPTH
    HOMEBREW_CURL
    HOMEBREW_DISPLAY
    HOMEBREW_GIT
    HOMEBREW_GIT_CONFIG_FILE
    HOMEBREW_LIBRARY
    HOMEBREW_MACOS_VERSION
    HOMEBREW_MACOS_VERSION_NUMERIC
    HOMEBREW_MINIMUM_GIT_VERSION
    HOMEBREW_RUBY_PATH
    HOMEBREW_SYSTEM
    HOMEBREW_SYSTEM_TEMP
    HOMEBREW_OS_VERSION
    HOMEBREW_PATH
    HOMEBREW_PROCESSOR
    HOMEBREW_PRODUCT
    HOMEBREW_USER_AGENT
    HOMEBREW_USER_AGENT_CURL
    HOMEBREW_VERSION
  ].freeze
  f.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}"
  [:HOMEBREW_CELLAR, :HOMEBREW_CACHE, :HOMEBREW_LOGS, :HOMEBREW_REPOSITORY,
   :HOMEBREW_TEMP].each do |key|
    value = Object.const_get(key)
    f.puts "#{key}: #{value}" if defaults_hash[key] != value.to_s
  end
  if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s
    f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}"
  end
  unless ENV["HOMEBREW_ENV"]
    ENV.sort.each do |key, value|
      next unless key.start_with?("HOMEBREW_")
      next if key.start_with?("HOMEBREW_BUNDLE_")
      next if boring_keys.include?(key)
      next if defaults_hash[key.to_sym]

      value = "set" if ENV.sensitive?(key)
      f.puts "#{key}: #{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



22
23
24
25
26
27
28
# File 'brew/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



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

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

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

.headObject



27
28
29
# File 'brew/Library/Homebrew/system_config.rb', line 27

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

.host_gcc_versionObject



15
16
17
18
19
20
# File 'brew/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



8
9
10
11
12
13
# File 'brew/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



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

def kernel
  `uname -m`.chomp
end

.last_commitObject



31
32
33
# File 'brew/Library/Homebrew/system_config.rb', line 31

def last_commit
  HOMEBREW_REPOSITORY.git_last_commit || "never"
end

.originObject



35
36
37
# File 'brew/Library/Homebrew/system_config.rb', line 35

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

.xcodeObject



32
33
34
35
36
37
38
# File 'brew/Library/Homebrew/extend/os/mac/system_config.rb', line 32

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



48
49
50
# File 'brew/Library/Homebrew/extend/os/mac/system_config.rb', line 48

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