diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index b9dfebb6ec..2ebf119e60 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -331,6 +331,12 @@ module Cask "conflicts_with" => conflicts_with, "container" => container&.pairs, "auto_updates" => auto_updates, + "deprecated" => deprecated?, + "deprecation_date" => deprecation_date, + "deprecation_reason" => deprecation_reason, + "disabled" => disabled?, + "disable_date" => disable_date, + "disable_reason" => disable_reason, "tap_git_head" => tap_git_head, "languages" => languages, "ruby_source_path" => ruby_source_path, diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index e8a1bf39b0..1a08657cef 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -84,6 +84,14 @@ module Cask :url, :version, :appdir, + :deprecate!, + :deprecated?, + :deprecation_date, + :deprecation_reason, + :disable!, + :disabled?, + :disable_date, + :disable_reason, :discontinued?, :livecheck, :livecheckable?, @@ -96,9 +104,9 @@ module Cask extend Predicable include OnSystem::MacOSOnly - attr_reader :cask, :token + attr_reader :cask, :token, :deprecation_date, :deprecation_reason, :disable_date, :disable_reason - attr_predicate :on_system_blocks_exist? + attr_predicate :on_system_blocks_exist?, :disabled?, :livecheckable? def initialize(cask) @cask = cask @@ -316,9 +324,15 @@ module Cask end def discontinued? + # odeprecated "`discontinued?`", "`deprecated?` or `disabled?`" @caveats&.discontinued? == true end + # TODO: replace with with attr_predicate once discontinued? is disabled + def deprecated? + @deprecated == true || @caveats&.discontinued? == true + end + # @api public def auto_updates(auto_updates = nil) set_unique_stanza(:auto_updates, auto_updates.nil?) { auto_updates } @@ -337,8 +351,27 @@ module Cask @livecheck.instance_eval(&block) end - def livecheckable? - @livecheckable == true + # @api public + def deprecate!(date:, because:) + @deprecation_date = Date.parse(date) + return if @deprecation_date > Date.today + + @deprecation_reason = because + @deprecated = true + end + + # @api public + def disable!(date:, because:) + @disable_date = Date.parse(date) + + if @disable_date > Date.today + @deprecation_reason = because + @deprecated = true + return + end + + @disable_reason = because + @disabled = true end ORDINARY_ARTIFACT_CLASSES.each do |klass| diff --git a/Library/Homebrew/deprecate_disable.rb b/Library/Homebrew/deprecate_disable.rb index 2b31d467a7..b64e98e854 100644 --- a/Library/Homebrew/deprecate_disable.rb +++ b/Library/Homebrew/deprecate_disable.rb @@ -7,7 +7,12 @@ module DeprecateDisable module_function - DEPRECATE_DISABLE_REASONS = { + SHARED_DEPRECATE_DISABLE_REASONS = { + repo_archived: "has an archived upstream repository", + repo_removed: "has a removed upstream repository", + }.freeze + + FORMULA_DEPRECATE_DISABLE_REASONS = { does_not_build: "does not build", no_license: "has no license", repo_archived: "has an archived upstream repository", @@ -20,20 +25,32 @@ module DeprecateDisable "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", + **SHARED_DEPRECATE_DISABLE_REASONS, }.freeze - def deprecate_disable_info(formula) - if formula.deprecated? + CASK_DEPRECATE_DISABLE_REASONS = { + discontinued: "is discontinued upstream", + unsigned_artifact: "has an unsigned binary which prevents it from running on Apple Silicon devices " \ + "under standard macOS security policy", + **SHARED_DEPRECATE_DISABLE_REASONS, + }.freeze + + def deprecate_disable_info(formula_or_cask) + if formula_or_cask.deprecated? type = :deprecated - reason = formula.deprecation_reason - elsif formula.disabled? + reason = formula_or_cask.deprecation_reason + elsif formula_or_cask.disabled? type = :disabled - reason = formula.disable_reason + reason = formula_or_cask.disable_reason else return end - reason = DEPRECATE_DISABLE_REASONS[reason] if DEPRECATE_DISABLE_REASONS.key? reason + 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] + end [type, reason] end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9eb6a6d5fa..cdae57e8b8 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -3550,7 +3550,7 @@ class Formula #
deprecate! date: "2020-08-27", because: :unmaintained
#
deprecate! date: "2020-08-27", because: "has been replaced by foo"
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae - # @see DeprecateDisable::DEPRECATE_DISABLE_REASONS + # @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS def deprecate!(date:, because:) @deprecation_date = Date.parse(date) return if @deprecation_date > Date.today @@ -3585,7 +3585,7 @@ class Formula #
disable! date: "2020-08-27", because: :does_not_build
#
disable! date: "2020-08-27", because: "has been replaced by foo"
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae - # @see DeprecateDisable::DEPRECATE_DISABLE_REASONS + # @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS def disable!(date:, because:) @disable_date = Date.parse(date) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 8edcbb6799..da319e1093 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -412,7 +412,7 @@ module Homebrew return if formula.disabled? return if formula.deprecated? && - formula.deprecation_reason != DeprecateDisable::DEPRECATE_DISABLE_REASONS[:versioned_formula] + formula.deprecation_reason != DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS[:versioned_formula] problem <<~EOS #{formula.full_name} contains conflicting version recursive dependencies: diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 014006ff21..5d6e47c5b0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -464,7 +464,7 @@ module Formulary def self.convert_to_deprecate_disable_reason_string_or_symbol(string) require "deprecate_disable" - return string unless DeprecateDisable::DEPRECATE_DISABLE_REASONS.keys.map(&:to_s).include?(string) + return string unless DeprecateDisable::FORMULARY_DEPRECATE_DISABLE_REASONS.keys.map(&:to_s).include?(string) string.to_sym end