Skip to content

Commit

Permalink
Merge pull request #16944 from cho-m/mismatched_binary_allowlist-gran…
Browse files Browse the repository at this point in the history
…ular-globs

formula_cellar_checks: more granular mismatched_binary_allowlist
  • Loading branch information
MikeMcQuaid authored Mar 24, 2024
2 parents 9a1793a + a5160e3 commit 92a4311
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Library/Homebrew/formula_cellar_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def check_cpuid_instruction(formula)
"No `cpuid` instruction detected. #{formula} should not use `ENV.runtime_cpu_detection`."
end

sig { params(formula: Formula).returns(T.nilable(String)) }
def check_binary_arches(formula)
return unless formula.prefix.directory?

Expand All @@ -347,19 +348,31 @@ def check_binary_arches(formula)

compatible_universal_binaries, mismatches = mismatches.partition do |file, arch|
arch == :universal && file.archs.include?(Hardware::CPU.arch)
end.map(&:to_h) # To prevent transformation into nested arrays
end
# To prevent transformation into nested arrays
compatible_universal_binaries = compatible_universal_binaries.to_h
mismatches = mismatches.to_h

universal_binaries_expected = if formula.tap.present? && formula.tap.core_tap?
formula.tap.audit_exception(:universal_binary_allowlist, formula.name)
universal_binaries_expected = if (formula_tap = formula.tap).present? && formula_tap.core_tap?
formula_tap.audit_exception(:universal_binary_allowlist, formula.name)
else
true
end
return if T.must(mismatches).empty? && universal_binaries_expected

mismatches_expected = formula.tap.blank? ||
formula.tap.audit_exception(:mismatched_binary_allowlist, formula.name)
return if T.must(compatible_universal_binaries).empty? && mismatches_expected
mismatches_expected = (formula_tap = formula.tap).blank? ||
formula_tap.audit_exception(:mismatched_binary_allowlist, formula.name)
mismatches_expected = [mismatches_expected] if mismatches_expected.is_a?(String)
if mismatches_expected.is_a?(Array)
glob_flags = File::FNM_DOTMATCH | File::FNM_EXTGLOB | File::FNM_PATHNAME
mismatches.delete_if do |file, _arch|
mismatches_expected.any? { |pattern| file.fnmatch?("#{formula.prefix.realpath}/#{pattern}", glob_flags) }
end
mismatches_expected = false
return if mismatches.empty? && compatible_universal_binaries.empty?
end

return if mismatches.empty? && universal_binaries_expected
return if compatible_universal_binaries.empty? && mismatches_expected
return if universal_binaries_expected && mismatches_expected

s = ""
Expand Down

0 comments on commit 92a4311

Please sign in to comment.