Explicitly pass specs to download strategy.
This commit is contained in:
parent
e367e7eea8
commit
7c496f7a7e
@ -17,13 +17,12 @@ class AbstractDownloadStrategy
|
||||
attr_reader :meta, :name, :version
|
||||
attr_reader :shutup
|
||||
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
@url = url
|
||||
@name = name
|
||||
@version = version
|
||||
@meta = resource.specs
|
||||
@meta = meta
|
||||
@shutup = false
|
||||
@mirrors = mirrors
|
||||
extend Pourable if meta[:bottle]
|
||||
end
|
||||
|
||||
@ -91,7 +90,7 @@ end
|
||||
class VCSDownloadStrategy < AbstractDownloadStrategy
|
||||
REF_TYPES = [:tag, :branch, :revisions, :revision].freeze
|
||||
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@ref_type, @ref = extract_ref(meta)
|
||||
@revision = meta[:revision]
|
||||
@ -210,8 +209,9 @@ end
|
||||
class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
||||
attr_reader :mirrors, :tarball_path, :temporary_path
|
||||
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@mirrors = meta.fetch(:mirrors, [])
|
||||
@tarball_path = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
|
||||
@temporary_path = Pathname.new("#{cached_location}.incomplete")
|
||||
end
|
||||
@ -389,7 +389,7 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy
|
||||
require "utils/formatter"
|
||||
require "utils/github"
|
||||
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
parse_url_pattern
|
||||
set_github_token
|
||||
@ -495,7 +495,7 @@ end
|
||||
class ScpDownloadStrategy < AbstractFileDownloadStrategy
|
||||
attr_reader :tarball_path, :temporary_path
|
||||
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@tarball_path = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
|
||||
@temporary_path = Pathname.new("#{cached_location}.incomplete")
|
||||
@ -546,7 +546,7 @@ class ScpDownloadStrategy < AbstractFileDownloadStrategy
|
||||
end
|
||||
|
||||
class SubversionDownloadStrategy < VCSDownloadStrategy
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@url = @url.sub("svn+http://", "")
|
||||
end
|
||||
@ -631,7 +631,7 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
||||
%r{http://llvm\.org},
|
||||
].freeze
|
||||
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@ref_type ||= :branch
|
||||
@ref ||= "master"
|
||||
@ -803,7 +803,7 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
||||
end
|
||||
|
||||
class GitHubGitDownloadStrategy < GitDownloadStrategy
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
|
||||
return unless %r{^https?://github\.com/(?<user>[^/]+)/(?<repo>[^/]+)\.git$} =~ @url
|
||||
@ -857,7 +857,7 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
|
||||
end
|
||||
|
||||
class CVSDownloadStrategy < VCSDownloadStrategy
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@url = @url.sub(%r{^cvs://}, "")
|
||||
|
||||
@ -927,7 +927,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy
|
||||
end
|
||||
|
||||
class MercurialDownloadStrategy < VCSDownloadStrategy
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@url = @url.sub(%r{^hg://}, "")
|
||||
end
|
||||
@ -983,7 +983,7 @@ class MercurialDownloadStrategy < VCSDownloadStrategy
|
||||
end
|
||||
|
||||
class BazaarDownloadStrategy < VCSDownloadStrategy
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@url.sub!(%r{^bzr://}, "")
|
||||
ENV["BZR_HOME"] = HOMEBREW_TEMP
|
||||
@ -1034,7 +1034,7 @@ class BazaarDownloadStrategy < VCSDownloadStrategy
|
||||
end
|
||||
|
||||
class FossilDownloadStrategy < VCSDownloadStrategy
|
||||
def initialize(url, name, version, resource, mirrors: [])
|
||||
def initialize(url, name, version, **meta)
|
||||
super
|
||||
@url = @url.sub(%r{^fossil://}, "")
|
||||
end
|
||||
|
@ -17,16 +17,6 @@ class Resource
|
||||
# formula name before initialization of the formula
|
||||
attr_accessor :name
|
||||
|
||||
class Download
|
||||
def initialize(resource)
|
||||
@resource = resource
|
||||
end
|
||||
|
||||
def specs
|
||||
@resource.specs
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(name = nil, &block)
|
||||
@name = name
|
||||
@url = nil
|
||||
@ -45,8 +35,8 @@ class Resource
|
||||
end
|
||||
|
||||
def downloader
|
||||
download_strategy.new(url, download_name, version, Download.new(self),
|
||||
mirrors: mirrors.dup)
|
||||
download_strategy.new(url, download_name, version,
|
||||
mirrors: mirrors.dup, **specs)
|
||||
end
|
||||
|
||||
# Removes /s from resource names; this allows go package names
|
||||
@ -149,7 +139,7 @@ class Resource
|
||||
define_method(type) { |val| @checksum = Checksum.new(type, val) }
|
||||
end
|
||||
|
||||
def url(val = nil, specs = {})
|
||||
def url(val = nil, **specs)
|
||||
return @url if val.nil?
|
||||
@url = val
|
||||
@specs.merge!(specs)
|
||||
|
@ -1,13 +1,12 @@
|
||||
require "download_strategy"
|
||||
|
||||
describe AbstractDownloadStrategy do
|
||||
subject { described_class.new(url, name, version, resource) }
|
||||
subject { described_class.new(url, name, version, **specs) }
|
||||
|
||||
let(:specs) { {} }
|
||||
let(:name) { "foo" }
|
||||
let(:url) { "http://example.com/foo.tar.gz" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: specs) }
|
||||
let(:args) { %w[foo bar baz] }
|
||||
|
||||
specify "#source_modified_time" do
|
||||
@ -37,23 +36,21 @@ end
|
||||
describe VCSDownloadStrategy do
|
||||
let(:url) { "http://example.com/bar" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: {}) }
|
||||
|
||||
describe "#cached_location" do
|
||||
it "returns the path of the cached resource" do
|
||||
allow_any_instance_of(described_class).to receive(:cache_tag).and_return("foo")
|
||||
downloader = described_class.new(url, "baz", version, resource)
|
||||
downloader = described_class.new(url, "baz", version)
|
||||
expect(downloader.cached_location).to eq(HOMEBREW_CACHE/"baz--foo")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe GitHubPrivateRepositoryDownloadStrategy do
|
||||
subject { described_class.new(url, "foo", version, resource) }
|
||||
subject { described_class.new(url, "foo", version) }
|
||||
|
||||
let(:url) { "https://github.com/owner/repo/archive/1.1.5.tar.gz" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: {}) }
|
||||
|
||||
before do
|
||||
ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
|
||||
@ -74,11 +71,10 @@ describe GitHubPrivateRepositoryDownloadStrategy do
|
||||
end
|
||||
|
||||
describe GitHubPrivateRepositoryReleaseDownloadStrategy do
|
||||
subject { described_class.new(url, "foo", version, resource) }
|
||||
subject { described_class.new(url, "foo", version) }
|
||||
|
||||
let(:url) { "https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, url: url, specs: {}) }
|
||||
|
||||
before do
|
||||
ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
|
||||
@ -126,12 +122,11 @@ describe GitHubPrivateRepositoryReleaseDownloadStrategy do
|
||||
end
|
||||
|
||||
describe GitHubGitDownloadStrategy do
|
||||
subject { described_class.new(url, name, version, resource) }
|
||||
subject { described_class.new(url, name, version) }
|
||||
|
||||
let(:name) { "brew" }
|
||||
let(:url) { "https://github.com/homebrew/brew.git" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: {}) }
|
||||
|
||||
it "parses the URL and sets the corresponding instance variables" do
|
||||
expect(subject.instance_variable_get(:@user)).to eq("homebrew")
|
||||
@ -140,12 +135,11 @@ describe GitHubGitDownloadStrategy do
|
||||
end
|
||||
|
||||
describe GitDownloadStrategy do
|
||||
subject { described_class.new(url, name, version, resource) }
|
||||
subject { described_class.new(url, name, version) }
|
||||
|
||||
let(:name) { "baz" }
|
||||
let(:url) { "https://github.com/homebrew/foo" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: {}) }
|
||||
let(:cached_location) { subject.cached_location }
|
||||
|
||||
before do
|
||||
@ -187,7 +181,6 @@ describe GitDownloadStrategy do
|
||||
describe "#fetch_last_commit" do
|
||||
let(:url) { "file://#{remote_repo}" }
|
||||
let(:version) { Version.create("HEAD") }
|
||||
let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: version) }
|
||||
let(:remote_repo) { HOMEBREW_PREFIX/"remote_repo" }
|
||||
|
||||
before { remote_repo.mkpath }
|
||||
@ -208,15 +201,14 @@ describe GitDownloadStrategy do
|
||||
end
|
||||
|
||||
describe S3DownloadStrategy do
|
||||
subject { described_class.new(url, name, version, resource) }
|
||||
subject { described_class.new(url, name, version) }
|
||||
|
||||
let(:name) { "foo" }
|
||||
let(:url) { "http://bucket.s3.amazonaws.com/foo.tar.gz" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: {}) }
|
||||
|
||||
describe "#_fetch" do
|
||||
subject { described_class.new(url, name, version, resource)._fetch }
|
||||
subject { described_class.new(url, name, version)._fetch }
|
||||
|
||||
context "when given Bad S3 URL" do
|
||||
let(:url) { "http://example.com/foo.tar.gz" }
|
||||
@ -231,19 +223,19 @@ describe S3DownloadStrategy do
|
||||
end
|
||||
|
||||
describe CurlDownloadStrategy do
|
||||
subject { described_class.new(url, name, version, resource) }
|
||||
subject { described_class.new(url, name, version, **specs) }
|
||||
|
||||
let(:name) { "foo" }
|
||||
let(:url) { "http://example.com/foo.tar.gz" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: { user: "download:123456" }) }
|
||||
let(:specs) { { user: "download:123456" } }
|
||||
|
||||
it "parses the opts and sets the corresponding args" do
|
||||
expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"])
|
||||
end
|
||||
|
||||
describe "#tarball_path" do
|
||||
subject { described_class.new(url, name, version, resource).tarball_path }
|
||||
subject { described_class.new(url, name, version, **specs).tarball_path }
|
||||
|
||||
context "when URL ends with file" do
|
||||
it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") }
|
||||
@ -258,11 +250,10 @@ describe CurlDownloadStrategy do
|
||||
end
|
||||
|
||||
describe ScpDownloadStrategy do
|
||||
subject { described_class.new(url, name, version, resource) }
|
||||
subject { described_class.new(url, name, version) }
|
||||
let(:name) { "foo" }
|
||||
let(:url) { "scp://example.com/foo.tar.gz" }
|
||||
let(:version) { nil }
|
||||
let(:resource) { double(Resource, specs: {}) }
|
||||
|
||||
describe "#initialize" do
|
||||
invalid_urls = %w[
|
||||
|
Loading…
x
Reference in New Issue
Block a user