Add compatibility layer for AbstractDownloadStrategy#fetch.
				
					
				
			This commit is contained in:
		
							parent
							
								
									cdcd216237
								
							
						
					
					
						commit
						b6ed8915e5
					
				@ -1,2 +1,4 @@
 | 
			
		||||
# typed: strict
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "compat/download_strategy"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										26
									
								
								Library/Homebrew/compat/download_strategy.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Library/Homebrew/compat/download_strategy.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
# typed: false
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
class AbstractDownloadStrategy
 | 
			
		||||
  module Compat
 | 
			
		||||
    def fetch(timeout: nil)
 | 
			
		||||
      super()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  class << self
 | 
			
		||||
    def method_added(method)
 | 
			
		||||
      if method == :fetch && instance_method(method).arity.zero?
 | 
			
		||||
        odeprecated "`def fetch` in a subclass of #{self}",
 | 
			
		||||
                    "`def fetch(timeout: nil, **options)` and output a warning " \
 | 
			
		||||
                    "when `options` contains new unhandled options"
 | 
			
		||||
 | 
			
		||||
        class_eval do
 | 
			
		||||
          prepend Compat
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      super
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -455,7 +455,7 @@ end
 | 
			
		||||
class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
  extend T::Sig
 | 
			
		||||
 | 
			
		||||
  def fetch
 | 
			
		||||
  def fetch(timeout: nil)
 | 
			
		||||
    ohai "Downloading #{url}"
 | 
			
		||||
    if cached_location.exist?
 | 
			
		||||
      puts "Already downloaded: #{cached_location}"
 | 
			
		||||
@ -463,7 +463,8 @@ class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
      begin
 | 
			
		||||
        curl "--location", "--create-dirs", "--output", temporary_path, url,
 | 
			
		||||
             *meta.fetch(:curl_args, []),
 | 
			
		||||
             secrets: meta.fetch(:secrets, [])
 | 
			
		||||
             secrets: meta.fetch(:secrets, []),
 | 
			
		||||
             timeout: timeout
 | 
			
		||||
      rescue ErrorDuringExecution
 | 
			
		||||
        raise CurlDownloadStrategyError, url
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
# typed: true
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "context"
 | 
			
		||||
require "resource"
 | 
			
		||||
require "metafiles"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@
 | 
			
		||||
require_relative "load_path"
 | 
			
		||||
 | 
			
		||||
require "English"
 | 
			
		||||
require "fileutils"
 | 
			
		||||
require "json"
 | 
			
		||||
require "json/add/exception"
 | 
			
		||||
require "pathname"
 | 
			
		||||
@ -39,8 +40,6 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
 | 
			
		||||
  inflect.irregular "it", "they"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
require "utils/sorbet"
 | 
			
		||||
 | 
			
		||||
HOMEBREW_BOTTLE_DEFAULT_DOMAIN = ENV["HOMEBREW_BOTTLE_DEFAULT_DOMAIN"]
 | 
			
		||||
HOMEBREW_BREW_DEFAULT_GIT_REMOTE = ENV["HOMEBREW_BREW_DEFAULT_GIT_REMOTE"]
 | 
			
		||||
HOMEBREW_CORE_DEFAULT_GIT_REMOTE = ENV["HOMEBREW_CORE_DEFAULT_GIT_REMOTE"]
 | 
			
		||||
@ -73,10 +72,11 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX =
 | 
			
		||||
  %r[https://github\.com/([\w-]+)/([\w-]+)?/(?:pull/(\d+)|commit/[0-9a-fA-F]{4,40})].freeze
 | 
			
		||||
HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/.freeze
 | 
			
		||||
 | 
			
		||||
require "fileutils"
 | 
			
		||||
require "utils/sorbet"
 | 
			
		||||
 | 
			
		||||
require "os"
 | 
			
		||||
require "env_config"
 | 
			
		||||
require "compat" unless Homebrew::EnvConfig.no_compat?
 | 
			
		||||
require "os"
 | 
			
		||||
require "messages"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
@ -152,7 +152,5 @@ require "official_taps"
 | 
			
		||||
require "tap"
 | 
			
		||||
require "tap_constants"
 | 
			
		||||
 | 
			
		||||
require "compat" unless Homebrew::EnvConfig.no_compat?
 | 
			
		||||
 | 
			
		||||
# Enables `patchelf.rb` write support.
 | 
			
		||||
HOMEBREW_PATCHELF_RB_WRITE = ENV["HOMEBREW_NO_PATCHELF_RB_WRITE"].blank?.freeze
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,8 @@
 | 
			
		||||
# typed: false
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "time"
 | 
			
		||||
 | 
			
		||||
require "utils/analytics"
 | 
			
		||||
require "utils/curl"
 | 
			
		||||
require "utils/fork"
 | 
			
		||||
@ -16,7 +18,6 @@ require "utils/repology"
 | 
			
		||||
require "utils/svn"
 | 
			
		||||
require "utils/tty"
 | 
			
		||||
require "tap_constants"
 | 
			
		||||
require "time"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  extend Context
 | 
			
		||||
@ -206,7 +207,7 @@ module Kernel
 | 
			
		||||
 | 
			
		||||
    # Don't throw deprecations at all for cached, .brew or .metadata files.
 | 
			
		||||
    return if backtrace.any? do |line|
 | 
			
		||||
      next true if line.include?(HOMEBREW_CACHE)
 | 
			
		||||
      next true if line.include?(HOMEBREW_CACHE.to_s)
 | 
			
		||||
      next true if line.include?("/.brew/")
 | 
			
		||||
      next true if line.include?("/.metadata/")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -630,7 +630,9 @@ If you need more control over the way files are downloaded and staged, you can c
 | 
			
		||||
 | 
			
		||||
```ruby
 | 
			
		||||
class MyDownloadStrategy < SomeHomebrewDownloadStrategy
 | 
			
		||||
  def fetch
 | 
			
		||||
  def fetch(timeout: nil, **options)
 | 
			
		||||
    opoo "Unhandled options in #{self.class}#fetch: #{options.keys.join(", ")}" unless options.empty?
 | 
			
		||||
    
 | 
			
		||||
    # downloads output to `temporary_path`
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user