| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  | require "hardware" | 
					
						
							|  |  |  | require "software_spec" | 
					
						
							|  |  |  | require "rexml/document" | 
					
						
							|  |  |  | require "development_tools" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SystemConfig | 
					
						
							|  |  |  |   class << self | 
					
						
							|  |  |  |     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? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       realpath = path.realpath | 
					
						
							|  |  |  |       if realpath == path | 
					
						
							|  |  |  |         path | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         "#{path} => #{realpath}" | 
					
						
							|  |  |  |       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 | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       "CPU: #{Hardware.cores_as_words}-core #{Hardware::CPU.bits}-bit #{Hardware::CPU.family}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def kernel | 
					
						
							|  |  |  |       `uname -m`.chomp | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def describe_java | 
					
						
							| 
									
										
										
										
											2018-02-22 14:20:23 +00:00
										 |  |  |       return "N/A" unless which "java" | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  |       _, err, status = system_command("java", args: ["-version"], print_stderr: false) | 
					
						
							|  |  |  |       return "N/A" unless status.success? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  |       err[/java version "([\d\._]+)"/, 1] || "N/A" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 02:54:57 +02:00
										 |  |  |     def describe_git | 
					
						
							|  |  |  |       return "N/A" unless Utils.git_available? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 02:54:57 +02:00
										 |  |  |       "#{Utils.git_version} => #{Utils.git_path}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |     def describe_curl | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  |       out, = system_command(curl_executable, args: ["--version"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if /^curl (?<curl_version>[\d\.]+)/ =~ out | 
					
						
							|  |  |  |         "#{curl_version} => #{curl_executable}" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         "N/A" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |     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 = { | 
					
						
							| 
									
										
										
										
											2018-11-02 17:18:07 +00:00
										 |  |  |         HOMEBREW_PREFIX:        Homebrew::DEFAULT_PREFIX, | 
					
						
							|  |  |  |         HOMEBREW_REPOSITORY:    Homebrew::DEFAULT_REPOSITORY, | 
					
						
							|  |  |  |         HOMEBREW_CELLAR:        Homebrew::DEFAULT_CELLAR, | 
					
						
							|  |  |  |         HOMEBREW_CACHE:         "#{ENV["HOME"]}/Library/Caches/Homebrew", | 
					
						
							| 
									
										
										
										
											2019-04-17 17:02:33 +09:00
										 |  |  |         HOMEBREW_LOGS:          "#{ENV["HOME"]}/Library/Logs/Homebrew", | 
					
						
							| 
									
										
										
										
											2018-11-02 17:18:07 +00:00
										 |  |  |         HOMEBREW_TEMP:          ENV["HOMEBREW_SYSTEM_TEMP"], | 
					
						
							| 
									
										
										
										
											2018-09-23 19:43:30 +01:00
										 |  |  |         HOMEBREW_RUBY_WARNINGS: "-W0", | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       }.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 | 
					
						
							| 
									
										
										
										
											2018-06-29 19:51:18 +01:00
										 |  |  |         HOMEBREW_BOTTLE_DEFAULT_DOMAIN | 
					
						
							|  |  |  |         HOMEBREW_BOTTLE_DOMAIN | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |         HOMEBREW_BREW_FILE | 
					
						
							|  |  |  |         HOMEBREW_COMMAND_DEPTH | 
					
						
							|  |  |  |         HOMEBREW_CURL | 
					
						
							| 
									
										
										
										
											2019-04-20 16:22:10 +09:00
										 |  |  |         HOMEBREW_DISPLAY | 
					
						
							| 
									
										
										
										
											2018-10-25 01:17:22 -04:00
										 |  |  |         HOMEBREW_GIT | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-23 12:59:03 +10:00
										 |  |  |         HOMEBREW_MACOS_VERSION_NUMERIC | 
					
						
							| 
									
										
										
										
											2018-10-27 20:44:13 -04:00
										 |  |  |         HOMEBREW_MINIMUM_GIT_VERSION | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |         HOMEBREW_RUBY_PATH | 
					
						
							|  |  |  |         HOMEBREW_SYSTEM | 
					
						
							| 
									
										
										
										
											2018-07-03 15:41:33 +01:00
										 |  |  |         HOMEBREW_SYSTEM_TEMP | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |         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}" | 
					
						
							| 
									
										
										
										
											2019-04-17 17:02:33 +09:00
										 |  |  |       [: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 | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |       if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s | 
					
						
							|  |  |  |         f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-04-02 09:29:14 +01:00
										 |  |  |       unless ENV["HOMEBREW_ENV"] | 
					
						
							|  |  |  |         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] | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-02 09:29:14 +01:00
										 |  |  |           value = "set" if key =~ /(cookie|key|token|password)/i | 
					
						
							|  |  |  |           f.puts "#{key}: #{value}" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       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}" | 
					
						
							| 
									
										
										
										
											2018-03-17 18:03:19 -07:00
										 |  |  |       f.print "Clang: " | 
					
						
							|  |  |  |       if clang.null? | 
					
						
							| 
									
										
										
										
											2018-03-22 08:26:26 +00:00
										 |  |  |         f.puts "N/A" | 
					
						
							| 
									
										
										
										
											2018-03-17 18:03:19 -07:00
										 |  |  |       else | 
					
						
							|  |  |  |         f.print "#{clang} build " | 
					
						
							|  |  |  |         if clang_build.null? | 
					
						
							| 
									
										
										
										
											2018-03-22 08:26:26 +00:00
										 |  |  |           f.puts "(parse error)" | 
					
						
							| 
									
										
										
										
											2018-03-17 18:03:19 -07:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2018-03-22 08:26:26 +00:00
										 |  |  |           f.puts clang_build | 
					
						
							| 
									
										
										
										
											2018-03-17 18:03:19 -07:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											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}" | 
					
						
							| 
									
										
										
										
											2018-09-30 10:50:37 +01:00
										 |  |  |       f.puts "Java: #{describe_java}" if describe_java != "N/A" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     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" |