From 03ee70b1aeb0178a0394e1fb53f08aaecdad9031 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 26 Apr 2023 09:08:40 -0700 Subject: [PATCH 1/6] Remove kernel/reporting extension --- .gitignore | 1 - Library/Homebrew/global.rb | 1 - Library/Homebrew/utils/autoremove.rb | 4 +- .../core_ext/kernel/reporting.rb | 45 ------------------- 4 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.3/lib/active_support/core_ext/kernel/reporting.rb diff --git a/.gitignore b/.gitignore index 773337130a..165b20da79 100644 --- a/.gitignore +++ b/.gitignore @@ -80,7 +80,6 @@ !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/inflections.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/multibyte.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/enumerable.rb -!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/kernel/reporting.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/i18n.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/inflector/transliterate.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/inflector/methods.rb diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 4b4a9641a1..b59bcdc6ca 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -18,7 +18,6 @@ require "active_support/core_ext/file/atomic" require "active_support/core_ext/hash/deep_merge" require "active_support/core_ext/hash/except" require "active_support/core_ext/hash/keys" -require "active_support/core_ext/kernel/reporting" require "active_support/core_ext/object/blank" require "active_support/core_ext/object/try" require "active_support/core_ext/string/exclude" diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index 3a53c5d745..bce407f306 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -33,7 +33,9 @@ module Utils next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle formula.deps.select(&:build?).each do |dep| - Kernel.suppress(FormulaUnavailableError) { dependents << dep.to_formula } + dependents << dep.to_formula + rescue FormulaUnavailableError + # do nothing end end formulae - dependents diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.3/lib/active_support/core_ext/kernel/reporting.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.3/lib/active_support/core_ext/kernel/reporting.rb deleted file mode 100644 index 9155bd6c10..0000000000 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.3/lib/active_support/core_ext/kernel/reporting.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -module Kernel - module_function - - # Sets $VERBOSE to +nil+ for the duration of the block and back to its original - # value afterwards. - # - # silence_warnings do - # value = noisy_call # no warning voiced - # end - # - # noisy_call # warning voiced - def silence_warnings - with_warnings(nil) { yield } - end - - # Sets $VERBOSE to +true+ for the duration of the block and back to its - # original value afterwards. - def enable_warnings - with_warnings(true) { yield } - end - - # Sets $VERBOSE for the duration of the block and back to its original - # value afterwards. - def with_warnings(flag) - old_verbose, $VERBOSE = $VERBOSE, flag - yield - ensure - $VERBOSE = old_verbose - end - - # Blocks and ignores any exception passed as argument if raised within the block. - # - # suppress(ZeroDivisionError) do - # 1/0 - # puts 'This code is NOT reached' - # end - # - # puts 'This code gets executed and nothing related to ZeroDivisionError was seen' - def suppress(*exception_classes) - yield - rescue *exception_classes - end -end From 8f97dea1670bd5026839b19c679443219d7c58d3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 26 Apr 2023 09:09:14 -0700 Subject: [PATCH 2/6] Remove other activesupport use --- Library/Homebrew/utils/autoremove.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index bce407f306..712709afe6 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -23,8 +23,6 @@ module Utils # for those built from source. # @private def formulae_with_no_formula_dependents(formulae) - return [] if formulae.blank? - dependents = T.let([], T::Array[Formula]) formulae.each do |formula| dependents += formula.runtime_formula_dependencies @@ -50,7 +48,7 @@ module Utils Tab.for_keg(f.any_installed_keg).installed_on_request end - if unused_formulae.present? + unless unused_formulae.empty? unused_formulae += unused_formulae_with_no_formula_dependents(formulae - unused_formulae) end From 7229d031338f7d6f4800a7a1706f8db63be1c799 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 26 Apr 2023 09:10:30 -0700 Subject: [PATCH 3/6] Switch from module_function to eigenclass --- Library/Homebrew/utils/autoremove.rb | 96 ++++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index 712709afe6..8b9d63f052 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -6,63 +6,63 @@ module Utils # # @private module Autoremove - module_function + class << self + # An array of all installed {Formula} with {Cask} dependents. + # @private + def formulae_with_cask_dependents(casks) + casks.flat_map { |cask| cask.depends_on[:formula] } + .compact + .map { |f| Formula[f] } + .flat_map { |f| [f, *f.runtime_formula_dependencies].compact } + end + private_class_method :formulae_with_cask_dependents - # An array of all installed {Formula} with {Cask} dependents. - # @private - def formulae_with_cask_dependents(casks) - casks.flat_map { |cask| cask.depends_on[:formula] } - .compact - .map { |f| Formula[f] } - .flat_map { |f| [f, *f.runtime_formula_dependencies].compact } - end - private_class_method :formulae_with_cask_dependents + # An array of all installed {Formula} without runtime {Formula} + # dependents for bottles and without build {Formula} dependents + # for those built from source. + # @private + def formulae_with_no_formula_dependents(formulae) + dependents = T.let([], T::Array[Formula]) + formulae.each do |formula| + dependents += formula.runtime_formula_dependencies - # An array of all installed {Formula} without runtime {Formula} - # dependents for bottles and without build {Formula} dependents - # for those built from source. - # @private - def formulae_with_no_formula_dependents(formulae) - dependents = T.let([], T::Array[Formula]) - formulae.each do |formula| - dependents += formula.runtime_formula_dependencies + # Ignore build dependencies when the formula is a bottle + next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle - # Ignore build dependencies when the formula is a bottle - next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle - - formula.deps.select(&:build?).each do |dep| - dependents << dep.to_formula - rescue FormulaUnavailableError - # do nothing + formula.deps.select(&:build?).each do |dep| + dependents << dep.to_formula + rescue FormulaUnavailableError + # do nothing + end end + formulae - dependents end - formulae - dependents - end - private_class_method :formulae_with_no_formula_dependents + private_class_method :formulae_with_no_formula_dependents - # Recursive function that returns an array of {Formula} without - # {Formula} dependents that weren't installed on request. - # @private - def unused_formulae_with_no_formula_dependents(formulae) - unused_formulae = formulae_with_no_formula_dependents(formulae).reject do |f| - Tab.for_keg(f.any_installed_keg).installed_on_request + # Recursive function that returns an array of {Formula} without + # {Formula} dependents that weren't installed on request. + # @private + def unused_formulae_with_no_formula_dependents(formulae) + unused_formulae = formulae_with_no_formula_dependents(formulae).reject do |f| + Tab.for_keg(f.any_installed_keg).installed_on_request + end + + unless unused_formulae.empty? + unused_formulae += unused_formulae_with_no_formula_dependents(formulae - unused_formulae) + end + + unused_formulae end + private_class_method :unused_formulae_with_no_formula_dependents - unless unused_formulae.empty? - unused_formulae += unused_formulae_with_no_formula_dependents(formulae - unused_formulae) + # An array of {Formula} without {Formula} or {Cask} + # dependents that weren't installed on request and without + # build dependencies for {Formula} installed from source. + # @private + def removable_formulae(formulae, casks) + unused_formulae = unused_formulae_with_no_formula_dependents(formulae) + unused_formulae - formulae_with_cask_dependents(casks) end - - unused_formulae - end - private_class_method :unused_formulae_with_no_formula_dependents - - # An array of {Formula} without {Formula} or {Cask} - # dependents that weren't installed on request and without - # build dependencies for {Formula} installed from source. - # @private - def removable_formulae(formulae, casks) - unused_formulae = unused_formulae_with_no_formula_dependents(formulae) - unused_formulae - formulae_with_cask_dependents(casks) end end end From a69fc114598fe4ad034aaec823051e0ea28600d3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 26 Apr 2023 09:11:21 -0700 Subject: [PATCH 4/6] Hoist public method --- Library/Homebrew/utils/autoremove.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index 8b9d63f052..aad6d89990 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -7,6 +7,15 @@ module Utils # @private module Autoremove class << self + # An array of {Formula} without {Formula} or {Cask} + # dependents that weren't installed on request and without + # build dependencies for {Formula} installed from source. + # @private + def removable_formulae(formulae, casks) + unused_formulae = unused_formulae_with_no_formula_dependents(formulae) + unused_formulae - formulae_with_cask_dependents(casks) + end + # An array of all installed {Formula} with {Cask} dependents. # @private def formulae_with_cask_dependents(casks) @@ -54,15 +63,6 @@ module Utils unused_formulae end private_class_method :unused_formulae_with_no_formula_dependents - - # An array of {Formula} without {Formula} or {Cask} - # dependents that weren't installed on request and without - # build dependencies for {Formula} installed from source. - # @private - def removable_formulae(formulae, casks) - unused_formulae = unused_formulae_with_no_formula_dependents(formulae) - unused_formulae - formulae_with_cask_dependents(casks) - end end end end From 65a4d9f6278b8a452bb87abdfd6c7ae26715d395 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 26 Apr 2023 09:12:08 -0700 Subject: [PATCH 5/6] Fix visibility modifiers --- Library/Homebrew/utils/autoremove.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index aad6d89990..cbc0e0d8bd 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -16,6 +16,8 @@ module Utils unused_formulae - formulae_with_cask_dependents(casks) end + private + # An array of all installed {Formula} with {Cask} dependents. # @private def formulae_with_cask_dependents(casks) @@ -24,7 +26,6 @@ module Utils .map { |f| Formula[f] } .flat_map { |f| [f, *f.runtime_formula_dependencies].compact } end - private_class_method :formulae_with_cask_dependents # An array of all installed {Formula} without runtime {Formula} # dependents for bottles and without build {Formula} dependents @@ -46,7 +47,6 @@ module Utils end formulae - dependents end - private_class_method :formulae_with_no_formula_dependents # Recursive function that returns an array of {Formula} without # {Formula} dependents that weren't installed on request. @@ -62,7 +62,6 @@ module Utils unused_formulae end - private_class_method :unused_formulae_with_no_formula_dependents end end end From 1df469b34877aa8f8524276fb44dca77d50ff8f0 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 26 Apr 2023 09:13:00 -0700 Subject: [PATCH 6/6] Enable strict typing --- Library/Homebrew/utils/autoremove.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index cbc0e0d8bd..8ee06034b1 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module Utils @@ -11,6 +11,7 @@ module Utils # dependents that weren't installed on request and without # build dependencies for {Formula} installed from source. # @private + sig { params(formulae: T::Array[Formula], casks: T::Array[Cask::Cask]).returns(T::Array[Formula]) } def removable_formulae(formulae, casks) unused_formulae = unused_formulae_with_no_formula_dependents(formulae) unused_formulae - formulae_with_cask_dependents(casks) @@ -20,6 +21,7 @@ module Utils # An array of all installed {Formula} with {Cask} dependents. # @private + sig { params(casks: T::Array[Cask::Cask]).returns(T::Array[Formula]) } def formulae_with_cask_dependents(casks) casks.flat_map { |cask| cask.depends_on[:formula] } .compact @@ -31,6 +33,7 @@ module Utils # dependents for bottles and without build {Formula} dependents # for those built from source. # @private + sig { params(formulae: T::Array[Formula]).returns(T::Array[Formula]) } def formulae_with_no_formula_dependents(formulae) dependents = T.let([], T::Array[Formula]) formulae.each do |formula| @@ -51,6 +54,7 @@ module Utils # Recursive function that returns an array of {Formula} without # {Formula} dependents that weren't installed on request. # @private + sig { params(formulae: T::Array[Formula]).returns(T::Array[Formula]) } def unused_formulae_with_no_formula_dependents(formulae) unused_formulae = formulae_with_no_formula_dependents(formulae).reject do |f| Tab.for_keg(f.any_installed_keg).installed_on_request