Tweak formula deprecation/disabling.

This commit is contained in:
Mike McQuaid 2020-04-01 13:42:52 +01:00
parent 4121659413
commit 3effcc4dff
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
7 changed files with 48 additions and 53 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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!

View File

@ -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

View File

@ -13,7 +13,6 @@ require "utils/link"
require "utils/popen"
require "utils/svn"
require "utils/tty"
require "utils/deprecate"
require "tap_constants"
require "time"

View File

@ -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