Class: SystemConfig

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

Class Method Summary collapse

Class Method Details

.clangObject


11
12
13
14
15
16
17
# File '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 '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 'Library/Homebrew/extend/os/mac/system_config.rb', line 40

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

.core_tap_headObject


39
40
41
# File '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 '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 '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 '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 '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 '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 '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 '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 '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


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
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
# File 'Library/Homebrew/system_config.rb', line 170

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
  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


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
# File '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
  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


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


75
76
77
78
79
# File '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 '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 '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 '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 'Library/Homebrew/system_config.rb', line 81

def kernel
  `uname -m`.chomp
end

.last_commitObject


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

def last_commit
  HOMEBREW_REPOSITORY.git_last_commit || "never"
end

.originObject


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

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

.xcodeObject


32
33
34
35
36
37
38
# File '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


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

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