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 5fc3af1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,48 @@ def extract_artifacts
yield artifacts, @tmpdir if block_given?
end

sig { void }
def audit_rosetta
return unless online?
return if Homebrew::SimulateSystem.current_arch != :arm

odebug "Auditing Rosetta 2 requirement"

Check warning on line 570 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L570

Added line #L570 was not covered by tests

extract_artifacts do |artifacts, tmpdir|
artifacts.filter { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Binary) }

Check warning on line 573 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L572-L573

Added lines #L572 - L573 were not covered by tests
.each do |artifact|
path = tmpdir/artifact.source.relative_path_from(cask.staged_path)

Check warning on line 575 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L575

Added line #L575 was not covered by tests

result = case artifact

Check warning on line 577 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L577

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

Check warning on line 581 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L581

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

Check warning on line 590 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L590

Added line #L590 was not covered by tests
end

supports_arm = result.merged_output.include?("arm64")
mentions_rosetta = cask.caveats.include?("requires Rosetta 2")

Check warning on line 594 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L593-L594

Added lines #L593 - L594 were not covered by tests

if supports_arm && mentions_rosetta

Check warning on line 596 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L596

Added line #L596 was not covered by tests
add_error "Artifacts does not require Rosetta 2 but the caveats say otherwise!",
location: cask.url.location
elsif !supports_arm && !mentions_rosetta
add_error "Artifacts require Rosetta 2 but this is not indicated by the caveats!",
location: cask.url.location
end
end
end
end

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

0 comments on commit 5fc3af1

Please sign in to comment.