@@ -190,25 +190,45 @@ def shortened_version(version, cask:)
190
190
) . returns ( T ::Array [ [ T . any ( Regexp , String ) , T . any ( Pathname , String ) ] ] )
191
191
}
192
192
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.
194
201
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
196
210
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 ]
198
216
end
199
217
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
202
220
# Handle the cask being invalid for specific os/arch combinations
203
221
old_cask = begin
204
222
Cask ::CaskLoader . load ( cask . sourcefile_path )
205
- rescue Cask ::CaskInvalidError
223
+ rescue Cask ::CaskInvalidError , Cask :: CaskUnreadableError
206
224
raise unless cask . on_system_blocks_exist?
207
225
end
208
226
next if old_cask . nil?
209
227
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
212
232
213
233
old_version_regex = old_version . latest? ? ":latest" : %Q(["']#{ Regexp . escape ( old_version . to_s ) } ["'])
214
234
replacement_pairs << [ /version\s +#{ old_version_regex } /m ,
0 commit comments