Skip to content

Commit 34f659c

Browse files
committed
cask/audit: iterate over artifacts in rosetta/signing audit
1 parent dbe68ef commit 34f659c

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

Library/Homebrew/cask/audit.rb

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ def audit_signing
505505
extract_artifacts do |artifacts, tmpdir|
506506
is_container = artifacts.any? { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Pkg) }
507507

508-
artifacts.each do |artifact|
509-
next if artifact.is_a?(Artifact::Binary) && is_container == true
508+
any_signing_failure = artifacts.any? do |artifact|
509+
next false if artifact.is_a?(Artifact::Binary) && is_container == true
510510

511511
artifact_path = artifact.is_a?(Artifact::Pkg) ? artifact.path : artifact.source
512512

@@ -521,28 +521,32 @@ def audit_signing
521521
system_command("gktool", args: ["scan", path], print_stderr: false)
522522
when Artifact::Binary
523523
# Shell scripts cannot be signed, so we skip them
524-
next if path.text_executable?
524+
next false if path.text_executable?
525525

526526
system_command("codesign", args: ["--verify", "-R=notarized", "--check-notarization", path],
527527
print_stderr: false)
528528
else
529529
add_error "Unknown artifact type: #{artifact.class}", location: url.location
530530
end
531531

532-
if result.success? && cask.deprecated? && cask.deprecation_reason == :unsigned
533-
add_error "Cask is deprecated as unsigned but artifacts are signed!"
534-
end
535-
536-
next if cask.deprecated? && cask.deprecation_reason == :unsigned
537-
538-
next if result.success?
532+
next false if result.success?
533+
next true if cask.deprecated? && cask.deprecation_reason == :unsigned
539534

540535
add_error <<~EOS, location: url.location
541536
Signature verification failed:
542537
#{result.merged_output}
543538
macOS on ARM requires software to be signed.
544539
Please contact the upstream developer to let them know they should sign and notarize their software.
545540
EOS
541+
542+
true
543+
end
544+
545+
if cask.deprecated? && cask.deprecation_reason == :unsigned && !any_signing_failure
546+
add_error <<~EOS
547+
Cask is deprecated as unsigned but all artifacts are signed!
548+
Remove the deprecate/disable stanza or update the deprecate/disable reason.
549+
EOS
546550
end
547551
end
548552
end
@@ -640,9 +644,12 @@ def audit_rosetta
640644
extract_artifacts do |artifacts, tmpdir|
641645
is_container = artifacts.any? { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Pkg) }
642646

643-
artifacts.each do |artifact|
644-
next if !artifact.is_a?(Artifact::App) && !artifact.is_a?(Artifact::Binary)
645-
next if artifact.is_a?(Artifact::Binary) && is_container
647+
mentions_rosetta = cask.caveats.include?("requires Rosetta 2")
648+
requires_intel = cask.depends_on.arch&.any? { |arch| arch[:type] == :intel }
649+
650+
any_requires_rosetta = artifacts.any? do |artifact|
651+
next false if !artifact.is_a?(Artifact::App) && !artifact.is_a?(Artifact::Binary)
652+
next false if artifact.is_a?(Artifact::Binary) && is_container
646653

647654
path = tmpdir/artifact.source.relative_path_from(cask.staged_path)
648655

@@ -665,7 +672,7 @@ def audit_rosetta
665672
end
666673

667674
# binary stanza can contain shell scripts, so we just continue if lipo fails.
668-
next unless result.success?
675+
next false unless result.success?
669676

670677
odebug "Architectures: #{result.merged_output}"
671678

@@ -675,17 +682,17 @@ def audit_rosetta
675682
next
676683
end
677684

678-
supports_arm = result.merged_output.include?("arm64")
679-
mentions_rosetta = cask.caveats.include?("requires Rosetta 2")
680-
requires_intel = cask.depends_on.arch&.any? { |arch| arch[:type] == :intel }
685+
next true if result.merged_output.exclude?("arm64") && result.merged_output.include?("x86_64")
686+
end
681687

682-
if supports_arm && mentions_rosetta
683-
add_error "Artifacts do not require Rosetta 2 but the caveats say otherwise!",
684-
location: url.location
685-
elsif !supports_arm && !mentions_rosetta && !requires_intel
686-
add_error "Artifacts require Rosetta 2 but this is not indicated by the caveats!",
688+
if any_requires_rosetta
689+
if !mentions_rosetta && !requires_intel
690+
add_error "At least one artifact requires Rosetta 2 but this is not indicated by the caveats!",
687691
location: url.location
688692
end
693+
elsif mentions_rosetta
694+
add_error "No artifacts require Rosetta 2 but the caveats say otherwise!",
695+
location: url.location
689696
end
690697
end
691698
end

0 commit comments

Comments
 (0)