Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula_cellar_checks: more granular mismatched_binary_allowlist #16944

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@

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) }

Check warning on line 368 in Library/Homebrew/formula_cellar_checks.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_cellar_checks.rb#L367-L368

Added lines #L367 - L368 were not covered by tests
end
mismatches_expected = false

Check warning on line 370 in Library/Homebrew/formula_cellar_checks.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_cellar_checks.rb#L370

Added line #L370 was not covered by tests
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