Skip to content

Commit b0dc02e

Browse files
committed
fetch: add --all-platforms switch
- Iterate `[:macos, :linux] × [:intel, :arm]` (4 combos) for verifying multi-platform cask URLs and checksums in a single command, instead of `--os=all --arch=all` which iterates every macOS codename. - Tolerate `CaskInvalidError`/`CaskUnreadableError` during multi-combo fetches for casks that legitimately omit some platforms (mirrors the `bump-cask-pr.rb` rescue pattern). Signed-off-by: Patrick Linnane <patrick@linnane.io>
1 parent 0b7a7c7 commit b0dc02e

8 files changed

Lines changed: 30 additions & 6 deletions

File tree

Library/Homebrew/cli/args.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def only_formula_or_cask
126126

127127
sig { returns(T::Array[[Symbol, Symbol]]) }
128128
def os_arch_combinations
129+
return OnSystem::BASE_OS_OPTIONS.product(OnSystem::ARCH_OPTIONS) if @table[:all_platforms?]
130+
129131
skip_invalid_combinations = false
130132

131133
oses = case (os_sym = @table[:os]&.to_sym)

Library/Homebrew/cmd/fetch.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class FetchCmd < AbstractCommand
2525
flag "--arch=",
2626
description: "Download for the given CPU architecture. " \
2727
"(Pass `all` to download for all architectures.)"
28+
switch "--all-platforms",
29+
description: "Download for every supported OS and CPU architecture combination."
2830
flag "--bottle-tag=",
2931
description: "Download a bottle for given tag."
3032
switch "--HEAD",
@@ -65,6 +67,9 @@ class FetchCmd < AbstractCommand
6567
conflicts "--formula", "--cask"
6668
conflicts "--os", "--bottle-tag"
6769
conflicts "--arch", "--bottle-tag"
70+
conflicts "--all-platforms", "--os"
71+
conflicts "--all-platforms", "--arch"
72+
conflicts "--all-platforms", "--bottle-tag"
6873

6974
named_args [:formula, :cask], min: 1
7075
end
@@ -160,9 +165,13 @@ def run
160165

161166
os_arch_combinations.each do |os, arch|
162167
SimulateSystem.with(os:, arch:) do
163-
cask = Cask::CaskLoader.load(ref)
168+
loaded_cask = begin
169+
Cask::CaskLoader.load(ref)
170+
rescue Cask::CaskInvalidError, Cask::CaskUnreadableError
171+
raise unless cask.on_system_blocks_exist?
172+
end
164173

165-
if cask.url.nil? || cask.sha256.nil?
174+
if loaded_cask.nil? || loaded_cask.url.nil? || loaded_cask.sha256.nil?
166175
opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}"
167176
next
168177
end
@@ -171,7 +180,7 @@ def run
171180
quarantine = true if quarantine.nil?
172181

173182
download = Cask::Download.new(
174-
cask,
183+
loaded_cask,
175184
quarantine:,
176185
require_sha: Homebrew::EnvConfig.cask_opts_require_sha?,
177186
)

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

completions/bash/brew

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ _brew_fetch() {
14531453
-*)
14541454
__brewcomp "
14551455
--HEAD
1456+
--all-platforms
14561457
--arch
14571458
--bottle-tag
14581459
--build-bottle

completions/fish/brew.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ __fish_brew_complete_arg 'extract' -a '(__fish_brew_suggest_taps_installed)'
974974

975975
__fish_brew_complete_cmd 'fetch' 'Download a bottle (if available) or source packages for formulae and binaries for casks'
976976
__fish_brew_complete_arg 'fetch' -l HEAD -d 'Fetch HEAD version instead of stable version'
977+
__fish_brew_complete_arg 'fetch' -l all-platforms -d 'Download for every supported OS and CPU architecture combination'
977978
__fish_brew_complete_arg 'fetch' -l arch -d 'Download for the given CPU architecture. (Pass `all` to download for all architectures.)'
978979
__fish_brew_complete_arg 'fetch' -l bottle-tag -d 'Download a bottle for given tag'
979980
__fish_brew_complete_arg 'fetch' -l build-bottle -d 'Download source packages (for eventual bottling) rather than a bottle'

completions/zsh/_brew

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,16 +1274,17 @@ _brew_extract() {
12741274
_brew_fetch() {
12751275
_arguments \
12761276
'(--cask)--HEAD[Fetch HEAD version instead of stable version]' \
1277-
'(--bottle-tag)--arch[Download for the given CPU architecture. (Pass `all` to download for all architectures.)]' \
1278-
'(--build-from-source --build-bottle --force-bottle --cask --os --arch)--bottle-tag[Download a bottle for given tag]' \
1277+
'(--os --arch --bottle-tag)--all-platforms[Download for every supported OS and CPU architecture combination]' \
1278+
'(--bottle-tag --all-platforms)--arch[Download for the given CPU architecture. (Pass `all` to download for all architectures.)]' \
1279+
'(--build-from-source --build-bottle --force-bottle --cask --os --arch --all-platforms)--bottle-tag[Download a bottle for given tag]' \
12791280
'(--build-from-source --force-bottle --bottle-tag --cask)--build-bottle[Download source packages (for eventual bottling) rather than a bottle]' \
12801281
'(--build-bottle --force-bottle --bottle-tag)--build-from-source[Download source packages rather than a bottle]' \
12811282
'--debug[Display any debugging information]' \
12821283
'(--cask)--deps[Also download dependencies for any listed formula]' \
12831284
'--force[Remove a previously cached version and re-fetch]' \
12841285
'(--build-from-source --build-bottle --bottle-tag --cask)--force-bottle[Download a bottle if it exists for the current or newest version of macOS, even if it would not be used during installation]' \
12851286
'--help[Show this message]' \
1286-
'(--bottle-tag)--os[Download for the given operating system. (Pass `all` to download for all operating systems.)]' \
1287+
'(--bottle-tag --all-platforms)--os[Download for the given operating system. (Pass `all` to download for all operating systems.)]' \
12871288
'--quiet[Make some output more quiet]' \
12881289
'--retry[Retry if downloading fails or re-download if the checksum of a previously cached version no longer matches. Tries at most 5 times with exponential backoff]' \
12891290
'--verbose[Do a verbose VCS checkout, if the URL represents a VCS. This is useful for seeing if an existing VCS cache has been updated]' \

docs/Manpage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,10 @@ binaries for *`cask`*s. For files, also print SHA-256 checksums.
993993
: Download for the given CPU architecture. (Pass `all` to download for all
994994
architectures.)
995995

996+
`--all-platforms`
997+
998+
: Download for every supported OS and CPU architecture combination.
999+
9961000
`--bottle-tag`
9971001

9981002
: Download a bottle for given tag.

manpages/brew.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ Download for the given operating system\. (Pass \fBall\fP to download for all op
650650
\fB\-\-arch\fP
651651
Download for the given CPU architecture\. (Pass \fBall\fP to download for all architectures\.)
652652
.TP
653+
\fB\-\-all\-platforms\fP
654+
Download for every supported OS and CPU architecture combination\.
655+
.TP
653656
\fB\-\-bottle\-tag\fP
654657
Download a bottle for given tag\.
655658
.TP

0 commit comments

Comments
 (0)