Class: SystemConfig

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



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

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

.clang_buildObject



33
34
35
36
37
38
39
# File 'Library/Homebrew/system_config.rb', line 33

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

.cltObject



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

def clt
  if instance_variable_defined?(:@clt)
    @clt
  elsif MacOS::CLT.installed? && MacOS::Xcode.version >= "4.3"
    @clt = MacOS::CLT.version
  end
end

.core_tap_headObject



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

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

.core_tap_last_commitObject



57
58
59
# File 'Library/Homebrew/system_config.rb', line 57

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

.core_tap_originObject



61
62
63
# File 'Library/Homebrew/system_config.rb', line 61

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

.describe_gitObject



139
140
141
142
# File 'Library/Homebrew/system_config.rb', line 139

def describe_git
  return "N/A" unless Utils.git_available?
  "#{Utils.git_version} => #{Utils.git_path}"
end

.describe_homebrew_rubyObject



113
114
115
# File 'Library/Homebrew/system_config.rb', line 113

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

.describe_homebrew_ruby_versionObject



104
105
106
107
108
109
110
111
# File 'Library/Homebrew/system_config.rb', line 104

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



126
127
128
129
130
131
132
133
134
135
136
137
# File 'Library/Homebrew/system_config.rb', line 126

def describe_java
  # java_home doesn't exist on all macOSs; it might be missing on older versions.
  return "N/A" unless File.executable? "/usr/libexec/java_home"

  java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast")
  return "N/A" unless $?.success?
  javas = []
  REXML::XPath.each(REXML::Document.new(java_xml), "//key[text()='JVMVersion']/following-sibling::string") do |item|
    javas << item.text
  end
  javas.uniq.join(", ")
end

.describe_path(path) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'Library/Homebrew/system_config.rb', line 65

def describe_path(path)
  return "N/A" if path.nil?
  realpath = path.realpath
  if realpath == path
    path
  else
    "#{path} => #{realpath}"
  end
end

.describe_perlObject



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

def describe_perl
  describe_path(which("perl"))
end

.describe_pythonObject



79
80
81
82
83
84
85
86
87
88
89
# File 'Library/Homebrew/system_config.rb', line 79

def describe_python
  python = which "python"
  return "N/A" if python.nil?
  python_binary = Utils.popen_read python, "-c", "import sys; sys.stdout.write(sys.executable)"
  python_binary = Pathname.new(python_binary).realpath
  if python == python_binary
    python
  else
    "#{python} => #{python_binary}"
  end
end

.describe_rubyObject



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

def describe_ruby
  ruby = which "ruby"
  return "N/A" if ruby.nil?
  ruby_binary = Utils.popen_read ruby, "-rrbconfig", "-e", \
    'include RbConfig;print"#{CONFIG["bindir"]}/#{CONFIG["ruby_install_name"]}#{CONFIG["EXEEXT"]}"'
  ruby_binary = Pathname.new(ruby_binary).realpath
  if ruby == ruby_binary
    ruby
  else
    "#{ruby} => #{ruby_binary}"
  end
end

.describe_xquartzObject



26
27
28
29
# File 'Library/Homebrew/extend/os/mac/system_config.rb', line 26

def describe_xquartz
  return "N/A" unless MacOS::XQuartz.installed?
  "#{MacOS::XQuartz.version} => #{describe_path(MacOS::XQuartz.prefix)}"
end

.dump_generic_verbose_configObject



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

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}"
  f.puts "HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY}"
  f.puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}"
  f.puts "HOMEBREW_BOTTLE_DOMAIN: #{BottleSpecification::DEFAULT_DOMAIN}"
  f.puts hardware if hardware
  f.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
  f.puts "GCC-4.0: build #{gcc_4_0}" unless gcc_4_0.null?
  f.puts "GCC-4.2: build #{gcc_4_2}" unless gcc_4_2.null?
  f.puts "Clang: #{clang.null? ? "N/A" : "#{clang} build #{clang_build}"}"
  f.puts "Git: #{describe_git}"
  f.puts "Perl: #{describe_perl}"
  f.puts "Python: #{describe_python}"
  f.puts "Ruby: #{describe_ruby}"
  f.puts "Java: #{describe_java}"
end

.dump_verbose_config(out = $stdout) ⇒ Object



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

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}"
  f.puts "HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY}"
  f.puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}"
  f.puts "HOMEBREW_BOTTLE_DOMAIN: #{BottleSpecification::DEFAULT_DOMAIN}"
  f.puts hardware if hardware
  f.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
  f.puts "GCC-4.0: build #{gcc_4_0}" unless gcc_4_0.null?
  f.puts "GCC-4.2: build #{gcc_4_2}" unless gcc_4_2.null?
  f.puts "Clang: #{clang.null? ? "N/A" : "#{clang} build #{clang_build}"}"
  f.puts "Git: #{describe_git}"
  f.puts "Perl: #{describe_perl}"
  f.puts "Python: #{describe_python}"
  f.puts "Ruby: #{describe_ruby}"
  f.puts "Java: #{describe_java}"
end

.formula_version(formula) ⇒ Object



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

def formula_version(formula)
  return "N/A" unless CoreTap.instance.installed?
  f = Formulary.factory formula
  return "N/A" unless f.installed?
  f.version
rescue FormulaUnavailableError
  return "N/A"
end

.gcc_4_0Object



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

def gcc_4_0
  @gcc_4_0 ||= if DevelopmentTools.installed?
    DevelopmentTools.gcc_4_0_build_version
  else
    Version::NULL
  end
end

.gcc_4_2Object



9
10
11
12
13
14
15
# File 'Library/Homebrew/system_config.rb', line 9

def gcc_4_2
  @gcc_4_2 ||= if DevelopmentTools.installed?
    DevelopmentTools.gcc_4_2_build_version
  else
    Version::NULL
  end
end

.hardwareObject



117
118
119
120
# File 'Library/Homebrew/system_config.rb', line 117

def hardware
  return if Hardware::CPU.type == :dunno
  "CPU: #{Hardware.cores_as_words}-core #{Hardware::CPU.bits}-bit #{Hardware::CPU.family}"
end

.headObject



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

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

.host_gcc_versionObject



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

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_os_versionObject



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

def host_os_version
  if which("lsb_release")
    description = `lsb_release -d`.chomp.sub("Description:\t", "")
    codename = `lsb_release -c`.chomp.sub("Codename:\t", "")
    "#{description} (#{codename})"
  elsif (redhat_release = Pathname.new("/etc/redhat-release")).readable?
    redhat_release.read.chomp
  else
    "N/A"
  end
end

.kernelObject



122
123
124
# File 'Library/Homebrew/system_config.rb', line 122

def kernel
  `uname -m`.chomp
end

.last_commitObject



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

def last_commit
  HOMEBREW_REPOSITORY.git_last_commit || "never"
end

.macports_or_finkObject



21
22
23
24
# File 'Library/Homebrew/extend/os/mac/system_config.rb', line 21

def macports_or_fink
  @ponk ||= MacOS.macports_or_fink
  @ponk.join(", ") unless @ponk.empty?
end

.originObject



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

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

.xcodeObject



3
4
5
6
7
8
9
10
11
# File 'Library/Homebrew/extend/os/mac/system_config.rb', line 3

def xcode
  if instance_variable_defined?(:@xcode)
    @xcode
  elsif MacOS::Xcode.installed?
    @xcode = MacOS::Xcode.version
    @xcode += " => #{MacOS::Xcode.prefix}" unless MacOS::Xcode.default_prefix?
    @xcode
  end
end