| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-27 08:18:12 +00:00
										 |  |  | require "utils" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  | module OS | 
					
						
							| 
									
										
										
										
											2020-08-26 03:06:19 +02:00
										 |  |  |   # Helper module for querying system information on Linux. | 
					
						
							| 
									
										
										
										
											2019-09-13 16:48:12 +01:00
										 |  |  |   module Linux | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.os_version | 
					
						
							| 
									
										
										
										
											2019-09-13 16:48:12 +01:00
										 |  |  |       if which("lsb_release") | 
					
						
							| 
									
										
										
										
											2021-03-17 15:34:20 +00:00
										 |  |  |         lsb_info = Utils.popen_read("lsb_release", "-a") | 
					
						
							| 
									
										
										
										
											2022-01-09 21:12:52 -05:00
										 |  |  |         description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8") | 
					
						
							| 
									
										
										
										
											2020-11-30 14:41:02 -06:00
										 |  |  |         codename = lsb_info[/^Codename:\s*(.*)$/, 1] | 
					
						
							| 
									
										
										
										
											2020-12-02 11:54:59 +00:00
										 |  |  |         if codename.blank? || (codename == "n/a") | 
					
						
							| 
									
										
										
										
											2020-11-30 14:41:02 -06:00
										 |  |  |           description | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           "#{description} (#{codename})" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-09-13 16:48:12 +01:00
										 |  |  |       elsif (redhat_release = Pathname.new("/etc/redhat-release")).readable? | 
					
						
							|  |  |  |         redhat_release.read.chomp | 
					
						
							| 
									
										
										
										
											2023-07-29 00:58:36 -04:00
										 |  |  |       elsif ::OS_VERSION.present? | 
					
						
							| 
									
										
										
										
											2023-07-29 00:41:13 -04:00
										 |  |  |         ::OS_VERSION | 
					
						
							| 
									
										
										
										
											2019-09-13 16:48:12 +01:00
										 |  |  |       else | 
					
						
							|  |  |  |         "Unknown" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-02-27 08:18:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.wsl? | 
					
						
							| 
									
										
										
										
											2023-02-27 08:18:12 +00:00
										 |  |  |       /-microsoft/i.match?(OS.kernel_version.to_s) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(Version) } | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.wsl_version | 
					
						
							| 
									
										
										
										
											2023-02-27 10:17:50 -06:00
										 |  |  |       return Version::NULL unless wsl? | 
					
						
							| 
									
										
										
										
											2023-02-27 08:18:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-27 10:17:50 -06:00
										 |  |  |       kernel = OS.kernel_version.to_s | 
					
						
							|  |  |  |       if Version.new(T.must(kernel[/^([0-9.]*)-.*/, 1])) > Version.new("5.15") | 
					
						
							|  |  |  |         Version.new("2 (Microsoft Store)") | 
					
						
							|  |  |  |       elsif kernel.include?("-microsoft") | 
					
						
							|  |  |  |         Version.new("2") | 
					
						
							|  |  |  |       elsif kernel.include?("-Microsoft") | 
					
						
							|  |  |  |         Version.new("1") | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-02-27 08:18:12 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-09-13 16:48:12 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 03:06:19 +02:00
										 |  |  |   # rubocop:disable Style/Documentation | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |   module Mac | 
					
						
							| 
									
										
										
										
											2022-06-29 11:47:57 -04:00
										 |  |  |     ::MacOS = OS::Mac | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-13 23:38:48 -07:00
										 |  |  |     raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.version | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.version` on Linux" | 
					
						
							| 
									
										
										
										
											2023-05-09 02:15:28 +02:00
										 |  |  |       MacOSVersion::NULL | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.full_version | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.full_version` on Linux" | 
					
						
							| 
									
										
										
										
											2023-05-09 02:15:28 +02:00
										 |  |  |       MacOSVersion::NULL | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.languages | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.languages` on Linux" | 
					
						
							| 
									
										
										
										
											2020-07-13 22:48:53 +10:00
										 |  |  |       @languages ||= Array(ENV["LANG"]&.slice(/[a-z]+/)).uniq | 
					
						
							| 
									
										
										
										
											2019-03-26 17:14:12 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.language | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.language` on Linux" | 
					
						
							| 
									
										
										
										
											2019-03-26 17:14:12 -04:00
										 |  |  |       languages.first | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.sdk_root_needed? | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.sdk_root_needed?` on Linux" | 
					
						
							| 
									
										
										
										
											2020-04-07 16:43:59 +01:00
										 |  |  |       false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.sdk_path_if_needed(_version = nil) | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.sdk_path_if_needed` on Linux" | 
					
						
							| 
									
										
										
										
											2020-03-10 14:59:22 +01:00
										 |  |  |       nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |     def self.sdk_path(_version = nil) | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |       # odeprecated "`MacOS.sdk_path` on Linux" | 
					
						
							| 
									
										
										
										
											2020-08-17 16:13:28 +01:00
										 |  |  |       nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |     module Xcode | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |       def self.version | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |         # odeprecated "`MacOS::Xcode.version` on Linux" | 
					
						
							| 
									
										
										
										
											2021-09-11 00:10:24 +01:00
										 |  |  |         ::Version::NULL | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-09-01 12:49:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |       def self.installed? | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |         # odeprecated "`MacOS::Xcode.installed?` on Linux" | 
					
						
							| 
									
										
										
										
											2020-09-01 12:49:19 +01:00
										 |  |  |         false | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-04-30 16:07:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     module CLT | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |       def self.version | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |         # odeprecated "`MacOS::CLT.version` on Linux" | 
					
						
							| 
									
										
										
										
											2021-09-11 00:10:24 +01:00
										 |  |  |         ::Version::NULL | 
					
						
							| 
									
										
										
										
											2020-04-30 16:07:55 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-09-01 12:49:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |       def self.installed? | 
					
						
							| 
									
										
										
										
											2023-11-22 21:21:29 -05:00
										 |  |  |         # odeprecated "`MacOS::CLT.installed?` on Linux" | 
					
						
							| 
									
										
										
										
											2020-09-01 12:49:19 +01:00
										 |  |  |         false | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-04-30 16:07:55 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-08-26 03:06:19 +02:00
										 |  |  |   # rubocop:enable Style/Documentation | 
					
						
							| 
									
										
										
										
											2018-02-20 11:13:13 -08:00
										 |  |  | end |