cleaner: add types

Signed-off-by: Michael Cho <michael@michaelcho.dev>
This commit is contained in:
Michael Cho 2024-03-10 20:20:34 -04:00
parent ae0ceee74f
commit 2d884981c2
No known key found for this signature in database
GPG Key ID: 55E85E28A7CD1E85
3 changed files with 10 additions and 3 deletions

View File

@ -15,11 +15,13 @@ class Cleaner
include Context include Context
# Create a cleaner for the given formula. # Create a cleaner for the given formula.
sig { params(formula: Formula).void }
def initialize(formula) def initialize(formula)
@formula = formula @formula = formula
end end
# Clean the keg of the formula. # Clean the keg of the formula.
sig { void }
def clean def clean
ObserverPathnameExtension.reset_counts! ObserverPathnameExtension.reset_counts!
@ -48,8 +50,7 @@ class Cleaner
# [1]: https://github.com/Homebrew/brew/pull/11597 # [1]: https://github.com/Homebrew/brew/pull/11597
# [2]: https://github.com/Homebrew/homebrew-core/issues/100190 # [2]: https://github.com/Homebrew/homebrew-core/issues/100190
# [3]: https://github.com/Homebrew/brew/pull/13215 # [3]: https://github.com/Homebrew/brew/pull/13215
Dir.glob(@formula.info/"**/dir").each do |file| @formula.info.glob("**/dir").each do |info_dir_file|
info_dir_file = Pathname(file)
next unless info_dir_file.file? next unless info_dir_file.file?
next if info_dir_file == @formula.info/@formula.name/"dir" next if info_dir_file == @formula.info/@formula.name/"dir"
next if @formula.skip_clean?(info_dir_file) next if @formula.skip_clean?(info_dir_file)
@ -65,6 +66,7 @@ class Cleaner
private private
sig { params(path: Pathname).void }
def observe_file_removal(path) def observe_file_removal(path)
path.extend(ObserverPathnameExtension).unlink if path.exist? path.extend(ObserverPathnameExtension).unlink if path.exist?
end end
@ -72,6 +74,7 @@ class Cleaner
# Removes any empty directories in the formula's prefix subtree # Removes any empty directories in the formula's prefix subtree
# Keeps any empty directories protected by skip_clean # Keeps any empty directories protected by skip_clean
# Removes any unresolved symlinks # Removes any unresolved symlinks
sig { void }
def prune def prune
dirs = [] dirs = []
symlinks = [] symlinks = []
@ -100,6 +103,7 @@ class Cleaner
end end
end end
sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path) def executable_path?(path)
path.text_executable? || path.executable? path.text_executable? || path.executable?
end end
@ -119,6 +123,7 @@ class Cleaner
# #
# lib may have a large directory tree (see Erlang for instance), and # lib may have a large directory tree (see Erlang for instance), and
# clean_dir applies cleaning rules to the entire tree # clean_dir applies cleaning rules to the entire tree
sig { params(directory: Pathname).void }
def clean_dir(directory) def clean_dir(directory)
directory.find do |path| directory.find do |path|
path.extend(ObserverPathnameExtension) path.extend(ObserverPathnameExtension)
@ -147,6 +152,7 @@ class Cleaner
end end
end end
sig { void }
def rewrite_shebangs def rewrite_shebangs
require "language/perl" require "language/perl"
require "utils/shebang" require "utils/shebang"

View File

@ -4,7 +4,7 @@
class Cleaner class Cleaner
private private
sig { params(path: Pathname).returns(T.nilable(T::Boolean)) } sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path) def executable_path?(path)
path.elf? || path.text_executable? path.elf? || path.text_executable?
end end

View File

@ -6,6 +6,7 @@ class Cleaner
undef executable_path? undef executable_path?
sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path) def executable_path?(path)
path.mach_o_executable? || path.text_executable? path.mach_o_executable? || path.text_executable?
end end