| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "requirement" | 
					
						
							| 
									
										
										
										
											2013-05-24 08:37:16 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 10:12:09 -07:00
										 |  |  | class MacOSRequirement < Requirement | 
					
						
							| 
									
										
										
										
											2013-05-24 08:37:16 -07:00
										 |  |  |   fatal true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 16:29:49 -05:00
										 |  |  |   attr_reader :comparator, :version | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |   def initialize(tags = [], comparator: ">=") | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |     if comparator == "==" && tags.first.respond_to?(:map) | 
					
						
							|  |  |  |       @version = tags.shift.map { |s| MacOS::Version.from_symbol(s) } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       @version = MacOS::Version.from_symbol(tags.shift) unless tags.empty? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |     @comparator = comparator | 
					
						
							| 
									
										
										
										
											2018-10-19 16:38:41 +01:00
										 |  |  |     super(tags) | 
					
						
							| 
									
										
										
										
											2013-05-24 08:37:16 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |   def version_specified? | 
					
						
							| 
									
										
										
										
											2017-02-25 10:17:25 -08:00
										 |  |  |     OS.mac? && @version | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   satisfy(build_env: false) do | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |     next [*@version].any? { |v| MacOS.version.public_send(@comparator, v) } if version_specified? | 
					
						
							| 
									
										
										
										
											2017-02-25 10:17:25 -08:00
										 |  |  |     next true if OS.mac? | 
					
						
							|  |  |  |     next true if @version | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-25 10:17:25 -08:00
										 |  |  |     false | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-05-24 08:37:16 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |   def message(type: :formula) | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |     return "macOS is required." unless version_specified? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case @comparator | 
					
						
							|  |  |  |     when ">=" | 
					
						
							|  |  |  |       "macOS #{@version.pretty_name} or newer is required." | 
					
						
							|  |  |  |     when "<=" | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |       case type | 
					
						
							|  |  |  |       when :formula | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							|  |  |  |           This formula either does not compile or function as expected on macOS | 
					
						
							|  |  |  |           versions newer than #{@version.pretty_name} due to an upstream incompatibility. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       when :cask | 
					
						
							| 
									
										
										
										
											2019-08-30 14:11:13 -04:00
										 |  |  |         "This cask does not run on macOS versions newer than #{@version.pretty_name}." | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |       if @version.respond_to?(:to_ary) | 
					
						
							| 
									
										
										
										
											2019-08-30 14:11:13 -04:00
										 |  |  |         *versions, last = @version.map(&:pretty_name) | 
					
						
							| 
									
										
										
										
											2019-08-15 10:14:10 +02:00
										 |  |  |         return "macOS #{versions.join(", ")} or #{last} is required." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |       "macOS #{@version.pretty_name} is required." | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-24 08:37:16 -07:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-09-18 00:37:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 16:29:49 -05:00
										 |  |  |   def inspect | 
					
						
							|  |  |  |     "#<#{self.class.name}: #{tags.inspect} version#{@comparator}#{@version}>" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 00:37:02 -04:00
										 |  |  |   def display_s | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |     return "macOS is required" unless version_specified? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 07:53:28 +02:00
										 |  |  |     "macOS #{@comparator} #{@version}" | 
					
						
							| 
									
										
										
										
											2016-09-18 00:37:02 -04:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-08-30 14:11:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def to_json(*args) | 
					
						
							|  |  |  |     comp = @comparator.to_s | 
					
						
							|  |  |  |     return { comp => @version.map(&:to_s) }.to_json(*args) if @version.is_a?(Array) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { comp => [@version.to_s] }.to_json(*args) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-05-24 08:37:16 -07:00
										 |  |  | end |