Skip to content

Commit 79d5115

Browse files
authored
Merge pull request #19689 from Homebrew/bump-cask-pr-fix-macos-host-handling
bump-cask-pr: fix macOS host handling
2 parents 0d9c056 + 612fec4 commit 79d5115

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,45 @@ def shortened_version(version, cask:)
190190
).returns(T::Array[[T.any(Regexp, String), T.any(Pathname, String)]])
191191
}
192192
def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
193-
# When blocks are absent, arch is not relevant. For consistency, we simulate the arm architecture.
193+
host_os = Homebrew::SimulateSystem.current_os
194+
host_is_macos = MacOSVersion::SYMBOLS.include?(host_os)
195+
newest_macos = MacOSVersion::SYMBOLS.keys.first
196+
197+
# NOTE: We substitute the newest macOS (e.g. `:sequoia`) in place of
198+
# `: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.
194201
system_options = if cask.on_system_blocks_exist?
195-
OnSystem::BASE_OS_OPTIONS.product(OnSystem::ARCH_OPTIONS)
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
208+
end
209+
end.uniq
196210
else
197-
[[:macos, :arm]]
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]
198216
end
199217

200-
system_options.each do |os, arch|
201-
SimulateSystem.with(os:, arch:) do
218+
system_options.each do |system_args|
219+
SimulateSystem.with(**system_args) do
202220
# Handle the cask being invalid for specific os/arch combinations
203221
old_cask = begin
204222
Cask::CaskLoader.load(cask.sourcefile_path)
205-
rescue Cask::CaskInvalidError
223+
rescue Cask::CaskInvalidError, Cask::CaskUnreadableError
206224
raise unless cask.on_system_blocks_exist?
207225
end
208226
next if old_cask.nil?
209227

210-
old_version = old_cask.version
211-
bump_version = new_version.send(arch) || new_version.general
228+
old_version = old_cask.version
229+
next unless old_version
230+
231+
bump_version = new_version.send(system_args[:arch]) || new_version.general
212232

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

0 commit comments

Comments
 (0)