Skip to content

fetch: add --all-platforms to fetch every variant#22426

Merged
MikeMcQuaid merged 2 commits into
Homebrew:mainfrom
p-linnane:fetch-all-platforms
May 29, 2026
Merged

fetch: add --all-platforms to fetch every variant#22426
MikeMcQuaid merged 2 commits into
Homebrew:mainfrom
p-linnane:fetch-all-platforms

Conversation

@p-linnane
Copy link
Copy Markdown
Member

@p-linnane p-linnane commented May 27, 2026

brew fetch --cask --all-platforms <cask> downloads every supported variant of a cask in one command, to verify that all URLs resolve and checksums match without manually iterating --os/--arch.

It iterates the full OS/arch matrix (every macOS version × arm/intel, plus Linux) and each language block, then downloads each distinct URL once (many combinations resolve to the same file). This covers casks whose URL varies by macOS version — e.g. itsycal resolves to 0.14.1 on Catalina and 0.15.12 on Big Sur and newer — not just a fixed set of platform corners.

Notes:

  • --all-platforms is equivalent to --os=all --arch=all and reuses the existing os_arch_combinations machinery, so it also works for <formula>e (fetching every bottle); the language and distinct-URL handling are cask-specific.
  • Under --all-platforms, a cask without on_system blocks resolves identically everywhere, so it collapses to a single combination (existing --os=all/--arch=all behaviour is unchanged).
  • Casks that legitimately omit some platforms (e.g. an on_linux block with only x86_64_linux) are tolerated rather than raising, mirroring the bump-cask-pr rescue pattern.
  • OS/arch cannot be simulated for casks loaded from the API, so an opoo points to HOMEBREW_NO_INSTALL_FROM_API (languages are unaffected). This matches the pre-existing behaviour of --os=all --arch=all.
  • Profiling note: cask reloading under simulation is ~1 ms each; the dominant cost is one curl --head redirect resolution per unique URL, inherent to resolving a download's cached filename.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR.

AI (Claude Code) assisted with the implementation and this description. The cask iteration is extracted into a cask_downloads helper with unit tests asserting the distinct-URL set (sha256-os → 4 URLs) and the single-combination collapse (local-caffeine → 1). Verified locally: brew lgtm passes, and the full-matrix + language iteration resolves the expected distinct URLs for source casks (itsycal → 2 macOS-version URLs, git-credential-manager → 4 of 15 combinations, firefox → 102 language URLs); API-loaded casks emit the warning.


Copilot AI review requested due to automatic review settings May 27, 2026 02:00
@p-linnane p-linnane force-pushed the fetch-all-platforms branch from 08c63fe to b0dc02e Compare May 27, 2026 02:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --all-platforms switch to brew fetch that expands os_arch_combinations to the 4 base [:macos, :linux] × [:intel, :arm] combos (vs. the ~24 expanded by --os=all --arch=all), primarily as a shorthand for verifying multi-platform cask URLs/SHAs. Also makes the cask iteration tolerant of CaskInvalidError / CaskUnreadableError when the original cask uses on_system blocks, mirroring the existing rescue pattern in bump-cask-pr.

Changes:

  • New --all-platforms switch on brew fetch, conflicting with --os, --arch, and --bottle-tag.
  • Shared Args#os_arch_combinations short-circuits to BASE_OS_OPTIONS × ARCH_OPTIONS when --all-platforms is set.
  • Cask loop renames the inner reloaded cask to loaded_cask, rescues invalid/unreadable cask errors for system-block casks, and skips combos that produce a nil reload.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/cmd/fetch.rb Adds the switch, conflict declarations, and the rescue/loaded_cask handling in the cask iteration.
Library/Homebrew/cli/args.rb Adds the --all-platforms short-circuit in the shared os_arch_combinations helper.
Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi Regenerated DSL RBI exposing all_platforms? on FetchCmd::Args.
Files not reviewed (1)
  • Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/cmd/fetch.rb Outdated
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, thanks!

Adds a --all-platforms switch to brew fetch that iterates [:macos, :linux] × [:intel, :arm] (four combos), as a shorthand for verifying multi-platform cask URLs and SHA-256 checksums in a single command. --os=all --arch=all already exists but iterates every macOS codename (~24 combos), which is excessive when cask URLs typically don't vary by macOS version.

This feels like a bit of a potential footgun in future.

I think this should handle the case where cask URLs do vary by the macOS version and do something along the lines of e.g. getting each possible variant of the URL across all potential platforms and trying to download the unique URLs that result. May want/need to handle languages as part of this too.

If the system simulation part of this is too slow over all the possible combos: would be good to profile and speed that up as it shouldn't need to be.

I think --all would be an acceptable shorthand for this, too.

@p-linnane p-linnane force-pushed the fetch-all-platforms branch from fdd9806 to 0bfdc8c Compare May 28, 2026 22:45
@p-linnane p-linnane changed the title fetch: add --all-platforms switch fetch: add --all-platforms to fetch every cask variant May 28, 2026
@p-linnane p-linnane requested a review from Copilot May 28, 2026 22:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi: Language not supported

Comment thread Library/Homebrew/cmd/fetch.rb Outdated
Comment thread Library/Homebrew/cmd/fetch.rb Outdated
Comment thread Library/Homebrew/cmd/fetch.rb Outdated
Comment thread Library/Homebrew/cmd/fetch.rb Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi: Language not supported

Comment thread Library/Homebrew/cmd/fetch.rb Outdated
Comment thread Library/Homebrew/cmd/fetch.rb
@p-linnane p-linnane force-pushed the fetch-all-platforms branch from c727501 to d2e81ea Compare May 28, 2026 23:49
- Iterate the full OS/arch matrix plus each `language` for
  `--all-platforms`, downloading each distinct URL once. This covers
  per-macOS-version URL variants, not just a fixed set of corners.
- Collapse to a single combination for casks without `on_system`
  blocks, since they resolve identically on every platform.
- Tolerate `CaskInvalidError`/`CaskUnreadableError` for casks that omit
  some platforms (mirrors the `bump-cask-pr.rb` rescue pattern).
- Warn when a cask is loaded from the API, since OS/arch cannot be
  simulated without the source.

Signed-off-by: Patrick Linnane <patrick@linnane.io>
@p-linnane p-linnane force-pushed the fetch-all-platforms branch from d2e81ea to 6de4649 Compare May 28, 2026 23:53
@p-linnane p-linnane changed the title fetch: add --all-platforms to fetch every cask variant fetch: add --all-platforms to fetch every variant May 28, 2026
@p-linnane
Copy link
Copy Markdown
Member Author

@MikeMcQuaid This should be good to go based off your feedback and some help from Copilot. Would like you to do another review since there was a decent amount of changes.

@p-linnane p-linnane requested a review from MikeMcQuaid May 28, 2026 23:59
Comment thread Library/Homebrew/cli/args.rb Outdated
Comment thread Library/Homebrew/cli/args.rb Outdated
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MikeMcQuaid MikeMcQuaid enabled auto-merge May 29, 2026 07:32
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 29, 2026
Merged via the queue into Homebrew:main with commit 50b8a98 May 29, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants