fetch: add --all-platforms to fetch every variant#22426
Conversation
08c63fe to
b0dc02e
Compare
There was a problem hiding this comment.
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-platformsswitch onbrew fetch, conflicting with--os,--arch, and--bottle-tag. - Shared
Args#os_arch_combinationsshort-circuits toBASE_OS_OPTIONS × ARCH_OPTIONSwhen--all-platformsis 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 anilreload.
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.
9ba2c09 to
fdd9806
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
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.
fdd9806 to
0bfdc8c
Compare
--all-platforms to fetch every cask variant
0bfdc8c to
c727501
Compare
c727501 to
d2e81ea
Compare
- 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>
d2e81ea to
6de4649
Compare
--all-platforms to fetch every cask variant--all-platforms to fetch every variant
|
@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. |
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
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 eachlanguageblock, then downloads each distinct URL once (many combinations resolve to the same file). This covers casks whose URL varies by macOS version — e.g.itsycalresolves to0.14.1on Catalina and0.15.12on Big Sur and newer — not just a fixed set of platform corners.Notes:
--all-platformsis equivalent to--os=all --arch=alland reuses the existingos_arch_combinationsmachinery, so it also works for<formula>e (fetching every bottle); thelanguageand distinct-URL handling are cask-specific.--all-platforms, a cask withouton_systemblocks resolves identically everywhere, so it collapses to a single combination (existing--os=all/--arch=allbehaviour is unchanged).on_linuxblock with onlyx86_64_linux) are tolerated rather than raising, mirroring thebump-cask-prrescue pattern.opoopoints toHOMEBREW_NO_INSTALL_FROM_API(languages are unaffected). This matches the pre-existing behaviour of--os=all --arch=all.curl --headredirect resolution per unique URL, inherent to resolving a download's cached filename.brew lgtm(style, typechecking and tests) with your changes locally?AI (Claude Code) assisted with the implementation and this description. The cask iteration is extracted into a
cask_downloadshelper with unit tests asserting the distinct-URL set (sha256-os→ 4 URLs) and the single-combination collapse (local-caffeine→ 1). Verified locally:brew lgtmpasses, 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.