8000 BottleLoader: Use the formula stored in the bottle by sjackman · Pull Request #3176 · Homebrew/brew · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BottleLoader: Use the formula stored in the bottle #3176

Merged
merged 6 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ def initialize(resource)
# 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:
Copy link
Member
@MikeMcQuaid MikeMcQuaid Sep 25, 2017 < 8000 /div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about outputting the bottle file and expected formula path within it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#{bottle_path}
#{formula_path}
EOS
end
end
23 changes: 18 additions & 5 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def pour_bottle?(install_bottle_options = { warn: false })

return false if @pour_failed

bottle = formula.bottle
return false if !bottle && !formula.local_bottle_path
return false if !formula.bottled? && !formula.local_bottle_path
return true if force_bottle?
return false if build_from_source? || build_bottle? || interactive?
return false if ARGV.cc
Expand All @@ -101,11 +100,11 @@ def pour_bottle?(install_bottle_options = { warn: false })
return false
end

unless bottle.compatible_cellar?
unless formula.bottled?
if install_bottle_options[:warn]
opoo <<-EOS.undent
Building #{formula.full_name} from source:
The bottle needs a #{bottle.cellar} Cellar (yours is #{HOMEBREW_CELLAR}).
The bottle needs a #{formula.bottle_specification.cellar} Cellar (yours is #{HOMEBREW_CELLAR}).
EOS
end
return false
Expand Down Expand Up @@ -236,6 +235,15 @@ def install
raise CannotInstallFormulaError, message
end

# Warn if a more recent version of this formula is available in the tap.
begin
if formula.pkg_version < (v = Formulary.factory(formula.full_name).pkg_version)
opoo "#{formula.full_name} #{v} is available and more recent than version #{formula.pkg_version}."
end
rescue FormulaUnavailableError
nil
end

check_conflicts

if !pour_bottle? && !formula.bottle_unneeded? && !DevelopmentTools.installed?
Expand Down Expand Up @@ -309,7 +317,12 @@ def install
clean

# Store the formula used to build the keg in the keg.
s = formula.path.read.gsub(/ bottle do.+?end\n\n?/m, "")
formula_contents = if formula.local_bottle_path
Utils::Bottles.formula_contents formula.local_bottle_path, name: formula.name
else
formula.path.read
end
s = formula_contents.gsub(/ bottle do.+?end\n\n?/m, "")
brew_prefix = formula.prefix/".brew"
brew_prefix.mkdir
Pathname(brew_prefix/"#{formula.name}.rb").atomic_write(s)
Expand Down
10 changes: 3 additions & 7 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,10 @@ def initialize(bottle_name)
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/bottle_hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

let(:formula) do
double(
bottle: nil,
bottled?: false,
local_bottle_path: nil,
bottle_disabled?: false,
some_random_method: true,
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class Baz < Formula; end
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
2 changes: 1 addition & 1 deletion Library/Homebrew/test/formulary_spec.rb
628C
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class #{subject.class_s(formula_name)} < Formula
bottle do
cellar :any_skip_relocation
root_url "file://#{bottle_dir}"
sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag}
sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => :#{Utils::Bottles.tag}
end

def install
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Library/Homebrew/test/support/fixtures/testball_bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_pa
stable.bottle do
cellar :any_skip_relocation
root_url "file://#{TEST_FIXTURE_DIR}/bottles"
sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => Utils::Bottles.tag
sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => Utils::Bottles.tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably: adding the formula?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

end
cxxstdlib_check :skip
end
Expand Down
13 changes: 12 additions & 1 deletion Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def native_regex
end

def receipt_path(bottle_file)
Utils.popen_read("tar", "-tzf", bottle_file).lines.map(&:chomp).find do |line|
path = Utils.popen_read("tar", "-tzf", bottle_file).lines.map(&:chomp).find do |line|
line =~ %r{.+/.+/INSTALL_RECEIPT.json}
end
raise "This bottle does not contain the file INSTALL_RECEIPT.json: #{bottle_file}" unless path
path
end

def resolve_formula_names(bottle_file)
Expand All @@ -52,6 +54,15 @@ def resolve_formula_names(bottle_file)
def resolve_version(bottle_file)
PkgVersion.parse receipt_path(bottle_file).split("/")[1]
end

def formula_contents(bottle_file,
name: resolve_formula_names(bottle_file)[0])
bottle_version = resolve_version bottle_file
formula_path = "#{name}/#{bottle_version}/.brew/#{name}.rb"
contents = Utils.popen_read "tar", "-xOzf", bottle_file, formula_path
raise BottleFormulaUnavailableError.new(bottle_file, formula_path) unless $CHILD_STATUS.success?
contents
end
end

class Bintray
Expand Down
0