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

feat: check if casks should warn about rosetta #17573

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
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 @@
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