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