Skip to content

Commit c161409

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

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

Library/Homebrew/cask/audit.rb

Lines changed: 27 additions & 21 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,21 +521,16 @@ 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:
@@ -544,6 +539,13 @@ def audit_signing
544539
Please contact the upstream developer to let them know they should sign and notarize their software.
545540
EOS
546541
end
542+
543+
if cask.deprecated? && cask.deprecation_reason == :unsigned && !any_signing_failure
544+
add_error <<~EOS
545+
Cask is deprecated as unsigned but all artifacts are signed!
546+
Remove the deprecate/disable stanza or update the deprecate/disable reason.
547+
EOS
548+
end
547549
end
548550
end
549551

@@ -640,9 +642,12 @@ def audit_rosetta
640642
extract_artifacts do |artifacts, tmpdir|
641643
is_container = artifacts.any? { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Pkg) }
642644

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
645+
mentions_rosetta = cask.caveats.include?("requires Rosetta 2")
646+
requires_intel = cask.depends_on.arch&.any? { |arch| arch[:type] == :intel }
647+
648+
any_requires_rosetta = artifacts.any? do |artifact|
649+
next false if !artifact.is_a?(Artifact::App) && !artifact.is_a?(Artifact::Binary)
650+
next false if artifact.is_a?(Artifact::Binary) && is_container
646651

647652
path = tmpdir/artifact.source.relative_path_from(cask.staged_path)
648653

@@ -665,7 +670,7 @@ def audit_rosetta
665670
end
666671

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

670675
odebug "Architectures: #{result.merged_output}"
671676

@@ -676,16 +681,17 @@ def audit_rosetta
676681
end
677682

678683
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 }
684+
next true if !supports_arm && result.merged_output.include?("x86_64")
685+
end
681686

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!",
687+
if any_requires_rosetta
688+
if !mentions_rosetta && !requires_intel
689+
add_error "At least one artifact requires Rosetta 2 but this is not indicated by the caveats!",
687690
location: url.location
688691
end
692+
elsif mentions_rosetta
693+
add_error "No artifacts require Rosetta 2 but the caveats say otherwise!",
694+
location: url.location
689695
end
690696
end
691697
end

0 commit comments

Comments
 (0)