From 8814a492aaa34b70b52c44e92cd01ee76da098b1 Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Wed, 21 Aug 2024 09:50:15 +0200 Subject: [PATCH] Use plist main binary for Rosetta audit Currently `brew audit` only audits the first binary in a cask. For example the cask `wiso-steuer-2024` contains multiple binaries in `Contents/MacOS`: - `btssysteminfo` - `whilfe` - `wmain24` The first binary (some telemetry tool) is not the main binary and not a universal binary, but the other two are. Given that `wmain24` is defined as the main binary in the `Contents/Info.plist`, brew probably should audit that binary rather than just checking the first one. --- Library/Homebrew/cask/audit.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index e903d558de..23ee6c9748 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -574,7 +574,11 @@ module Cask File.executable?(f) && !File.directory?(f) && !f.end_with?(".dylib") end add_error "No binaries in App: #{artifact.source}", location: cask.url.location if files.empty? - system_command("lipo", args: ["-archs", files.first], print_stderr: false) + + main_binary = get_plist_main_binary(path) + main_binary ||= files.first + + system_command("lipo", args: ["-archs", main_binary], print_stderr: false) when Artifact::Binary binary_path = path.to_s.gsub(cask.appdir, tmpdir) system_command("lipo", args: ["-archs", binary_path], print_stderr: true) @@ -739,6 +743,17 @@ module Cask end end + sig { params(path: Pathname).returns(T.nilable(String)) } + def get_plist_main_binary(path) + return unless online? + + plist_path = "#{path}/Contents/Info.plist" + return unless File.exist?(plist_path) + + plist = system_command!("plutil", args: ["-convert", "xml1", "-o", "-", plist_path]).plist + plist["CFBundleExecutable"].presence + end + sig { void } def audit_github_prerelease_version odebug "Auditing GitHub prerelease"