Implement bottles again

Bottles now pour purely, without doing all the other unnecessary stuff that happened before the `brew upgrade` code shuffle.

Formula.pourable? removed since it was install-specific metadata and not related to the formula itself. Now all such logic is in the FormulaInstaller which is much cleaner.

I also changed the bottle cache location to the normal directory and added a .bottle pre-extension. Thus you can see everything in one directory without messing about.
This commit is contained in:
Max Howell 2011-08-24 01:13:15 +01:00
parent 19e387d92e
commit 6ac0a28523
3 changed files with 26 additions and 33 deletions

View File

@ -183,8 +183,7 @@ end
class CurlBottleDownloadStrategy <CurlDownloadStrategy class CurlBottleDownloadStrategy <CurlDownloadStrategy
def initialize url, name, version, specs def initialize url, name, version, specs
super super
HOMEBREW_CACHE_BOTTLES.mkpath @tarball_path = HOMEBREW_CACHE/"#{name}-#{version}.bottle#{ext}"
@tarball_path=HOMEBREW_CACHE_BOTTLES+("#{name}-#{version}"+ext)
end end
def stage def stage
ohai "Pouring #{File.basename(@tarball_path)}" ohai "Pouring #{File.basename(@tarball_path)}"

View File

@ -45,13 +45,6 @@ class SoftwareSpecification
end end
end end
class BottleSoftwareSpecification < SoftwareSpecification
def download_strategy
return CurlBottleDownloadStrategy if @using.nil?
raise "Strategies cannot be used with bottles."
end
end
# Used to annotate formulae that duplicate OS X provided software # Used to annotate formulae that duplicate OS X provided software
# or cause conflicts when linked in. # or cause conflicts when linked in.
@ -120,8 +113,6 @@ class Formula
@url = @head @url = @head
@version = 'HEAD' @version = 'HEAD'
@spec_to_use = @unstable @spec_to_use = @unstable
elsif pourable?
@spec_to_use = BottleSoftwareSpecification.new(@bottle, @specs)
else else
if @stable.nil? if @stable.nil?
@spec_to_use = SoftwareSpecification.new(@url, @specs) @spec_to_use = SoftwareSpecification.new(@url, @specs)
@ -457,10 +448,6 @@ class Formula
end end
end end
def pourable?
@bottle and not ARGV.build_from_source?
end
protected protected
# Pretty titles the command and buffers stdout/stderr # Pretty titles the command and buffers stdout/stderr
# Throws if there's an error # Throws if there's an error
@ -521,16 +508,17 @@ private
CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze
def verify_download_integrity fn public # for FormulaInstaller
def verify_download_integrity fn, *args
require 'digest' require 'digest'
if not pourable? if args.count != 2
type=CHECKSUM_TYPES.detect { |type| instance_variable_defined?("@#{type}") } type=CHECKSUM_TYPES.detect { |type| instance_variable_defined?("@#{type}") }
type ||= :md5 type ||= :md5
supplied=instance_variable_get("@#{type}") supplied=instance_variable_get("@#{type}")
type=type.to_s.upcase type=type.to_s.upcase
else else
supplied=instance_variable_get("@bottle_sha1") supplied, type = args
type="SHA1"
end end
hasher = Digest.const_get(type) hasher = Digest.const_get(type)
@ -552,26 +540,20 @@ EOF
end end
end end
private
def stage def stage
HOMEBREW_CACHE.mkpath HOMEBREW_CACHE.mkpath
fetched = @downloader.fetch fetched = @downloader.fetch
verify_download_integrity fetched if fetched.kind_of? Pathname verify_download_integrity fetched if fetched.kind_of? Pathname
mktemp do
if not pourable? @downloader.stage
mktemp do yield
@downloader.stage
yield
end
else
HOMEBREW_CELLAR.cd do
@downloader.stage
yield
end
end end
end end
def patch def patch
return if patches.nil? or pourable? return if patches.nil?
if not patches.kind_of? Hash if not patches.kind_of? Hash
# We assume -p1 # We assume -p1

View File

@ -14,7 +14,7 @@ class FormulaInstaller
@f = ff @f = ff
@show_header = true @show_header = true
@ignore_deps = ARGV.include? '--ignore-dependencies' || ARGV.interactive? @ignore_deps = ARGV.include? '--ignore-dependencies' || ARGV.interactive?
@install_bottle = ff.pourable? #TODO better @install_bottle = !ff.bottle.nil? && !ARGV.build_from_source?
end end
def install def install
@ -149,7 +149,7 @@ class FormulaInstaller
def clean def clean
require 'cleaner' require 'cleaner'
Cleaner.new f if not f.pourable? Cleaner.new f
rescue Exception => e rescue Exception => e
opoo "The cleaning step did not complete successfully" opoo "The cleaning step did not complete successfully"
puts "Still, the installation was successful, so we will link it into your prefix" puts "Still, the installation was successful, so we will link it into your prefix"
@ -157,6 +157,18 @@ class FormulaInstaller
@show_summary_heading = true @show_summary_heading = true
end end
def pour
HOMEBREW_CACHE.mkpath
downloader = CurlBottleDownloadStrategy.new f.bottle, f.name, f.version, nil
downloader.fetch
f.verify_download_integrity downloader.tarball_path, f.bottle_sha1, "SHA1"
HOMEBREW_CELLAR.cd do
downloader.stage
end
end
## checks
def paths def paths
@paths ||= ENV['PATH'].split(':').map{ |p| File.expand_path p } @paths ||= ENV['PATH'].split(':').map{ |p| File.expand_path p }
end end