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).
			
			
This commit is contained in:
		
							parent
							
								
									d6da002a6e
								
							
						
					
					
						commit
						6f06afbc11
					
				@ -194,29 +194,33 @@ module Homebrew
 | 
			
		||||
        host_is_macos = MacOSVersion::SYMBOLS.include?(host_os)
 | 
			
		||||
        newest_macos = MacOSVersion::SYMBOLS.keys.first
 | 
			
		||||
 | 
			
		||||
        depends_on_archs = cask.depends_on.arch&.filter_map { |arch| arch[:type] }&.uniq
 | 
			
		||||
 | 
			
		||||
        # 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?
 | 
			
		||||
          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
 | 
			
		||||
        # to on_system blocks referencing macOS versions.
 | 
			
		||||
        os_values = []
 | 
			
		||||
        arch_values = depends_on_archs.presence || []
 | 
			
		||||
        if cask.on_system_blocks_exist?
 | 
			
		||||
          OnSystem::BASE_OS_OPTIONS.each do |os|
 | 
			
		||||
            os_values << if os == :macos
 | 
			
		||||
              (host_is_macos ? host_os : newest_macos)
 | 
			
		||||
            else
 | 
			
		||||
              os
 | 
			
		||||
            end
 | 
			
		||||
          end.uniq
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          arch_values = OnSystem::ARCH_OPTIONS if arch_values.empty?
 | 
			
		||||
        else
 | 
			
		||||
          # 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]
 | 
			
		||||
          # Architecture is only relevant if on_system blocks are present or
 | 
			
		||||
          # the cask uses `depends_on arch`, otherwise we default to ARM for
 | 
			
		||||
          # consistency.
 | 
			
		||||
          os_values << (host_is_macos ? host_os : newest_macos)
 | 
			
		||||
          arch_values << :arm if arch_values.empty?
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        system_options.each do |system_args|
 | 
			
		||||
          SimulateSystem.with(**system_args) do
 | 
			
		||||
        os_values.product(arch_values).each do |os, arch|
 | 
			
		||||
          SimulateSystem.with(os:, arch:) do
 | 
			
		||||
            # Handle the cask being invalid for specific os/arch combinations
 | 
			
		||||
            old_cask = begin
 | 
			
		||||
              Cask::CaskLoader.load(cask.sourcefile_path)
 | 
			
		||||
@ -228,7 +232,7 @@ module Homebrew
 | 
			
		||||
            old_version = old_cask.version
 | 
			
		||||
            next unless old_version
 | 
			
		||||
 | 
			
		||||
            bump_version = new_version.send(system_args[:arch]) || new_version.general
 | 
			
		||||
            bump_version = new_version.send(arch) || new_version.general
 | 
			
		||||
 | 
			
		||||
            old_version_regex = old_version.latest? ? ":latest" : %Q(["']#{Regexp.escape(old_version.to_s)}["'])
 | 
			
		||||
            replacement_pairs << [/version\s+#{old_version_regex}/m,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user