Skip to content

Commit 6f06afb

Browse files
committed
bump-cask-pr: respect depends_on arch
This reworks the `SimulateSystem` args in the `bump-cask-pr` `replace_version_and_checksum` method to respect `depends_on arch` values in casks. That is to say, we shouldn't simulate Intel for a cask using `depends_on arch: :arm64` and we shouldn't simulate ARM if the cask uses `depends_on arch: :x86_64`. In the process, this refactors how we collect/combine OS/arch values. To make this approach work predictably, I removed the logic that omits OS values matching the host OS (as `SimulateSystem` already handles this). The `[{ os:, arch: }]` hash format only made sense when we were omitting values, so this returns to the previous `[[os, arch]]` array format (to align with the `OnSystem::ALL_OS_ARCH_COMBINATIONS` array format).
1 parent d6da002 commit 6f06afb

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

Library/Homebrew/dev-cmd/bump-cask-pr.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,33 @@ def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
194194
host_is_macos = MacOSVersion::SYMBOLS.include?(host_os)
195195
newest_macos = MacOSVersion::SYMBOLS.keys.first
196196

197+
depends_on_archs = cask.depends_on.arch&.filter_map { |arch| arch[:type] }&.uniq
198+
197199
# NOTE: We substitute the newest macOS (e.g. `:sequoia`) in place of
198200
# `:macos` values (when used), as a generic `:macos` value won't apply
199-
# to on_system blocks referencing macOS versions. We also omit the OS
200-
# when the value aligns with the host.
201-
system_options = if cask.on_system_blocks_exist?
202-
OnSystem::BASE_OS_OPTIONS.each_with_object([]) do |os, array|
203-
OnSystem::ARCH_OPTIONS.each do |arch|
204-
system_hash = { arch: }
205-
system_hash[:os] = os if host_is_macos && os != :macos
206-
system_hash[:os] = newest_macos if !host_is_macos && os == :macos
207-
array << system_hash
201+
# to on_system blocks referencing macOS versions.
202+
os_values = []
203+
arch_values = depends_on_archs.presence || []
204+
if cask.on_system_blocks_exist?
205+
OnSystem::BASE_OS_OPTIONS.each do |os|
206+
os_values << if os == :macos
207+
(host_is_macos ? host_os : newest_macos)
208+
else
209+
os
208210
end
209-
end.uniq
211+
end
212+
213+
arch_values = OnSystem::ARCH_OPTIONS if arch_values.empty?
210214
else
211-
# Architecture is only relevant if on_system blocks are present. When
212-
# not present, we default to ARM for consistency.
213-
system_hash = { arch: :arm }
214-
system_hash[:os] = newest_macos unless host_is_macos
215-
[system_hash]
215+
# Architecture is only relevant if on_system blocks are present or
216+
# the cask uses `depends_on arch`, otherwise we default to ARM for
217+
# consistency.
218+
os_values << (host_is_macos ? host_os : newest_macos)
219+
arch_values << :arm if arch_values.empty?
216220
end
217221

218-
system_options.each do |system_args|
219-
SimulateSystem.with(**system_args) do
222+
os_values.product(arch_values).each do |os, arch|
223+
SimulateSystem.with(os:, arch:) do
220224
# Handle the cask being invalid for specific os/arch combinations
221225
old_cask = begin
222226
Cask::CaskLoader.load(cask.sourcefile_path)
@@ -228,7 +232,7 @@ def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
228232
old_version = old_cask.version
229233
next unless old_version
230234

231-
bump_version = new_version.send(system_args[:arch]) || new_version.general
235+
bump_version = new_version.send(arch) || new_version.general
232236

233237
old_version_regex = old_version.latest? ? ":latest" : %Q(["']#{Regexp.escape(old_version.to_s)}["'])
234238
replacement_pairs << [/version\s+#{old_version_regex}/m,

0 commit comments

Comments
 (0)