From 8e6731b7c72180edfa090d5752f1a9bb385aa511 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 23 Jul 2021 11:40:01 +0800 Subject: [PATCH] formula_cellar_checks: show mismatched arch in `check_binary_arches` This will make the error more informative by showing the architecture a binary was built for along with the error message. Before: foo: * Binaries built for an incompatible architecture were installed into foo's prefix. The offending files are: /usr/local/Cellar/foo/1.0/lib/libbar.dylib /usr/local/Cellar/foo/1.0/lib/libfoo.dylib /usr/local/Cellar/foo/1.0/lib/libincompatible.dylib Unexpected universal binaries were found. The offending files are: /usr/local/Cellar/foo/1.0/lib/liball.dylib /usr/local/Cellar/foo/1.0/lib/libuniversal.dylib After: foo: * Binaries built for a non-native architecture were installed into foo's prefix. The offending files are: /usr/local/Cellar/foo/1.0/lib/libbar.dylib (i386) /usr/local/Cellar/foo/1.0/lib/libfoo.dylib (arm64) /usr/local/Cellar/foo/1.0/lib/libincompatible.dylib (universal) Unexpected universal binaries were found. The offending files are: /usr/local/Cellar/foo/1.0/lib/liball.dylib /usr/local/Cellar/foo/1.0/lib/libuniversal.dylib --- Library/Homebrew/formula_cellar_checks.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index dde65b9769..1ba4a41a7e 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -320,14 +320,16 @@ module FormulaCellarChecks return if !OS.mac? && !OS.linux? keg = Keg.new(formula.prefix) - mismatches = keg.binary_executable_or_library_files.reject do |file| - file.arch == Hardware::CPU.arch + mismatches = {} + keg.binary_executable_or_library_files.each do |file| + farch = file.arch + mismatches[file] = farch unless farch == Hardware::CPU.arch end return if mismatches.empty? - compatible_universal_binaries, mismatches = mismatches.partition do |file| - file.arch == :universal && file.archs.include?(Hardware::CPU.arch) - end + 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 universal_binaries_expected = if formula.tap.present? && formula.tap.core_tap? tap_audit_exception(:universal_binary_allowlist, formula.name) @@ -340,9 +342,9 @@ module FormulaCellarChecks if mismatches.present? s += <<~EOS - Binaries built for an incompatible architecture were installed into #{formula}'s prefix. + Binaries built for a non-native architecture were installed into #{formula}'s prefix. The offending files are: - #{mismatches * "\n "} + #{mismatches.map { |m| "#{m.first}\t(#{m.last})" } * "\n "} EOS end @@ -350,7 +352,7 @@ module FormulaCellarChecks s += <<~EOS Unexpected universal binaries were found. The offending files are: - #{compatible_universal_binaries * "\n "} + #{compatible_universal_binaries.keys * "\n "} EOS end