diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 50dc74434f..6420504515 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -67,7 +67,7 @@ class DependencyCollector def cache_key(spec) if spec.is_a?(Resource) if spec.download_strategy <= CurlDownloadStrategy - return "#{spec.download_strategy}#{File.extname(spec.url).split("?").first}" + return "#{spec.download_strategy}#{File.extname(T.must(spec.url)).split("?").first}" end return spec.download_strategy diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 0fff15b4db..930248160d 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -156,7 +156,7 @@ module Homebrew new_hash = args.sha256 new_tag = args.tag new_revision = args.revision - old_url = formula_spec.url + old_url = T.must(formula_spec.url) old_tag = formula_spec.specs[:tag] old_formula_version = formula_version(formula) old_version = old_formula_version.to_s @@ -234,7 +234,7 @@ module Homebrew replacement_pairs += if new_url_hash.present? [ [ - /#{Regexp.escape(formula_spec.url)}/, + /#{Regexp.escape(T.must(formula_spec.url))}/, new_url, ], [ @@ -256,7 +256,7 @@ module Homebrew elsif new_url.present? [ [ - /#{Regexp.escape(formula_spec.url)}/, + /#{Regexp.escape(T.must(formula_spec.url))}/, new_url, ], [ diff --git a/Library/Homebrew/downloadable.rb b/Library/Homebrew/downloadable.rb index f8fcaf8355..c04bd8aaac 100644 --- a/Library/Homebrew/downloadable.rb +++ b/Library/Homebrew/downloadable.rb @@ -12,7 +12,7 @@ module Downloadable abstract! requires_ancestor { Kernel } - sig { overridable.returns(T.nilable(URL)) } + sig { overridable.returns(T.any(NilClass, String, URL)) } attr_reader :url sig { overridable.returns(T.nilable(Checksum)) } diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d36bf7a006..5d1ba633eb 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -3650,8 +3650,8 @@ class Formula # ``` # # @api public - sig { params(val: String, specs: T::Hash[Symbol, T.any(String, Symbol)]).void } - def url(val, specs = {}) = stable.url(val, specs) + sig { params(val: String, specs: T::Hash[Symbol, T.anything]).returns(String) } + def url(val = T.unsafe(nil), specs = {}) = stable.url(val, specs) # The version string for the {.stable} version of the formula. # The version is autodetected from the URL and/or tag so only needs to be diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index a8eeb2c7e2..4e2d49eab0 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -186,6 +186,7 @@ class Resource @checksum = Checksum.new(val) end + sig { override.params(val: T.nilable(String), specs: T.anything).returns(T.nilable(String)) } def url(val = nil, **specs) return @url&.to_s if val.nil? @@ -198,6 +199,7 @@ class Resource @url = URL.new(val, specs) @downloader = nil @download_strategy = @url.download_strategy + @url.to_s end sig { override.params(val: T.nilable(T.any(String, Version))).returns(T.nilable(Version)) } @@ -239,6 +241,7 @@ class Resource def determine_url_mirrors extra_urls = [] + url = T.must(self.url) # glibc-bootstrap if url.start_with?("https://github.com/Homebrew/glibc-bootstrap/releases/download") diff --git a/Library/Homebrew/retryable_download.rb b/Library/Homebrew/retryable_download.rb index 0f647b8835..a7c7f40d23 100644 --- a/Library/Homebrew/retryable_download.rb +++ b/Library/Homebrew/retryable_download.rb @@ -9,7 +9,7 @@ module Homebrew attr_reader :downloadable private :downloadable - sig { override.returns(T.nilable(URL)) } + sig { override.returns(T.any(NilClass, String, URL)) } def url = downloadable.url sig { override.returns(T.nilable(Checksum)) } diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index fdd77a37b7..ca7fd3cea1 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -102,11 +102,13 @@ class SoftwareSpec patches.each { |p| p.owner = self } end + sig { override.params(val: T.nilable(String), specs: T::Hash[Symbol, T.anything]).returns(T.nilable(String)) } def url(val = nil, specs = {}) - return @resource.url if val.nil? - - @resource.url(val, **specs) - dependency_collector.add(@resource) + if val + @resource.url(val, **specs) + dependency_collector.add(@resource) + end + @resource.url end def bottle_defined? diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 9d404f4b20..045b27b3a0 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -535,6 +535,14 @@ RSpec.describe Formula do end end + specify ".url" do + f = formula do + url "foo-1.0" + end + + expect(f.class.url).to eq("foo-1.0") + end + specify "spec integration" do f = formula do homepage "https://brew.sh" diff --git a/Library/Homebrew/utils/pypi.rb b/Library/Homebrew/utils/pypi.rb index 9005162454..a0d99f3fc9 100644 --- a/Library/Homebrew/utils/pypi.rb +++ b/Library/Homebrew/utils/pypi.rb @@ -285,7 +285,7 @@ module PyPI url = if stable.specs[:tag].present? "git+#{stable.url}@#{stable.specs[:tag]}" else - stable.url + T.must(stable.url) end Package.new(url, is_url: true, python_name:) end