| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  | # Helper module for handling `disable!` and `deprecate!`. | 
					
						
							| 
									
										
										
										
											2024-07-14 11:49:43 -04:00
										 |  |  | # @api internal | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  | module DeprecateDisable | 
					
						
							|  |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   FORMULA_DEPRECATE_DISABLE_REASONS = T.let({ | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  |     does_not_build:      "does not build", | 
					
						
							|  |  |  |     no_license:          "has no license", | 
					
						
							|  |  |  |     repo_archived:       "has an archived upstream repository", | 
					
						
							|  |  |  |     repo_removed:        "has a removed upstream repository", | 
					
						
							|  |  |  |     unmaintained:        "is not maintained upstream", | 
					
						
							|  |  |  |     unsupported:         "is not supported upstream", | 
					
						
							|  |  |  |     deprecated_upstream: "is deprecated upstream", | 
					
						
							|  |  |  |     versioned_formula:   "is a versioned formula", | 
					
						
							| 
									
										
										
										
											2022-06-28 10:09:59 +01:00
										 |  |  |     checksum_mismatch:   "was built with an initially released source file that had " \ | 
					
						
							| 
									
										
										
										
											2021-11-15 19:34:19 +01:00
										 |  |  |                          "a different checksum than the current one. " \ | 
					
						
							|  |  |  |                          "Upstream's repository might have been compromised. " \ | 
					
						
							|  |  |  |                          "We can re-package this once upstream has confirmed that they retagged their release", | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   }.freeze, T::Hash[Symbol, String]) | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   CASK_DEPRECATE_DISABLE_REASONS = T.let({ | 
					
						
							| 
									
										
										
										
											2024-02-27 13:37:53 +11:00
										 |  |  |     discontinued:             "is discontinued upstream", | 
					
						
							| 
									
										
										
										
											2024-03-28 10:47:45 +11:00
										 |  |  |     moved_to_mas:             "is now exclusively distributed on the Mac App Store", | 
					
						
							| 
									
										
										
										
											2024-02-27 13:37:53 +11:00
										 |  |  |     no_longer_available:      "is no longer available upstream", | 
					
						
							|  |  |  |     no_longer_meets_criteria: "no longer meets the criteria for acceptable casks", | 
					
						
							|  |  |  |     unmaintained:             "is not maintained upstream", | 
					
						
							| 
									
										
										
										
											2025-08-18 16:15:27 +10:00
										 |  |  |     fails_gatekeeper_check:   "does not pass the macOS Gatekeeper check", | 
					
						
							| 
									
										
										
										
											2025-08-13 00:13:57 +10:00
										 |  |  |     # odeprecate: remove the unsigned reason in a future release | 
					
						
							| 
									
										
										
										
											2024-04-02 11:27:02 -04:00
										 |  |  |     unsigned:                 "is unsigned or does not meet signature requirements", | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   }.freeze, T::Hash[Symbol, String]) | 
					
						
							| 
									
										
										
										
											2023-12-03 21:59:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-14 11:49:43 -04:00
										 |  |  |   # One year when << or >> to Date.today. | 
					
						
							|  |  |  |   REMOVE_DISABLED_TIME_WINDOW = 12
 | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   REMOVE_DISABLED_BEFORE = T.let((Date.today << REMOVE_DISABLED_TIME_WINDOW).freeze, Date) | 
					
						
							| 
									
										
										
										
											2024-07-14 11:49:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T.nilable(Symbol)) } | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |   def type(formula_or_cask) | 
					
						
							|  |  |  |     return :deprecated if formula_or_cask.deprecated? | 
					
						
							| 
									
										
										
										
											2023-12-16 20:08:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     :disabled if formula_or_cask.disabled? | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-02 13:19:49 +02:00
										 |  |  |   sig { | 
					
						
							|  |  |  |     params( | 
					
						
							| 
									
										
										
										
											2025-04-14 13:46:05 +02:00
										 |  |  |       formula: T.nilable(String), | 
					
						
							|  |  |  |       cask:    T.nilable(String), | 
					
						
							| 
									
										
										
										
											2025-04-02 13:19:49 +02:00
										 |  |  |     ).returns(T.nilable(String)) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-04-14 13:46:05 +02:00
										 |  |  |   def replacement_with_type(formula, cask) | 
					
						
							|  |  |  |     if formula && formula == cask | 
					
						
							|  |  |  |       formula | 
					
						
							|  |  |  |     elsif formula | 
					
						
							| 
									
										
										
										
											2025-04-02 13:19:49 +02:00
										 |  |  |       "--formula #{formula}" | 
					
						
							|  |  |  |     elsif cask | 
					
						
							|  |  |  |       "--cask #{cask}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T.nilable(String)) } | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |   def message(formula_or_cask) | 
					
						
							|  |  |  |     return if type(formula_or_cask).blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     reason = if formula_or_cask.deprecated? | 
					
						
							|  |  |  |       formula_or_cask.deprecation_reason | 
					
						
							| 
									
										
										
										
											2023-12-03 21:59:03 -05:00
										 |  |  |     elsif formula_or_cask.disabled? | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |       formula_or_cask.disable_reason | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-18 14:15:19 +10:00
										 |  |  |     # odeprecate: remove this remapping in a future release | 
					
						
							|  |  |  |     reason = :fails_gatekeeper_check if reason == :unsigned | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-03 21:59:03 -05:00
										 |  |  |     reason = if formula_or_cask.is_a?(Formula) && FORMULA_DEPRECATE_DISABLE_REASONS.key?(reason) | 
					
						
							|  |  |  |       FORMULA_DEPRECATE_DISABLE_REASONS[reason] | 
					
						
							|  |  |  |     elsif formula_or_cask.is_a?(Cask::Cask) && CASK_DEPRECATE_DISABLE_REASONS.key?(reason) | 
					
						
							|  |  |  |       CASK_DEPRECATE_DISABLE_REASONS[reason] | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |     else | 
					
						
							|  |  |  |       reason | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-14 11:49:43 -04:00
										 |  |  |     message = if reason.present? | 
					
						
							|  |  |  |       "#{type(formula_or_cask)} because it #{reason}!" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       "#{type(formula_or_cask)}!" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     disable_date = formula_or_cask.disable_date | 
					
						
							|  |  |  |     if !disable_date && formula_or_cask.deprecation_date | 
					
						
							|  |  |  |       disable_date = formula_or_cask.deprecation_date >> REMOVE_DISABLED_TIME_WINDOW | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-08-14 21:31:01 +02:00
										 |  |  |     if disable_date | 
					
						
							|  |  |  |       message += if disable_date < Date.today | 
					
						
							|  |  |  |         " It was disabled on #{disable_date}." | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         " It will be disabled on #{disable_date}." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-02 13:19:49 +02:00
										 |  |  |     replacement = if formula_or_cask.disabled? | 
					
						
							|  |  |  |       replacement_with_type( | 
					
						
							|  |  |  |         formula_or_cask.disable_replacement_formula, | 
					
						
							|  |  |  |         formula_or_cask.disable_replacement_cask, | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     elsif formula_or_cask.deprecated? | 
					
						
							|  |  |  |       replacement_with_type( | 
					
						
							|  |  |  |         formula_or_cask.deprecation_replacement_formula, | 
					
						
							|  |  |  |         formula_or_cask.deprecation_replacement_cask, | 
					
						
							|  |  |  |       ) | 
					
						
							| 
									
										
										
										
											2025-03-24 16:23:57 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 15:50:03 -05:00
										 |  |  |     if replacement.present? | 
					
						
							|  |  |  |       message << "\n" | 
					
						
							|  |  |  |       message << <<~EOS | 
					
						
							|  |  |  |         Replacement: | 
					
						
							| 
									
										
										
										
											2025-04-02 13:19:49 +02:00
										 |  |  |           brew install #{replacement} | 
					
						
							| 
									
										
										
										
											2024-11-07 15:50:03 -05:00
										 |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-14 11:49:43 -04:00
										 |  |  |     message | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |   sig { params(string: T.nilable(String), type: Symbol).returns(T.nilable(T.any(String, Symbol))) } | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |   def to_reason_string_or_symbol(string, type:) | 
					
						
							| 
									
										
										
										
											2024-12-20 12:13:33 -05:00
										 |  |  |     return if string.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type == :formula && FORMULA_DEPRECATE_DISABLE_REASONS.key?(string.to_sym)) || | 
					
						
							|  |  |  |        (type == :cask && CASK_DEPRECATE_DISABLE_REASONS.key?(string.to_sym)) | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |       return string.to_sym | 
					
						
							| 
									
										
										
										
											2023-12-03 21:59:03 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 00:30:49 -05:00
										 |  |  |     string | 
					
						
							| 
									
										
										
										
											2020-09-07 13:00:02 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | end |