Allow bottles to use any DownloadStrategy
This commit is contained in:
parent
2ec684a123
commit
06f7d7d696
@ -6,6 +6,13 @@ class AbstractDownloadStrategy
|
||||
extend Forwardable
|
||||
include FileUtils
|
||||
|
||||
module Pourable
|
||||
def stage
|
||||
ohai "Pouring #{cached_location.basename}"
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :meta, :name, :version, :resource
|
||||
attr_reader :shutup
|
||||
|
||||
@ -15,6 +22,7 @@ class AbstractDownloadStrategy
|
||||
@url = resource.url
|
||||
@version = resource.version
|
||||
@meta = resource.specs
|
||||
extend Pourable if meta[:bottle]
|
||||
end
|
||||
|
||||
# Download and cache the resource as {#cached_location}.
|
||||
@ -442,14 +450,6 @@ class NoUnzipCurlDownloadStrategy < CurlDownloadStrategy
|
||||
end
|
||||
end
|
||||
|
||||
# This strategy extracts our binary packages.
|
||||
class CurlBottleDownloadStrategy < CurlDownloadStrategy
|
||||
def stage
|
||||
ohai "Pouring #{cached_location.basename}"
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# This strategy extracts local binary packages.
|
||||
class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy
|
||||
attr_reader :cached_location
|
||||
@ -457,11 +457,6 @@ class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy
|
||||
def initialize(path)
|
||||
@cached_location = path
|
||||
end
|
||||
|
||||
def stage
|
||||
ohai "Pouring #{cached_location.basename}"
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# S3DownloadStrategy downloads tarballs from AWS S3.
|
||||
|
||||
@ -111,7 +111,8 @@ module Formulary
|
||||
# The name of the formula is found between the last slash and the last hyphen.
|
||||
formula_name = File.basename(bottle_name)[/(.+)-/, 1]
|
||||
resource = Resource.new(formula_name) { url bottle_name }
|
||||
downloader = CurlBottleDownloadStrategy.new resource.name, resource
|
||||
resource.specs[:bottle] = true
|
||||
downloader = CurlDownloadStrategy.new resource.name, resource
|
||||
@bottle_filename = downloader.cached_location
|
||||
cached = @bottle_filename.exist?
|
||||
downloader.fetch
|
||||
|
||||
@ -283,13 +283,14 @@ class Bottle
|
||||
@name = formula.name
|
||||
@resource = Resource.new
|
||||
@resource.owner = formula
|
||||
@resource.specs[:bottle] = true
|
||||
@spec = spec
|
||||
|
||||
checksum, tag = spec.checksum_for(Utils::Bottles.tag)
|
||||
|
||||
filename = Filename.create(formula, tag, spec.rebuild)
|
||||
@resource.url(build_url(spec.root_url, filename))
|
||||
@resource.download_strategy = CurlBottleDownloadStrategy
|
||||
@resource.url(build_url(spec.root_url, filename),
|
||||
select_download_strategy(spec.root_url_specs))
|
||||
@resource.version = formula.pkg_version
|
||||
@resource.checksum = checksum
|
||||
@prefix = spec.prefix
|
||||
@ -315,6 +316,11 @@ class Bottle
|
||||
def build_url(root_url, filename)
|
||||
"#{root_url}/#{filename}"
|
||||
end
|
||||
|
||||
def select_download_strategy(specs)
|
||||
specs[:using] ||= CurlDownloadStrategy
|
||||
specs
|
||||
end
|
||||
end
|
||||
|
||||
class BottleSpecification
|
||||
@ -324,20 +330,22 @@ class BottleSpecification
|
||||
|
||||
attr_rw :prefix, :cellar, :rebuild
|
||||
attr_accessor :tap
|
||||
attr_reader :checksum, :collector
|
||||
attr_reader :checksum, :collector, :root_url_specs
|
||||
|
||||
def initialize
|
||||
@rebuild = 0
|
||||
@prefix = DEFAULT_PREFIX
|
||||
@cellar = DEFAULT_CELLAR
|
||||
@collector = Utils::Bottles::Collector.new
|
||||
@root_url_specs = {}
|
||||
end
|
||||
|
||||
def root_url(var = nil)
|
||||
def root_url(var = nil, specs = {})
|
||||
if var.nil?
|
||||
@root_url ||= "#{DEFAULT_DOMAIN}/#{Utils::Bottles::Bintray.repository(tap)}"
|
||||
else
|
||||
@root_url = var
|
||||
@root_url_specs.merge!(specs)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -2,9 +2,10 @@ require "download_strategy"
|
||||
|
||||
describe AbstractDownloadStrategy do
|
||||
subject { described_class.new(name, resource) }
|
||||
let(:specs) { {} }
|
||||
let(:name) { "foo" }
|
||||
let(:url) { "http://example.com/foo.tar.gz" }
|
||||
let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
|
||||
let(:resource) { double(Resource, url: url, mirrors: [], specs: specs, version: nil) }
|
||||
let(:args) { %w[foo bar baz] }
|
||||
|
||||
describe "#expand_safe_system_args" do
|
||||
@ -34,6 +35,20 @@ describe AbstractDownloadStrategy do
|
||||
expect(subject.source_modified_time).to eq(File.mtime("foo"))
|
||||
end
|
||||
end
|
||||
|
||||
context "when specs[:bottle]" do
|
||||
let(:specs) { { bottle: true } }
|
||||
|
||||
it "extends Pourable" do
|
||||
expect(subject).to be_a_kind_of(AbstractDownloadStrategy::Pourable)
|
||||
end
|
||||
end
|
||||
|
||||
context "without specs[:bottle]" do
|
||||
it "is does not extend Pourable" do
|
||||
expect(subject).to_not be_a_kind_of(AbstractDownloadStrategy::Pourable)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe VCSDownloadStrategy do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user