| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											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 "development_tools" | 
					
						
							| 
									
										
										
										
											2019-07-13 22:48:22 +08:00
										 |  |  | require "extend/ENV" | 
					
						
							| 
									
										
										
										
											2020-10-10 17:53:31 +02:00
										 |  |  | require "system_command" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 07:35:50 +02:00
										 |  |  | # Helper module for querying information about the system configuration. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @api private | 
					
						
							|  |  |  | module SystemConfig | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |   class << self | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 17:53:31 +02:00
										 |  |  |     include SystemCommand::Mixin | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 16:07:47 +01:00
										 |  |  |     sig { returns(Pathname) } | 
					
						
							|  |  |  |     def homebrew_repo | 
					
						
							|  |  |  |       HOMEBREW_REPOSITORY.dup.extend(GitRepositoryExtension) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def head | 
					
						
							| 
									
										
										
										
											2021-05-12 16:07:47 +01:00
										 |  |  |       homebrew_repo.git_head || "(none)" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def last_commit | 
					
						
							| 
									
										
										
										
											2021-05-12 16:07:47 +01:00
										 |  |  |       homebrew_repo.git_last_commit || "never" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def origin | 
					
						
							| 
									
										
										
										
											2021-05-12 16:07:47 +01:00
										 |  |  |       homebrew_repo.git_origin || "(none)" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def core_tap_head | 
					
						
							|  |  |  |       CoreTap.instance.git_head || "(none)" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def core_tap_last_commit | 
					
						
							|  |  |  |       CoreTap.instance.git_last_commit || "never" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2020-08-02 00:09:52 -04:00
										 |  |  |     def core_tap_branch | 
					
						
							|  |  |  |       CoreTap.instance.git_branch || "(none)" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def core_tap_origin | 
					
						
							|  |  |  |       CoreTap.instance.remote || "(none)" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     def describe_clang | 
					
						
							|  |  |  |       return "N/A" if clang.null? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       clang_build_info = clang_build.null? ? "(parse error)" : clang_build | 
					
						
							|  |  |  |       "#{clang} build #{clang_build_info}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-07-11 22:32:46 +08:00
										 |  |  |     def describe_homebrew_ruby | 
					
						
							|  |  |  |       "#{describe_homebrew_ruby_version} => #{RUBY_PATH}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(T.nilable(String)) } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def kernel | 
					
						
							|  |  |  |       `uname -m`.chomp | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-06-13 02:54:57 +02:00
										 |  |  |     def describe_git | 
					
						
							| 
									
										
										
										
											2020-08-23 06:32:26 +02:00
										 |  |  |       return "N/A" unless Utils::Git.available? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-23 06:32:26 +02:00
										 |  |  |       "#{Utils::Git.version} => #{Utils::Git.path}" | 
					
						
							| 
									
										
										
										
											2016-06-13 02:54:57 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |     def describe_curl | 
					
						
							| 
									
										
										
										
											2021-02-09 20:58:30 +00:00
										 |  |  |       out, = system_command(curl_executable, args: ["--version"], verbose: false) | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 09:49:23 +01:00
										 |  |  |       if /^curl (?<curl_version>[\d.]+)/ =~ out | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  |         "#{curl_version} => #{curl_executable}" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         "N/A" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     def core_tap_config(f = $stdout) | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       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}" | 
					
						
							| 
									
										
										
										
											2020-08-02 00:09:52 -04:00
										 |  |  |         f.puts "Core tap branch: #{core_tap_branch}" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       else | 
					
						
							|  |  |  |         f.puts "Core tap: N/A" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def homebrew_config(f = $stdout) | 
					
						
							|  |  |  |       f.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}" | 
					
						
							|  |  |  |       f.puts "ORIGIN: #{origin}" | 
					
						
							|  |  |  |       f.puts "HEAD: #{head}" | 
					
						
							|  |  |  |       f.puts "Last commit: #{last_commit}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def homebrew_env_config(f = $stdout) | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       f.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}" | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |       { | 
					
						
							|  |  |  |         HOMEBREW_REPOSITORY: Homebrew::DEFAULT_REPOSITORY, | 
					
						
							|  |  |  |         HOMEBREW_CELLAR:     Homebrew::DEFAULT_CELLAR, | 
					
						
							|  |  |  |       }.freeze.each do |key, default| | 
					
						
							| 
									
										
										
										
											2019-04-17 17:02:33 +09:00
										 |  |  |         value = Object.const_get(key) | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |         f.puts "#{key}: #{value}" if value.to_s != default.to_s | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       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 | 
					
						
							| 
									
										
										
										
											2020-09-01 14:05:52 +01:00
										 |  |  |         next if (default = hash[:default].presence) && value.to_s == default.to_s | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ENV.sensitive?(env) | 
					
						
							|  |  |  |           f.puts "#{env}: set" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           f.puts "#{env}: #{value}" | 
					
						
							| 
									
										
										
										
											2018-04-02 09:29:14 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-07-11 22:32:46 +08:00
										 |  |  |       f.puts "Homebrew Ruby: #{describe_homebrew_ruby}" | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def host_software_config(f = $stdout) | 
					
						
							|  |  |  |       f.puts "Clang: #{describe_clang}" | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def dump_verbose_config(f = $stdout) | 
					
						
							|  |  |  |       homebrew_config(f) | 
					
						
							|  |  |  |       core_tap_config(f) | 
					
						
							|  |  |  |       homebrew_env_config(f) | 
					
						
							|  |  |  |       f.puts hardware if hardware | 
					
						
							|  |  |  |       host_software_config(f) | 
					
						
							|  |  |  |     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" |