Cleanup bottle DSL.

* Remove legacy url syntax.
* Use revision instead of version.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Mike McQuaid 2013-02-09 19:06:54 -08:00
parent 161104cae7
commit 360af367a8
4 changed files with 33 additions and 28 deletions

View File

@ -2,22 +2,25 @@ require 'tab'
require 'macos' require 'macos'
require 'extend/ARGV' require 'extend/ARGV'
def bottle_filename f, bottle_version=nil def bottle_filename f, bottle_revision=nil
name = f.name.downcase name = f.name.downcase
version = f.stable.version version = f.stable.version
bottle_version ||= f.bottle.revision.to_i bottle_revision ||= f.bottle.revision.to_i
"#{name}-#{version}#{bottle_native_suffix(bottle_version)}" "#{name}-#{version}#{bottle_native_suffix(bottle_revision)}"
end end
def install_bottle? f def install_bottle? f
return true if ARGV.include? '--install-bottle' and MacOS.bottles_supported?(true) return true if ARGV.include? '--install-bottle' and MacOS.bottles_supported?(true)
return true if f.downloader and defined? f.downloader.local_bottle_path \ return true if f.downloader and defined? f.downloader.local_bottle_path \
and f.downloader.local_bottle_path and f.downloader.local_bottle_path
not ARGV.build_from_source? \
and MacOS.bottles_supported? \ return false if ARGV.build_from_source?
and f.pour_bottle? \ return false unless MacOS.bottles_supported?
and f.build.used_options.empty? \ return false unless f.pour_bottle?
and bottle_current?(f) return false unless f.build.used_options.empty?
return false unless bottle_current?(f)
true
end end
def built_as_bottle? f def built_as_bottle? f
@ -45,18 +48,18 @@ def bottle_file_outdated? f, file
bottle_ext && bottle_url_ext && bottle_ext != bottle_url_ext bottle_ext && bottle_url_ext && bottle_ext != bottle_url_ext
end end
def bottle_new_version f def bottle_new_revision f
return 0 unless bottle_current? f return 0 unless bottle_current? f
f.bottle.revision + 1 f.bottle.revision + 1
end end
def bottle_native_suffix version=nil def bottle_native_suffix revision=nil
".#{MacOS.cat}#{bottle_suffix(version)}" ".#{MacOS.cat}#{bottle_suffix(revision)}"
end end
def bottle_suffix version=nil def bottle_suffix revision=nil
version = version.to_i > 0 ? ".#{version}" : "" revision = revision.to_i > 0 ? ".#{revision}" : ""
".bottle#{version}.tar.gz" ".bottle#{revision}.tar.gz"
end end
def bottle_native_regex def bottle_native_regex

View File

@ -13,19 +13,21 @@ module Homebrew extend self
return ofail "Formula not installed with '--build-bottle': #{f.name}" return ofail "Formula not installed with '--build-bottle': #{f.name}"
end end
directory = Pathname.pwd bottle_revision = bottle_new_revision f
bottle_version = bottle_new_version f filename = bottle_filename f, bottle_revision
filename = bottle_filename f, bottle_version bottle_path = Pathname.pwd/filename
sha1 = nil
HOMEBREW_CELLAR.cd do HOMEBREW_CELLAR.cd do
ohai "Bottling #{f.name} #{f.version}..." ohai "Bottling #{f.name} #{f.version}..."
# Use gzip, faster to compress than bzip2, faster to uncompress than bzip2 # Use gzip, faster to compress than bzip2, faster to uncompress than bzip2
# or an uncompressed tarball (and more bandwidth friendly). # or an uncompressed tarball (and more bandwidth friendly).
safe_system 'tar', 'czf', directory/filename, "#{f.name}/#{f.version}" safe_system 'tar', 'czf', bottle_path, "#{f.name}/#{f.version}"
sha1 = bottle_path.sha1
puts "./#{filename}" puts "./#{filename}"
puts "bottle do" puts "bottle do"
puts " version #{bottle_version}" if bottle_version > 0 puts " revision #{bottle_revision}" if bottle_revision > 0
puts " sha1 '#{(directory/filename).sha1}' => :#{MacOS.cat}" puts " sha1 '#{sha1}' => :#{MacOS.cat}"
puts "end" puts "end"
end end
end end

View File

@ -83,7 +83,7 @@ class Bottle < SoftwareSpec
# TODO: Can be removed when all bottles migrated to underscored cat symbols. # TODO: Can be removed when all bottles migrated to underscored cat symbols.
attr_reader :cat_without_underscores attr_reader :cat_without_underscores
def initialize url=nil, version=nil def initialize
super super
@revision = 0 @revision = 0
@cat_without_underscores = false @cat_without_underscores = false
@ -98,8 +98,6 @@ class Bottle < SoftwareSpec
case val case val
when nil when nil
@#{cksum}[MacOS.cat] @#{cksum}[MacOS.cat]
when String
@#{cksum}[:lion] = Checksum.new(:#{cksum}, val)
when Hash when Hash
key, value = val.shift key, value = val.shift
@#{cksum}[value] = Checksum.new(:#{cksum}, key) @#{cksum}[value] = Checksum.new(:#{cksum}, key)
@ -115,12 +113,13 @@ class Bottle < SoftwareSpec
} }
end end
def url val=nil def revision val=nil
val.nil? ? @url : @url = val val.nil? ? @revision : @revision = val
end end
# Used in the bottle DSL to set @revision, but acts as an # Used in the old bottle DSL to set @revision, but acts as an
# as accessor for @version to preserve the interface # as accessor for @version to preserve the interface
# TODO: Can be removed when no bottles are using `version` any more.
def version val=nil def version val=nil
if val.nil? if val.nil?
return @version ||= Version.parse(@url) return @version ||= Version.parse(@url)

View File

@ -131,8 +131,9 @@ class ExplicitVersionSpecTestBall < Formula
bottle do bottle do
version '1' version '1'
url 'file:///foo.com/test-0.3.lion.bottle.tar.gz' sha1 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' => :snow_leopard
sha1 'baadf00dbaadf00dbaadf00dbaadf00dbaadf00d' sha1 'baadf00dbaadf00dbaadf00dbaadf00dbaadf00d' => :lion
sha1 '8badf00d8badf00d8badf00d8badf00d8badf00d' => :mountain_lion
end end
def initialize name=nil def initialize name=nil