Skip to content

Commit

Permalink
Merge pull request #16873 from cho-m/cleaner-types
Browse files Browse the repository at this point in the history
cleaner: add types
  • Loading branch information
reitermarkus committed Mar 11, 2024
2 parents a30f6c4 + 2d88498 commit 780fbbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Library/Homebrew/cleaner.rb
Expand Up @@ -15,11 +15,13 @@ class Cleaner
include Context

# Create a cleaner for the given formula.
sig { params(formula: Formula).void }
def initialize(formula)
@formula = formula
end

# Clean the keg of the formula.
sig { void }
def clean
ObserverPathnameExtension.reset_counts!

Expand Down Expand Up @@ -48,8 +50,7 @@ def clean
# [1]: https://github.com/Homebrew/brew/pull/11597
# [2]: https://github.com/Homebrew/homebrew-core/issues/100190
# [3]: https://github.com/Homebrew/brew/pull/13215
Dir.glob(@formula.info/"**/dir").each do |file|
info_dir_file = Pathname(file)
@formula.info.glob("**/dir").each do |info_dir_file|
next unless info_dir_file.file?
next if info_dir_file == @formula.info/@formula.name/"dir"
next if @formula.skip_clean?(info_dir_file)
Expand All @@ -65,13 +66,15 @@ def clean

private

sig { params(path: Pathname).void }
def observe_file_removal(path)
path.extend(ObserverPathnameExtension).unlink if path.exist?
end

# Removes any empty directories in the formula's prefix subtree
# Keeps any empty directories protected by skip_clean
# Removes any unresolved symlinks
sig { void }
def prune
dirs = []
symlinks = []
Expand Down Expand Up @@ -100,6 +103,7 @@ def prune
end
end

sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.text_executable? || path.executable?
end
Expand All @@ -119,6 +123,7 @@ def executable_path?(path)
#
# lib may have a large directory tree (see Erlang for instance), and
# clean_dir applies cleaning rules to the entire tree
sig { params(directory: Pathname).void }
def clean_dir(directory)
directory.find do |path|
path.extend(ObserverPathnameExtension)
Expand Down Expand Up @@ -147,6 +152,7 @@ def clean_dir(directory)
end
end

sig { void }
def rewrite_shebangs
require "language/perl"
require "utils/shebang"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/linux/cleaner.rb
Expand Up @@ -4,7 +4,7 @@
class Cleaner
private

sig { params(path: Pathname).returns(T.nilable(T::Boolean)) }
sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.elf? || path.text_executable?
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/extend/os/mac/cleaner.rb
Expand Up @@ -6,6 +6,7 @@ class Cleaner

undef executable_path?

sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
Expand Down

0 comments on commit 780fbbc

Please sign in to comment.