From a486b1df21e14c4f6e8e116ad16808c9f343eba3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 15 Aug 2024 12:41:54 -0700 Subject: [PATCH] Revert "PoC: Use a factory rather than dynamically redefine methods" This reverts commit c4f9e5eccd8a87dc2a7d58bcd50da25f5c511369. --- Library/Homebrew/cleaner.rb | 8 +++++--- Library/Homebrew/cleaner_factory.rb | 22 --------------------- Library/Homebrew/extend/os/cleaner.rb | 8 ++++++++ Library/Homebrew/extend/os/linux/cleaner.rb | 4 ++-- Library/Homebrew/extend/os/mac/cleaner.rb | 6 ++++-- Library/Homebrew/formula_installer.rb | 4 ++-- 6 files changed, 21 insertions(+), 31 deletions(-) delete mode 100644 Library/Homebrew/cleaner_factory.rb create mode 100644 Library/Homebrew/extend/os/cleaner.rb diff --git a/Library/Homebrew/cleaner.rb b/Library/Homebrew/cleaner.rb index 71c8b90b536e1..d81022029c413 100644 --- a/Library/Homebrew/cleaner.rb +++ b/Library/Homebrew/cleaner.rb @@ -1,4 +1,4 @@ -# typed: strict +# typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true # Cleans a newly installed keg. @@ -104,7 +104,7 @@ def prune end end - sig { overridable.params(path: Pathname).returns(T::Boolean) } + sig { params(path: Pathname).returns(T::Boolean) } def executable_path?(path) path.text_executable? || path.executable? end @@ -113,7 +113,7 @@ def executable_path?(path) # pointless conflicts with other formulae. They are removed by Debian, # Arch & MacPorts amongst other packagers as well. The files are # created as part of installing any Perl module. - PERL_BASENAMES = T.let(Set.new(%w[perllocal.pod .packlist]).freeze, T::Set[String]) + PERL_BASENAMES = Set.new(%w[perllocal.pod .packlist]).freeze # Clean a top-level (`bin`, `sbin`, `lib`) directory, recursively, by fixing file # permissions and removing .la files, unless the files (or parent @@ -201,3 +201,5 @@ def clean_python_metadata end end end + +require "extend/os/cleaner" diff --git a/Library/Homebrew/cleaner_factory.rb b/Library/Homebrew/cleaner_factory.rb deleted file mode 100644 index 33d84442679cf..0000000000000 --- a/Library/Homebrew/cleaner_factory.rb +++ /dev/null @@ -1,22 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -require "cleaner" - -class CleanerFactory - # This just a PoC - # rubocop:disable Homebrew/MoveToExtendOS - CLEANER_CLASS = T.let(if OS.mac? - require "extend/os/mac/cleaner" - CleanerMac - elsif OS.linux? - require "extend/os/linux/cleaner" - CleanerLinux - else - Cleaner - end.freeze, T.class_of(Cleaner)) - # rubocop:enable Homebrew/MoveToExtendOS - - sig { params(formula: Formula).returns(Cleaner) } - def self.create(formula) = CLEANER_CLASS.new(formula) -end diff --git a/Library/Homebrew/extend/os/cleaner.rb b/Library/Homebrew/extend/os/cleaner.rb new file mode 100644 index 0000000000000..2e318d7d5b45b --- /dev/null +++ b/Library/Homebrew/extend/os/cleaner.rb @@ -0,0 +1,8 @@ +# typed: strict +# frozen_string_literal: true + +if OS.mac? + require "extend/os/mac/cleaner" +elsif OS.linux? + require "extend/os/linux/cleaner" +end diff --git a/Library/Homebrew/extend/os/linux/cleaner.rb b/Library/Homebrew/extend/os/linux/cleaner.rb index 58d488ac7b9c8..e1e34f09ad1af 100644 --- a/Library/Homebrew/extend/os/linux/cleaner.rb +++ b/Library/Homebrew/extend/os/linux/cleaner.rb @@ -1,10 +1,10 @@ # typed: strict # frozen_string_literal: true -class CleanerLinux < Cleaner +class Cleaner private - sig { override.params(path: Pathname).returns(T::Boolean) } + sig { params(path: Pathname).returns(T::Boolean) } def executable_path?(path) path.elf? || path.text_executable? end diff --git a/Library/Homebrew/extend/os/mac/cleaner.rb b/Library/Homebrew/extend/os/mac/cleaner.rb index 0a337ab304b49..460169c996214 100644 --- a/Library/Homebrew/extend/os/mac/cleaner.rb +++ b/Library/Homebrew/extend/os/mac/cleaner.rb @@ -1,10 +1,12 @@ # typed: strict # frozen_string_literal: true -class CleanerMac < Cleaner +class Cleaner private - sig { override.params(path: Pathname).returns(T::Boolean) } + undef executable_path? + + sig { params(path: Pathname).returns(T::Boolean) } def executable_path?(path) path.mach_o_executable? || path.text_executable? end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index aff7df6d189c0..ec6a4345e0e38 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -6,7 +6,7 @@ require "tab" require "utils/bottles" require "caveats" -require "cleaner_factory" +require "cleaner" require "formula_cellar_checks" require "install_renamed" require "sandbox" @@ -1107,7 +1107,7 @@ def fix_dynamic_linkage(keg) sig { void } def clean ohai "Cleaning" if verbose? - CleanerFactory.create(formula).clean + Cleaner.new(formula).clean rescue Exception => e # rubocop:disable Lint/RescueException opoo "The cleaning step did not complete successfully" puts "Still, the installation was successful, so we will link it into your prefix."