diff --git a/Library/Homebrew/cask/url.rb b/Library/Homebrew/cask/url.rb index 47af7f7079..7efafb5a95 100644 --- a/Library/Homebrew/cask/url.rb +++ b/Library/Homebrew/cask/url.rb @@ -5,12 +5,12 @@ require "source_location" require "utils/curl" module Cask - BlockReturn = T.type_alias do - T.any(URI::Generic, String, [T.any(URI::Generic, String), T::Hash[Symbol, T.untyped]]) - end - # Class corresponding to the `url` stanza. class URL < SimpleDelegator + BlockReturn = T.type_alias do + T.any(URI::Generic, String, [T.any(URI::Generic, String), T::Hash[Symbol, T.untyped]]) + end + class DSL sig { returns(T.any(URI::Generic, String)) } attr_reader :uri @@ -173,9 +173,8 @@ module Cask # # @api public sig { - override - .params(method: Symbol, args: T.untyped, block: T.nilable(T.proc.returns(T.untyped))) - .returns(T.untyped) + override.params(method: Symbol, args: T.untyped, block: T.nilable(T.proc.returns(T.untyped))) + .returns(T.anything) } def method_missing(method, *args, &block) if @dsl.respond_to?(method) diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index 6c5414f2d4..830d995c8f 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -115,7 +115,7 @@ module Homebrew strategy = DownloadStrategyDetector.detect(url) downloader = strategy.new(url, token, version.to_s, cache: Cask::Cache.path) downloader.fetch - downloader.cached_location!.sha256 + downloader.cached_location.sha256 end [url.gsub(version.to_s, "\#{version}"), sha256] diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index ef3c3548a9..887c25f86f 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -50,12 +50,6 @@ class AbstractDownloadStrategy sig { returns(String) } attr_reader :url - # Location of the cached download. - # - # @api public - sig { returns(T.nilable(Pathname)) } - attr_reader :cached_location - sig { returns(Pathname) } attr_reader :cache @@ -90,8 +84,11 @@ class AbstractDownloadStrategy sig { overridable.params(timeout: T.any(Float, Integer, NilClass)).void } def fetch(timeout: nil); end - sig { returns(Pathname) } - def cached_location! = T.must(cached_location) + # Location of the cached download. + # + # @api public + sig { abstract.returns(Pathname) } + def cached_location; end # Disable any output during downloading. # @@ -117,7 +114,7 @@ class AbstractDownloadStrategy # @api public sig { overridable.params(block: T.untyped).void } def stage(&block) - UnpackStrategy.detect(cached_location!, + UnpackStrategy.detect(cached_location, prioritize_extension: true, ref_type: @ref_type, ref: @ref) .extract_nestedly(basename:, @@ -158,12 +155,12 @@ class AbstractDownloadStrategy # @api public sig { overridable.void } def clear_cache - rm_rf(cached_location!) + rm_rf(cached_location) end sig { returns(Pathname) } def basename - cached_location!.basename + cached_location.basename end private @@ -212,7 +209,7 @@ end class VCSDownloadStrategy < AbstractDownloadStrategy abstract! - sig { returns(Pathname) } + sig { override.returns(Pathname) } attr_reader :cached_location REF_TYPES = [:tag, :branch, :revisions, :revision].freeze @@ -336,7 +333,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy # Path for storing the completed download. # # @api public - sig { returns(Pathname) } + sig { override.returns(Pathname) } def cached_location return @cached_location if @cached_location diff --git a/Library/Homebrew/downloadable.rb b/Library/Homebrew/downloadable.rb index 3f917e983b..037e9ad0d6 100644 --- a/Library/Homebrew/downloadable.rb +++ b/Library/Homebrew/downloadable.rb @@ -56,7 +56,7 @@ module Downloadable sig { overridable.returns(Pathname) } def cached_download - downloader.cached_location! + downloader.cached_location end sig { overridable.void } diff --git a/Library/Homebrew/test/cask/tab_spec.rb b/Library/Homebrew/test/cask/tab_spec.rb index 9b346e2601..be2f5bdc25 100644 --- a/Library/Homebrew/test/cask/tab_spec.rb +++ b/Library/Homebrew/test/cask/tab_spec.rb @@ -124,8 +124,10 @@ RSpec.describe Cask::Tab, :cask do specify "with all types of dependencies" do cask = Cask::CaskLoader.load("with-depends-on-everything") - unar = instance_double(Formula, full_name: "unar", version: "1.2", revision: 0, pkg_version: "1.2", - deps: [], requirements: []) + unar = Class.new(Formula) do + url "my_url" + version "1.2" + end.new("unar", Pathname.new(__FILE__).expand_path, :stable) expect(Formulary).to receive(:factory).with("unar").and_return(unar) expected_hash = { diff --git a/Library/Homebrew/utils/topological_hash.rb b/Library/Homebrew/utils/topological_hash.rb index 9b6cec4f20..14e1bd705b 100644 --- a/Library/Homebrew/utils/topological_hash.rb +++ b/Library/Homebrew/utils/topological_hash.rb @@ -27,14 +27,15 @@ module Utils packages.each do |cask_or_formula| next if accumulator.key?(cask_or_formula) - if cask_or_formula.is_a?(Cask::Cask) + case cask_or_formula + when Cask::Cask formula_deps = cask_or_formula.depends_on .formula .map { |f| Formula[f] } cask_deps = cask_or_formula.depends_on .cask .map { |c| Cask::CaskLoader.load(c, config: nil) } - else + when Formula formula_deps = cask_or_formula.deps .reject(&:build?) .reject(&:test?) @@ -42,6 +43,8 @@ module Utils cask_deps = cask_or_formula.requirements .filter_map(&:cask) .map { |c| Cask::CaskLoader.load(c, config: nil) } + else + T.absurd(cask_or_formula) end accumulator[cask_or_formula] = formula_deps + cask_deps