| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  | require "hardware" | 
					
						
							|  |  |  | require "software_spec" | 
					
						
							|  |  |  | require "rexml/document" | 
					
						
							|  |  |  | require "tap" | 
					
						
							|  |  |  | require "development_tools" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SystemConfig | 
					
						
							|  |  |  |   class << self | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |     def gcc_4_2 | 
					
						
							| 
									
										
										
										
											2017-02-26 01:24:53 +03:00
										 |  |  |       @gcc_4_2 ||= if DevelopmentTools.installed? | 
					
						
							|  |  |  |         DevelopmentTools.gcc_4_2_build_version | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |     def gcc_4_0 | 
					
						
							| 
									
										
										
										
											2017-02-26 01:24:53 +03:00
										 |  |  |       @gcc_4_0 ||= if DevelopmentTools.installed? | 
					
						
							|  |  |  |         DevelopmentTools.gcc_4_0_build_version | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clang | 
					
						
							| 
									
										
										
										
											2017-02-26 01:24:53 +03:00
										 |  |  |       @clang ||= if DevelopmentTools.installed? | 
					
						
							|  |  |  |         DevelopmentTools.clang_version | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clang_build | 
					
						
							| 
									
										
										
										
											2017-02-26 01:24:53 +03:00
										 |  |  |       @clang_build ||= if DevelopmentTools.installed? | 
					
						
							|  |  |  |         DevelopmentTools.clang_build_version | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def head | 
					
						
							| 
									
										
										
										
											2016-07-02 09:44:48 +02:00
										 |  |  |       HOMEBREW_REPOSITORY.git_head || "(none)" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def last_commit | 
					
						
							| 
									
										
										
										
											2016-07-02 09:44:48 +02:00
										 |  |  |       HOMEBREW_REPOSITORY.git_last_commit || "never" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def origin | 
					
						
							| 
									
										
										
										
											2016-07-02 09:44:48 +02:00
										 |  |  |       HOMEBREW_REPOSITORY.git_origin || "(none)" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def core_tap_head | 
					
						
							|  |  |  |       CoreTap.instance.git_head || "(none)" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def core_tap_last_commit | 
					
						
							|  |  |  |       CoreTap.instance.git_last_commit || "never" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def core_tap_origin | 
					
						
							|  |  |  |       CoreTap.instance.remote || "(none)" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_path(path) | 
					
						
							|  |  |  |       return "N/A" if path.nil? | 
					
						
							|  |  |  |       realpath = path.realpath | 
					
						
							|  |  |  |       if realpath == path | 
					
						
							|  |  |  |         path | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         "#{path} => #{realpath}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_perl | 
					
						
							| 
									
										
										
										
											2017-10-28 20:38:00 +01:00
										 |  |  |       describe_path(which("perl", ENV["HOMEBREW_PATH"])) | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_python | 
					
						
							| 
									
										
										
										
											2017-07-21 17:31:35 +01:00
										 |  |  |       python = begin | 
					
						
							|  |  |  |         python_path = PATH.new(ENV["HOMEBREW_PATH"]) | 
					
						
							|  |  |  |                           .prepend(Formula["python"].opt_libexec/"bin") | 
					
						
							|  |  |  |         which "python", python_path | 
					
						
							|  |  |  |       rescue FormulaUnavailableError | 
					
						
							|  |  |  |         which "python" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_ruby | 
					
						
							| 
									
										
										
										
											2017-10-28 20:38:00 +01:00
										 |  |  |       ruby = which "ruby", ENV["HOMEBREW_PATH"] | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 22:32:46 +08:00
										 |  |  |     def describe_homebrew_ruby_version | 
					
						
							|  |  |  |       case RUBY_VERSION | 
					
						
							|  |  |  |       when /^1\.[89]/, /^2\.0/ | 
					
						
							|  |  |  |         "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         RUBY_VERSION | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_homebrew_ruby | 
					
						
							|  |  |  |       "#{describe_homebrew_ruby_version} => #{RUBY_PATH}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def hardware | 
					
						
							|  |  |  |       return if Hardware::CPU.type == :dunno | 
					
						
							|  |  |  |       "CPU: #{Hardware.cores_as_words}-core #{Hardware::CPU.bits}-bit #{Hardware::CPU.family}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def kernel | 
					
						
							|  |  |  |       `uname -m`.chomp | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_java | 
					
						
							| 
									
										
										
										
											2016-09-18 19:57:19 +01:00
										 |  |  |       # java_home doesn't exist on all macOSs; it might be missing on older versions. | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       return "N/A" unless File.executable? "/usr/libexec/java_home" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-20 12:03:45 -07:00
										 |  |  |       java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast", err: :close) | 
					
						
							| 
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 |  |  |       return "N/A" unless $CHILD_STATUS.success? | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 02:54:57 +02:00
										 |  |  |     def describe_git | 
					
						
							|  |  |  |       return "N/A" unless Utils.git_available? | 
					
						
							|  |  |  |       "#{Utils.git_version} => #{Utils.git_path}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |     def describe_curl | 
					
						
							|  |  |  |       curl_version_output = Utils.popen_read("#{curl_executable} --version", err: :close) | 
					
						
							|  |  |  |       curl_version_output =~ /^curl ([\d\.]+)/ | 
					
						
							|  |  |  |       curl_version = Regexp.last_match(1) | 
					
						
							|  |  |  |       "#{curl_version} => #{curl_executable}" | 
					
						
							|  |  |  |     rescue | 
					
						
							|  |  |  |       "N/A" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       defaults_hash = { | 
					
						
							|  |  |  |         HOMEBREW_PREFIX: "/usr/local", | 
					
						
							|  |  |  |         HOMEBREW_REPOSITORY: "/usr/local/Homebrew", | 
					
						
							|  |  |  |         HOMEBREW_CELLAR: "/usr/local/Cellar", | 
					
						
							|  |  |  |         HOMEBREW_CACHE: "#{ENV["HOME"]}/Library/Caches/Homebrew", | 
					
						
							|  |  |  |       }.freeze | 
					
						
							|  |  |  |       boring_keys = %w[
 | 
					
						
							|  |  |  |         HOMEBREW_BROWSER | 
					
						
							|  |  |  |         HOMEBREW_EDITOR | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         HOMEBREW_ANALYTICS_ID | 
					
						
							|  |  |  |         HOMEBREW_ANALYTICS_USER_UUID | 
					
						
							| 
									
										
										
										
											2017-11-07 08:01:51 +00:00
										 |  |  |         HOMEBREW_AUTO_UPDATE_CHECKED | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |         HOMEBREW_BREW_FILE | 
					
						
							|  |  |  |         HOMEBREW_COMMAND_DEPTH | 
					
						
							|  |  |  |         HOMEBREW_CURL | 
					
						
							| 
									
										
										
										
											2017-11-27 10:15:26 +00:00
										 |  |  |         HOMEBREW_GIT_CONFIG_FILE | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |         HOMEBREW_LIBRARY | 
					
						
							|  |  |  |         HOMEBREW_MACOS_VERSION | 
					
						
							|  |  |  |         HOMEBREW_RUBY_PATH | 
					
						
							|  |  |  |         HOMEBREW_SYSTEM | 
					
						
							|  |  |  |         HOMEBREW_OS_VERSION | 
					
						
							|  |  |  |         HOMEBREW_PATH | 
					
						
							|  |  |  |         HOMEBREW_PROCESSOR | 
					
						
							|  |  |  |         HOMEBREW_PRODUCT | 
					
						
							|  |  |  |         HOMEBREW_USER_AGENT | 
					
						
							|  |  |  |         HOMEBREW_USER_AGENT_CURL | 
					
						
							|  |  |  |         HOMEBREW_VERSION | 
					
						
							|  |  |  |       ].freeze | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       f.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}" | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       if defaults_hash[:HOMEBREW_REPOSITORY] != HOMEBREW_REPOSITORY.to_s | 
					
						
							|  |  |  |         f.puts "HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       if defaults_hash[:HOMEBREW_CELLAR] != HOMEBREW_CELLAR.to_s | 
					
						
							|  |  |  |         f.puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       ENV.sort.each do |key, value| | 
					
						
							|  |  |  |         next unless key.start_with?("HOMEBREW_") | 
					
						
							|  |  |  |         next if boring_keys.include?(key) | 
					
						
							|  |  |  |         next if defaults_hash[key.to_sym] == value | 
					
						
							| 
									
										
										
										
											2017-11-07 07:47:50 +00:00
										 |  |  |         value = "set" if key =~ /(cookie|key|token|password)/i | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |         f.puts "#{key}: #{value}" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       f.puts hardware if hardware | 
					
						
							| 
									
										
										
										
											2016-07-11 22:32:46 +08:00
										 |  |  |       f.puts "Homebrew Ruby: #{describe_homebrew_ruby}" | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |       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? | 
					
						
							| 
									
										
										
										
											2016-11-03 16:52:58 -07:00
										 |  |  |       f.puts "Clang: #{clang.null? ? "N/A" : "#{clang} build #{clang_build}"}" | 
					
						
							| 
									
										
										
										
											2016-06-13 02:54:57 +02:00
										 |  |  |       f.puts "Git: #{describe_git}" | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |       f.puts "Curl: #{describe_curl}" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       f.puts "Perl: #{describe_perl}" | 
					
						
							|  |  |  |       f.puts "Python: #{describe_python}" | 
					
						
							|  |  |  |       f.puts "Ruby: #{describe_ruby}" | 
					
						
							|  |  |  |       f.puts "Java: #{describe_java}" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |     alias dump_generic_verbose_config dump_verbose_config | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/system_config" |