Skip to content

Commit

Permalink
Version bottles.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Apr 3, 2012
1 parent 2d5ed4c commit e827884
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
17 changes: 13 additions & 4 deletions Library/Homebrew/bottles.rb
@@ -1,8 +1,12 @@
require 'tab'
require 'extend/ARGV'

def bottle_filename f
"#{f.name}-#{f.version}#{bottle_native_suffix}"
def bottle_filename f, bottle_version=nil
name = f.name.downcase
version = f.version || f.standard.detect_version
bottle_version = bottle_version || f.bottle_version
bottle_version_tag = bottle_version > 0 ? "-#{bottle_version}" : ""
"#{name}-#{version}#{bottle_version_tag}#{bottle_native_suffix}"
end

def bottles_supported?
Expand All @@ -21,6 +25,11 @@ def bottle_current? f
f.bottle_url && f.bottle_sha1 && Pathname.new(f.bottle_url).version == f.version
end

def bottle_new_version f
return 0 unless f.bottle_version
f.bottle_version + 1
end

def bottle_native_suffix
".#{MacOS.cat}#{bottle_suffix}"
end
Expand All @@ -30,11 +39,11 @@ def bottle_suffix
end

def bottle_native_regex
/(\.#{MacOS.cat}\.bottle\.tar\.gz)$/
/((-\d+)?\.#{MacOS.cat}\.bottle\.tar\.gz)$/
end

def bottle_regex
/(\.[a-z]+\.bottle\.tar\.gz)$/
/((-\d+)?\.[a-z]+\.bottle\.tar\.gz)$/
end

def old_bottle_regex
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/cmd/bottle.rb
Expand Up @@ -16,7 +16,8 @@ def bottle_formula f
end

directory = Pathname.pwd
filename = bottle_filename f
bottle_version = bottle_new_version f
filename = bottle_filename f, bottle_version

HOMEBREW_CELLAR.cd do
ohai "Bottling #{f.name} #{f.version}..."
Expand All @@ -25,6 +26,7 @@ def bottle_formula f
safe_system 'tar', 'czf', directory/filename, "#{f.name}/#{f.version}"
puts "./#{filename}"
puts "bottle do"
puts " version #{bottle_version}" if bottle_version > 0
puts " sha1 '#{(directory/filename).sha1}' => :#{MacOS.cat}"
puts "end"
end
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/download_strategy.rb
Expand Up @@ -194,8 +194,7 @@ def initialize url, name, version, specs
@tarball_path = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"

unless @tarball_path.exist?
old_bottle_path = HOMEBREW_CACHE/"#{name}-#{version}#{bottle_suffix}"
old_bottle_path = HOMEBREW_CACHE/"#{name}-#{version}-bottle.tar.gz" unless old_bottle_path.exist?
old_bottle_path = HOMEBREW_CACHE/"#{name}-#{version}-bottle.tar.gz"
old_bottle_path = HOMEBREW_CACHE/"#{name}-#{version}.#{MacOS.cat}.bottle-bottle.tar.gz" unless old_bottle_path.exist?
FileUtils.mv old_bottle_path, @tarball_path if old_bottle_path.exist?
end
Expand Down
27 changes: 15 additions & 12 deletions Library/Homebrew/formula.rb
Expand Up @@ -12,8 +12,8 @@ class Formula
include FileUtils

attr_reader :name, :path, :url, :version, :homepage, :specs, :downloader
attr_reader :standard, :unstable
attr_reader :bottle_url, :bottle_sha1, :head
attr_reader :standard, :unstable, :head
attr_reader :bottle_version, :bottle_url, :bottle_sha1

# The build folder, usually in /tmp.
# Will only be non-nil during the stage method.
Expand All @@ -23,6 +23,7 @@ class Formula
def initialize name='__UNKNOWN__', path=nil
set_instance_variable 'homepage'
set_instance_variable 'url'
set_instance_variable 'bottle_version'
set_instance_variable 'bottle_url'
set_instance_variable 'bottle_sha1'
set_instance_variable 'head'
Expand Down Expand Up @@ -568,8 +569,8 @@ def #{attr}(val=nil)
end

attr_rw :version, :homepage, :mirrors, :specs
attr_rw :keg_only_reason, :skip_clean_all, :bottle_url, :bottle_sha1
attr_rw :cc_failures
attr_rw :keg_only_reason, :skip_clean_all, :cc_failures
attr_rw :bottle_version, :bottle_url, :bottle_sha1
attr_rw(*CHECKSUM_TYPES)

def head val=nil, specs=nil
Expand Down Expand Up @@ -603,6 +604,10 @@ def bottle url=nil, &block
return unless block_given?

bottle_block = Class.new do
def self.version version
@version = version
end

def self.url url
@url = url
end
Expand All @@ -617,18 +622,16 @@ def self.sha1 sha1
end
end

def self.url_sha1
if @sha1 && @url
return @url, @sha1
elsif @sha1
return nil, @sha1
end
def self.data
@version = 0 unless @version
return @version, @url, @sha1 if @sha1 && @url
return @version, nil, @sha1 if @sha1
end
end

bottle_block.instance_eval &block
@bottle_url, @bottle_sha1 = bottle_block.url_sha1
@bottle_url ||= "#{bottle_base_url}#{name.downcase}-#{@version||@standard.detect_version}#{bottle_native_suffix}" if @bottle_sha1
@bottle_version, @bottle_url, @bottle_sha1 = bottle_block.data
@bottle_url ||= bottle_base_url + bottle_filename(self) if @bottle_sha1
end

def mirror val, specs=nil
Expand Down

0 comments on commit e827884

Please sign in to comment.