From 7a62973de296e3d11cdbf17acd3bc7b19ca0d5bc Mon Sep 17 00:00:00 2001 From: vidusheeamoli Date: Thu, 19 Mar 2020 23:44:00 +0530 Subject: [PATCH] add deprecate module --- Library/Homebrew/cmd/install.rb | 1 + Library/Homebrew/cmd/reinstall.rb | 1 + Library/Homebrew/cmd/upgrade.rb | 2 ++ Library/Homebrew/formula.rb | 13 +++++++++++ Library/Homebrew/utils.rb | 1 + Library/Homebrew/utils/deprecate.rb | 35 +++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+) create mode 100644 Library/Homebrew/utils/deprecate.rb diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 7245c5690f..7684db7e7e 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -315,6 +315,7 @@ 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 c6abc8fa36..07956e1fac 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -61,6 +61,7 @@ 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 9a7588385b..1c261bb91d 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -150,6 +150,8 @@ 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 1df01f60a6..79fde5b1e7 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -51,6 +51,7 @@ class Formula include FileUtils include Utils::Inreplace include Utils::Shell + include Utils::Deprecate extend Enumerable extend Forwardable extend Cachable @@ -175,6 +176,16 @@ 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 @@ -211,6 +222,8 @@ class Formula @follow_installed_alias = true @prefix_returns_versioned_prefix = false @oldname_lock = nil + @is_deprecated = false + @is_disabled = false end # @private diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 65f6492a15..0dbcb461da 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -13,6 +13,7 @@ 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 new file mode 100644 index 0000000000..73529ff0db --- /dev/null +++ b/Library/Homebrew/utils/deprecate.rb @@ -0,0 +1,35 @@ +# 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