| 
									
										
										
										
											2024-08-12 10:30:59 +01:00
										 |  |  | # typed: true # rubocop:todo Sorbet/StrictSigil | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2024-07-14 08:49:39 -04:00
										 |  |  | require "git_repository" | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							|  |  |  | module SystemConfig | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |   class << self | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-15 19:06:40 -07:00
										 |  |  |     sig { returns(GitRepository) } | 
					
						
							| 
									
										
										
										
											2021-05-12 16:07:47 +01:00
										 |  |  |     def homebrew_repo | 
					
						
							| 
									
										
										
										
											2023-04-15 19:06:40 -07:00
										 |  |  |       GitRepository.new(HOMEBREW_REPOSITORY) | 
					
						
							| 
									
										
										
										
											2021-05-12 16:07:47 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-24 11:58:12 +08:00
										 |  |  |     sig { returns(String) } | 
					
						
							|  |  |  |     def branch | 
					
						
							|  |  |  |       homebrew_repo.branch_name || "(none)" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     def head | 
					
						
							| 
									
										
										
										
											2023-04-15 16:46:13 -07:00
										 |  |  |       homebrew_repo.head_ref || "(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 | 
					
						
							| 
									
										
										
										
											2023-04-15 16:46:13 -07:00
										 |  |  |       homebrew_repo.last_committed || "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 | 
					
						
							| 
									
										
										
										
											2023-04-15 16:46:13 -07:00
										 |  |  |       homebrew_repo.origin_url || "(none)" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     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? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-07 11:24:20 +08:00
										 |  |  |       if clang_build.null? | 
					
						
							|  |  |  |         clang.to_s | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         "#{clang} build #{clang_build}" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2023-12-12 03:09:59 +00:00
										 |  |  |       "#{RUBY_VERSION} => #{RUBY_PATH}" | 
					
						
							| 
									
										
										
										
											2016-07-11 22:32:46 +08:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2023-09-04 22:17:57 -04:00
										 |  |  |       out, = system_command(Utils::Curl.curl_executable, args: ["--version"], verbose: false) | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-15 15:06:58 -07:00
										 |  |  |       match_data = /^curl (?<curl_version>[\d.]+)/.match(out) | 
					
						
							|  |  |  |       if match_data | 
					
						
							| 
									
										
										
										
											2023-09-04 22:17:57 -04:00
										 |  |  |         "#{match_data[:curl_version]} => #{Utils::Curl.curl_path}" | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  |       else | 
					
						
							|  |  |  |         "N/A" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-11-04 16:34:26 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 22:54:38 -08:00
										 |  |  |     def dump_tap_config(tap, out = $stdout) | 
					
						
							|  |  |  |       case tap | 
					
						
							|  |  |  |       when CoreTap | 
					
						
							|  |  |  |         tap_name = "Core tap" | 
					
						
							|  |  |  |         json_file_name = "formula.jws.json" | 
					
						
							|  |  |  |       when CoreCaskTap | 
					
						
							|  |  |  |         tap_name = "Core cask tap" | 
					
						
							|  |  |  |         json_file_name = "cask.jws.json" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         raise ArgumentError, "Unknown tap: #{tap}" | 
					
						
							| 
									
										
										
										
											2023-01-26 17:36:40 +00:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 22:54:38 -08:00
										 |  |  |       if tap.installed? | 
					
						
							| 
									
										
										
										
											2023-12-22 10:39:29 -08:00
										 |  |  |         out.puts "#{tap_name} origin: #{tap.remote}" if tap.remote != tap.default_remote | 
					
						
							| 
									
										
										
										
											2023-12-21 22:54:38 -08:00
										 |  |  |         out.puts "#{tap_name} HEAD: #{tap.git_head || "(none)"}" | 
					
						
							|  |  |  |         out.puts "#{tap_name} last commit: #{tap.git_last_commit || "never"}" | 
					
						
							| 
									
										
										
										
											2025-06-13 12:09:02 +01:00
										 |  |  |         default_branches = %w[main master].freeze | 
					
						
							|  |  |  |         out.puts "#{tap_name} branch: #{tap.git_branch || "(none)"}" if default_branches.exclude?(tap.git_branch) | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-12-21 22:54:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  |       json_file = Homebrew::API::HOMEBREW_CACHE_API/json_file_name | 
					
						
							|  |  |  |       if json_file.exist? | 
					
						
							| 
									
										
										
										
											2023-12-21 22:54:38 -08:00
										 |  |  |         out.puts "#{tap_name} JSON: #{json_file.mtime.utc.strftime("%d %b %H:%M UTC")}" | 
					
						
							|  |  |  |       elsif !tap.installed? | 
					
						
							|  |  |  |         out.puts "#{tap_name}: N/A" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def core_tap_config(out = $stdout) | 
					
						
							|  |  |  |       dump_tap_config(CoreTap.instance, out) | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     def homebrew_config(out = $stdout) | 
					
						
							|  |  |  |       out.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}" | 
					
						
							|  |  |  |       out.puts "ORIGIN: #{origin}" | 
					
						
							|  |  |  |       out.puts "HEAD: #{head}" | 
					
						
							|  |  |  |       out.puts "Last commit: #{last_commit}" | 
					
						
							| 
									
										
										
										
											2024-11-24 11:58:12 +08:00
										 |  |  |       out.puts "Branch: #{branch}" | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     def homebrew_env_config(out = $stdout) | 
					
						
							|  |  |  |       out.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) | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |         out.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] | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |           out.puts "#{env}: set" if Homebrew::EnvConfig.send(method_name) | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |           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) | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |           out.puts "#{env}: set" | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |           out.puts "#{env}: #{value}" | 
					
						
							| 
									
										
										
										
											2018-04-02 09:29:14 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-11-04 16:35:24 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |       out.puts "Homebrew Ruby: #{describe_homebrew_ruby}" | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     def host_software_config(out = $stdout) | 
					
						
							|  |  |  |       out.puts "Clang: #{describe_clang}" | 
					
						
							|  |  |  |       out.puts "Git: #{describe_git}" | 
					
						
							|  |  |  |       out.puts "Curl: #{describe_curl}" | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     def dump_verbose_config(out = $stdout) | 
					
						
							|  |  |  |       homebrew_config(out) | 
					
						
							|  |  |  |       core_tap_config(out) | 
					
						
							|  |  |  |       homebrew_env_config(out) | 
					
						
							|  |  |  |       out.puts hardware if hardware | 
					
						
							|  |  |  |       host_software_config(out) | 
					
						
							| 
									
										
										
										
											2020-09-04 18:12:55 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:15 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/system_config" |