diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index b4806eee61..a4e5ff6ae5 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -1,2 +1,4 @@ # typed: strict # frozen_string_literal: true + +require "compat/download_strategy" diff --git a/Library/Homebrew/compat/download_strategy.rb b/Library/Homebrew/compat/download_strategy.rb new file mode 100644 index 0000000000..2b098f01b2 --- /dev/null +++ b/Library/Homebrew/compat/download_strategy.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 29d120955b..bfa1962d39 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -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 diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 7a9c013df6..6533d4dc2e 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -1,6 +1,7 @@ # typed: true # frozen_string_literal: true +require "context" require "resource" require "metafiles" diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 1a9c16c045..ffb5024b1b 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -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 diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index cc1bf9c445..83bae0d40d 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -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/") diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index 8e49bbaf9a..0796ec2ff2 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -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