Skip to content

Commit

Permalink
PoC: Use a factory rather than dynamically redefine methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Aug 15, 2024
1 parent 5ffacaf commit c4f9e5e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
8 changes: 3 additions & 5 deletions Library/Homebrew/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

# Cleans a newly installed keg.
Expand Down Expand Up @@ -104,7 +104,7 @@ def prune
end
end

sig { params(path: Pathname).returns(T::Boolean) }
sig { overridable.params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.text_executable? || path.executable?
end
Expand All @@ -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 = Set.new(%w[perllocal.pod .packlist]).freeze
PERL_BASENAMES = T.let(Set.new(%w[perllocal.pod .packlist]).freeze, T::Set[String])

# Clean a top-level (`bin`, `sbin`, `lib`) directory, recursively, by fixing file
# permissions and removing .la files, unless the files (or parent
Expand Down Expand Up @@ -201,5 +201,3 @@ def clean_python_metadata
end
end
end

require "extend/os/cleaner"
22 changes: 22 additions & 0 deletions Library/Homebrew/cleaner_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
8 changes: 0 additions & 8 deletions Library/Homebrew/extend/os/cleaner.rb

This file was deleted.

4 changes: 2 additions & 2 deletions Library/Homebrew/extend/os/linux/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# typed: strict
# frozen_string_literal: true

class Cleaner
class CleanerLinux < Cleaner
private

sig { params(path: Pathname).returns(T::Boolean) }
sig { override.params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.elf? || path.text_executable?
end
Expand Down
6 changes: 2 additions & 4 deletions Library/Homebrew/extend/os/mac/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# typed: strict
# frozen_string_literal: true

class Cleaner
class CleanerMac < Cleaner
private

undef executable_path?

sig { params(path: Pathname).returns(T::Boolean) }
sig { override.params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require "tab"
require "utils/bottles"
require "caveats"
require "cleaner"
require "cleaner_factory"
require "formula_cellar_checks"
require "install_renamed"
require "sandbox"
Expand Down Expand Up @@ -1107,7 +1107,7 @@ def fix_dynamic_linkage(keg)
sig { void }
def clean
ohai "Cleaning" if verbose?
Cleaner.new(formula).clean
CleanerFactory.create(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."
Expand Down

0 comments on commit c4f9e5e

Please sign in to comment.