BottleLoader: Use the formula stored in the bottle

This commit is contained in:
Shaun Jackman 2017-09-19 12:22:32 -07:00
parent 9642ec769e
commit 3ed832d4f0
3 changed files with 11 additions and 15 deletions

View File

@ -555,12 +555,12 @@ end
# raised when a single patch file is not found and apply hasn't been specified
class MissingApplyError < RuntimeError; end
class BottleVersionMismatchError < RuntimeError
def initialize(bottle_file, bottle_version, formula, formula_version)
class BottleFormulaUnavailableError < RuntimeError
def initialize(bottle_path, formula_path)
super <<-EOS.undent
Bottle version mismatch
Bottle: #{bottle_file} (#{bottle_version})
Formula: #{formula.full_name} (#{formula_version})
This bottle does not contain the formula file:
#{bottle_path}
#{formula_path}
EOS
end
end

View File

@ -122,14 +122,10 @@ module Formulary
super name, Formulary.path(full_name)
end
def get_formula(spec, alias_path: nil)
formula = super
def get_formula(spec, **)
contents = Utils::Bottles.formula_contents @bottle_filename, name: name
formula = Formulary.from_contents name, @bottle_filename, contents, spec
formula.local_bottle_path = @bottle_filename
formula_version = formula.pkg_version
bottle_version = Utils::Bottles.resolve_version(@bottle_filename)
unless formula_version == bottle_version
raise BottleVersionMismatchError.new(@bottle_filename, bottle_version, formula, formula_version)
end
formula
end
end

View File

@ -181,8 +181,8 @@ describe DuplicateResourceError do
its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") }
end
describe BottleVersionMismatchError do
subject { described_class.new("/foo.bottle.tar.gz", "1.0", formula, "1.1") }
describe BottleFormulaUnavailableError do
subject { described_class.new("/foo.bottle.tar.gz", "foo/1.0/.brew/foo.rb") }
let(:formula) { double(Formula, full_name: "foo") }
its(:to_s) { is_expected.to match(/Bottle version mismatch/) }
its(:to_s) { is_expected.to match(/This bottle does not contain the formula file/) }
end