From 3effcc4dff3217aa5a539ce1619844bfa704a515 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 1 Apr 2020 13:42:52 +0100 Subject: [PATCH] Tweak formula deprecation/disabling. --- Library/Homebrew/cmd/install.rb | 1 - Library/Homebrew/cmd/reinstall.rb | 1 - Library/Homebrew/cmd/upgrade.rb | 2 - Library/Homebrew/formula.rb | 55 ++++++++++++++++++++------- Library/Homebrew/formula_installer.rb | 6 +++ Library/Homebrew/utils.rb | 1 - Library/Homebrew/utils/deprecate.rb | 35 ----------------- 7 files changed, 48 insertions(+), 53 deletions(-) delete mode 100644 Library/Homebrew/utils/deprecate.rb diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 7684db7e7e..7245c5690f 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -315,7 +315,6 @@ module Homebrew end def install_formula(f) - opoo "#{f.name} has been deprecated" if f.is_deprecated? f.print_tap_action build_options = f.build diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 07956e1fac..c6abc8fa36 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -61,7 +61,6 @@ module Homebrew onoe "#{f.full_name} is pinned. You must unpin it to reinstall." next end - opoo "#{f.name} has been deprecated" if f.is_deprecated? Migrator.migrate_if_needed(f) reinstall_formula(f) Cleanup.install_formula_clean!(f) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 1c261bb91d..9a7588385b 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -150,8 +150,6 @@ module Homebrew def upgrade_formula(f) return if args.dry_run? - opoo "#{f.name} has been deprecated" if f.is_deprecated? - if f.opt_prefix.directory? keg = Keg.new(f.opt_prefix.resolved_path) keg_had_linked_opt = true diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 27bd068c39..45ebd50254 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -53,7 +53,6 @@ class Formula include Utils::Inreplace include Utils::Shebang include Utils::Shell - include Utils::Deprecate extend Enumerable extend Forwardable extend Cachable @@ -178,16 +177,6 @@ class Formula attr_accessor :follow_installed_alias alias follow_installed_alias? follow_installed_alias - # A Boolean indicating whether this formula is deprecated or not - # Defaults to false - attr_accessor :is_deprecated - alias is_deprecated? is_deprecated - - # A Boolean indicating whether this formula is disabled - # Defaults to false - attr_accessor :is_disabled - alias is_disabled? is_disabled - # @private def initialize(name, path, spec, alias_path: nil) @name = name @@ -224,8 +213,6 @@ class Formula @follow_installed_alias = true @prefix_returns_versioned_prefix = false @oldname_lock = nil - @is_deprecated = false - @is_disabled = false end # @private @@ -1118,6 +1105,20 @@ class Formula end end + # Whether this {Formula} is deprecated (i.e. warns on installation). + # Defaults to false. + # @return [Boolean] + def deprecated? + self.class.deprecated? + end + + # Whether this {Formula} is disabled (i.e. cannot be installed). + # Defaults to false. + # @return [Boolean] + def disabled? + self.class.disabled? + end + def skip_cxxstdlib_check? false end @@ -2618,6 +2619,34 @@ class Formula @pour_bottle_check.instance_eval(&block) end + # Deprecates a {Formula} so a warning is shown on each installation. + def deprecate!(date: nil) + return if date.present? && Date.parse(date) > Date.today + + @deprecated = true + end + + # Whether this {Formula} is deprecated (i.e. warns on installation). + # Defaults to false. + # @return [Boolean] + def deprecated? + @deprecated == true + end + + # Disables a {Formula} so it cannot be installed. + def disable!(date: nil) + return if date.present? && Date.parse(date) > Date.today + + @disabled = true + end + + # Whether this {Formula} is disabled (i.e. cannot be installed). + # Defaults to false. + # @return [Boolean] + def disabled? + @disabled == true + end + # @private def link_overwrite(*paths) paths.flatten! diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index de418af649..bb7f2bdca5 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -161,6 +161,12 @@ class FormulaInstaller def check_install_sanity raise FormulaInstallationAlreadyAttemptedError, formula if self.class.attempted.include?(formula) + if formula.deprecated? + opoo "#{formula.full_name} has been deprecated!" + elsif formula.disabled? + odie "#{formula.full_name} has been disabled!" + end + return if ignore_deps? recursive_deps = formula.recursive_dependencies diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 0dbcb461da..65f6492a15 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -13,7 +13,6 @@ require "utils/link" require "utils/popen" require "utils/svn" require "utils/tty" -require "utils/deprecate" require "tap_constants" require "time" diff --git a/Library/Homebrew/utils/deprecate.rb b/Library/Homebrew/utils/deprecate.rb deleted file mode 100644 index 73529ff0db..0000000000 --- a/Library/Homebrew/utils/deprecate.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module Utils - module Deprecate - # This module is common for both formulae and casks. - # To-do : Add support for casks + add disable method - - def deprecate - self.is_deprecated = true - - # deprecate all formulae dependent on this deprecated formula - all_formulae = ObjectSpace.each_object(Class).select { |klass| klass < Formula } - all_formulae.each do |f| - dependencies = f.recursive_dependencies.map(&:name) - f.is_deprecated = true if (dependencies.include? self.name) - end - end - - # Deprecation can be revoked if the underlying problem is fixed - def revoke_deprecation - self.is_deprecated = false - - # revoke deprecation from dependents as well - all_formulae = ObjectSpace.each_object(Class).select { |klass| klass < Formula } - all_formulae.each do |f| - dependencies = f.recursive_dependencies.map(&:name) - revoke = true - dependencies.each do |d| - revoke = !(d != self && d.is_deprecated?) - end - f.is_deprecated = false if revoke && (dependencies.include? self.name) - end - end - end -end