Skip to content

Commit

Permalink
linkage_checker: add broken_linkage_allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Sep 3, 2024
1 parent fafa618 commit cb96fbc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Library/Homebrew/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ def dylib_to_dep(dylib)
Regexp.last_match(2)
end

sig { params(file: Pathname).returns(T::Boolean) }
def broken_linkage_allowed?(file)
@broken_linkage_allowed ||= case (allowed = formula.tap&.audit_exception(:broken_linkage_allowlist, formula.name))
when String
[allowed]
when Array
allowed
else
[]
end
glob_flags = File::FNM_DOTMATCH | File::FNM_EXTGLOB | File::FNM_PATHNAME
@broken_linkage_allowed.any? { |pattern| file.fnmatch?("#{formula.prefix.realpath}/#{pattern}", glob_flags) }

Check warning on line 106 in Library/Homebrew/linkage_checker.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/linkage_checker.rb#L105-L106

Added lines #L105 - L106 were not covered by tests
end

def check_dylibs(rebuild_cache:)
keg_files_dylibs = nil

Expand Down Expand Up @@ -128,7 +142,7 @@ def check_dylibs(rebuild_cache:)
if !file_has_any_rpath_dylibs && (dylib.start_with? "@rpath/")
file_has_any_rpath_dylibs = true
pathname = Pathname(file)
@files_missing_rpaths << file if pathname.rpaths.empty?
@files_missing_rpaths << file if pathname.rpaths.empty? && !broken_linkage_allowed?(pathname)
end

next if checked_dylibs.include? dylib
Expand Down Expand Up @@ -156,7 +170,7 @@ def check_dylibs(rebuild_cache:)
# If we cannot associate the dylib with a dependency, then it may be a system library.
# If dlopen finds the dylib, then the linkage is not broken.
@system_dylibs << dylib
elsif !system_framework?(dylib)
elsif !system_framework?(dylib) && !broken_linkage_allowed?(Pathname(file))
@broken_dylibs << dylib
end
else
Expand Down

0 comments on commit cb96fbc

Please sign in to comment.