| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  | require "exceptions" | 
					
						
							| 
									
										
										
										
											2020-06-23 14:11:05 +01:00
										 |  |  | require "hardware" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "version" | 
					
						
							| 
									
										
										
										
											2013-02-06 22:49:43 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							| 
									
										
										
										
											2020-08-25 00:35:07 +02:00
										 |  |  |     # A macOS version. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api private | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |     class Version < ::Version | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |       extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |       sig { params(version: Symbol).returns(T.attached_class) } | 
					
						
							|  |  |  |       def self.from_symbol(version) | 
					
						
							| 
									
										
										
										
											2022-06-29 11:29:46 -04:00
										 |  |  |         str = MacOSVersions::SYMBOLS.fetch(version) { raise MacOSVersionError, version } | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |         new(str) | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-06-15 19:39:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |       sig { params(value: T.nilable(String)).void } | 
					
						
							|  |  |  |       def initialize(value) | 
					
						
							| 
									
										
										
										
											2020-12-09 11:55:27 +00:00
										 |  |  |         version ||= value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         raise MacOSVersionError, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version) | 
					
						
							| 
									
										
										
										
											2020-10-05 14:46:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-09 11:55:27 +00:00
										 |  |  |         super(version) | 
					
						
							| 
									
										
										
										
											2020-10-05 14:46:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-02 20:29:20 -05:00
										 |  |  |         @comparison_cache = {} | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-20 10:32:34 -08:00
										 |  |  |       sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def <=>(other) | 
					
						
							| 
									
										
										
										
											2014-04-02 20:29:20 -05:00
										 |  |  |         @comparison_cache.fetch(other) do | 
					
						
							| 
									
										
										
										
											2022-06-29 11:29:46 -04:00
										 |  |  |           if MacOSVersions::SYMBOLS.key?(other) && to_sym == other | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |             0
 | 
					
						
							|  |  |  |           else | 
					
						
							| 
									
										
										
										
											2022-06-29 11:29:46 -04:00
										 |  |  |             v = MacOSVersions::SYMBOLS.fetch(other) { other.to_s } | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |             @comparison_cache[other] = super(::Version.new(v)) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-04-02 20:29:20 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-06-14 11:56:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 18:34:47 +00:00
										 |  |  |       sig { returns(T.self_type) } | 
					
						
							|  |  |  |       def strip_patch | 
					
						
							|  |  |  |         # Big Sur is 11.x but Catalina is 10.15.x. | 
					
						
							| 
									
										
										
										
											2023-03-18 16:03:25 -07:00
										 |  |  |         if T.must(major) >= 11
 | 
					
						
							| 
									
										
										
										
											2021-02-09 18:34:47 +00:00
										 |  |  |           self.class.new(major.to_s) | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           major_minor | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |       sig { returns(Symbol) } | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def to_sym | 
					
						
							| 
									
										
										
										
											2022-06-29 11:29:46 -04:00
										 |  |  |         @to_sym ||= MacOSVersions::SYMBOLS.invert.fetch(strip_patch.to_s, :dunno) | 
					
						
							| 
									
										
										
										
											2013-06-14 14:47:16 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-06-15 19:40:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |       sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def pretty_name | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |         @pretty_name ||= to_sym.to_s.split("_").map(&:capitalize).join(" ").freeze | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-01-28 19:31:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 13:06:46 -04:00
										 |  |  |       sig { returns(T::Boolean) } | 
					
						
							|  |  |  |       def outdated_release? | 
					
						
							| 
									
										
										
										
											2023-02-24 13:25:18 +00:00
										 |  |  |         self < HOMEBREW_MACOS_OLDEST_SUPPORTED | 
					
						
							| 
									
										
										
										
											2021-06-22 13:06:46 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sig { returns(T::Boolean) } | 
					
						
							|  |  |  |       def prerelease? | 
					
						
							| 
									
										
										
										
											2023-02-24 13:25:18 +00:00
										 |  |  |         self >= HOMEBREW_MACOS_NEWEST_UNSUPPORTED | 
					
						
							| 
									
										
										
										
											2021-06-22 13:06:46 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  |       # For {OS::Mac::Version} compatibility. | 
					
						
							| 
									
										
										
										
											2020-11-23 10:14:18 +01:00
										 |  |  |       sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2019-01-28 19:31:21 +00:00
										 |  |  |       def requires_nehalem_cpu? | 
					
						
							| 
									
										
										
										
											2020-07-08 20:53:10 +02:00
										 |  |  |         unless Hardware::CPU.intel? | 
					
						
							|  |  |  |           raise "Unexpected architecture: #{Hardware::CPU.arch}. This only works with Intel architecture." | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-28 19:31:21 +00:00
										 |  |  |         Hardware.oldest_cpu(self) == :nehalem | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       # https://en.wikipedia.org/wiki/Nehalem_(microarchitecture) | 
					
						
							|  |  |  |       # Ensure any extra methods are also added to version/null.rb | 
					
						
							|  |  |  |       alias requires_sse4? requires_nehalem_cpu? | 
					
						
							|  |  |  |       alias requires_sse41? requires_nehalem_cpu? | 
					
						
							|  |  |  |       alias requires_sse42? requires_nehalem_cpu? | 
					
						
							|  |  |  |       alias requires_popcnt? requires_nehalem_cpu? | 
					
						
							| 
									
										
										
										
											2013-06-15 19:40:42 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-02-06 22:49:43 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | end |