Skip to content

Commit

Permalink
feat: check if casks should warn about rosetta
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Jun 27, 2024
1 parent d293ac1 commit e681f60
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,42 @@ def extract_artifacts
yield artifacts, @tmpdir if block_given?
end

sig { void }
def audit_rosetta
return unless online?

odebug "Auditing rosetta requirement"

return unless Homebrew::SimulateSystem.current_arch == :arm

extract_artifacts do |artifacts, tmpdir|
artifacts.filter { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Binary) }.each do |artifact|
path = tmpdir/artifact.source.relative_path_from(cask.staged_path)

result = case artifact
when Artifact::App
files = Dir[path/"Contents/MacOS/*"]
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)
when Artifact::Binary
system_command("lipo", args: ["-archs", path], print_stderr: false)
else
add_error "Unknown artifact type: #{artifact.class}", location: cask.url.location
end

unless result.success?
add_error "Failed to determine artifact architecture!", location: cask.url.location
next
end

next if result.merged_output.include?("arm64")
next if cask.caveats.include? "requires Rosetta 2"

add_error "Artifacts require Rosetta but this is not indicated by the caveats!", location: cask.url.location
end
end
end

sig { returns(T.any(NilClass, T::Boolean, Symbol)) }
def audit_livecheck_version
return unless online?
Expand Down

0 comments on commit e681f60

Please sign in to comment.