Merge pull request #19689 from Homebrew/bump-cask-pr-fix-macos-host-handling

bump-cask-pr: fix macOS host handling
This commit is contained in:
Mike McQuaid 2025-04-04 07:51:44 +00:00 committed by GitHub
commit 79d5115ba3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -190,25 +190,45 @@ module Homebrew
).returns(T::Array[[T.any(Regexp, String), T.any(Pathname, String)]]) ).returns(T::Array[[T.any(Regexp, String), T.any(Pathname, String)]])
} }
def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs) def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
# When blocks are absent, arch is not relevant. For consistency, we simulate the arm architecture. host_os = Homebrew::SimulateSystem.current_os
host_is_macos = MacOSVersion::SYMBOLS.include?(host_os)
newest_macos = MacOSVersion::SYMBOLS.keys.first
# NOTE: We substitute the newest macOS (e.g. `:sequoia`) in place of
# `:macos` values (when used), as a generic `:macos` value won't apply
# to on_system blocks referencing macOS versions. We also omit the OS
# when the value aligns with the host.
system_options = if cask.on_system_blocks_exist? system_options = if cask.on_system_blocks_exist?
OnSystem::BASE_OS_OPTIONS.product(OnSystem::ARCH_OPTIONS) OnSystem::BASE_OS_OPTIONS.each_with_object([]) do |os, array|
OnSystem::ARCH_OPTIONS.each do |arch|
system_hash = { arch: }
system_hash[:os] = os if host_is_macos && os != :macos
system_hash[:os] = newest_macos if !host_is_macos && os == :macos
array << system_hash
end
end.uniq
else else
[[:macos, :arm]] # Architecture is only relevant if on_system blocks are present. When
# not present, we default to ARM for consistency.
system_hash = { arch: :arm }
system_hash[:os] = newest_macos unless host_is_macos
[system_hash]
end end
system_options.each do |os, arch| system_options.each do |system_args|
SimulateSystem.with(os:, arch:) do SimulateSystem.with(**system_args) do
# Handle the cask being invalid for specific os/arch combinations # Handle the cask being invalid for specific os/arch combinations
old_cask = begin old_cask = begin
Cask::CaskLoader.load(cask.sourcefile_path) Cask::CaskLoader.load(cask.sourcefile_path)
rescue Cask::CaskInvalidError rescue Cask::CaskInvalidError, Cask::CaskUnreadableError
raise unless cask.on_system_blocks_exist? raise unless cask.on_system_blocks_exist?
end end
next if old_cask.nil? next if old_cask.nil?
old_version = old_cask.version old_version = old_cask.version
bump_version = new_version.send(arch) || new_version.general next unless old_version
bump_version = new_version.send(system_args[:arch]) || new_version.general
old_version_regex = old_version.latest? ? ":latest" : %Q(["']#{Regexp.escape(old_version.to_s)}["']) old_version_regex = old_version.latest? ? ":latest" : %Q(["']#{Regexp.escape(old_version.to_s)}["'])
replacement_pairs << [/version\s+#{old_version_regex}/m, replacement_pairs << [/version\s+#{old_version_regex}/m,