2012-03-07 17:29:05 -05:00
|
|
|
require 'formula'
|
2012-03-07 21:30:03 -05:00
|
|
|
require 'bottles'
|
2012-03-07 17:29:05 -05:00
|
|
|
require 'tab'
|
2013-03-11 18:56:26 +00:00
|
|
|
require 'keg'
|
2012-03-07 17:29:05 -05:00
|
|
|
|
2013-06-08 16:48:43 +01:00
|
|
|
class BottleMerger < Formula
|
|
|
|
# This provides a URL and Version which are the only needed properties of
|
|
|
|
# a Formula. This object is used to access the Formula bottle DSL to merge
|
|
|
|
# multiple outputs of `brew bottle`.
|
|
|
|
url '1'
|
2013-09-21 15:16:16 +01:00
|
|
|
def self.reset_bottle; @bottle = Bottle.new; end
|
2013-06-08 16:48:43 +01:00
|
|
|
end
|
|
|
|
|
2012-03-07 17:29:05 -05:00
|
|
|
module Homebrew extend self
|
2013-03-11 18:56:26 +00:00
|
|
|
def keg_contains string, keg
|
|
|
|
quiet_system 'fgrep', '--recursive', '--quiet', '--max-count=1', string, keg
|
|
|
|
end
|
|
|
|
|
2013-06-04 20:39:09 +01:00
|
|
|
def bottle_output bottle
|
|
|
|
puts "bottle do"
|
|
|
|
prefix = bottle.prefix.to_s
|
|
|
|
puts " prefix '#{prefix}'" if prefix != '/usr/local'
|
2013-07-14 12:11:41 -07:00
|
|
|
cellar = if bottle.cellar.is_a? Symbol
|
|
|
|
":#{bottle.cellar}"
|
|
|
|
elsif bottle.cellar.to_s != '/usr/local/Cellar'
|
|
|
|
"'bottle.cellar'"
|
|
|
|
end
|
|
|
|
puts " cellar #{cellar}" if cellar
|
2013-06-04 20:39:09 +01:00
|
|
|
puts " revision #{bottle.revision}" if bottle.revision > 0
|
|
|
|
Checksum::TYPES.each do |checksum_type|
|
2013-06-22 10:14:51 +01:00
|
|
|
checksum_os_versions = bottle.send checksum_type
|
|
|
|
next unless checksum_os_versions
|
|
|
|
os_versions = checksum_os_versions.keys
|
|
|
|
os_versions.map! {|osx| MacOS::Version.from_symbol osx }
|
|
|
|
os_versions.sort.reverse.each do |os_version|
|
|
|
|
osx = os_version.to_sym
|
|
|
|
checksum = checksum_os_versions[osx]
|
|
|
|
puts " #{checksum_type} '#{checksum}' => :#{osx}"
|
2013-06-04 20:39:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
puts "end"
|
|
|
|
end
|
|
|
|
|
2012-03-07 17:29:05 -05:00
|
|
|
def bottle_formula f
|
2012-03-15 10:57:34 +13:00
|
|
|
unless f.installed?
|
2012-04-30 14:08:59 +10:00
|
|
|
return ofail "Formula not installed: #{f.name}"
|
2012-03-15 10:57:34 +13:00
|
|
|
end
|
|
|
|
|
2012-08-25 11:31:57 -07:00
|
|
|
unless built_as_bottle? f
|
2012-04-30 14:08:59 +10:00
|
|
|
return ofail "Formula not installed with '--build-bottle': #{f.name}"
|
2012-03-15 10:57:34 +13:00
|
|
|
end
|
2012-03-07 17:29:05 -05:00
|
|
|
|
2013-02-09 19:06:54 -08:00
|
|
|
bottle_revision = bottle_new_revision f
|
|
|
|
filename = bottle_filename f, bottle_revision
|
2013-07-04 11:23:09 +01:00
|
|
|
|
|
|
|
if bottle_filename_formula_name(filename).empty?
|
2013-08-04 08:25:51 -07:00
|
|
|
return ofail "Add a new regex to bottle_version.rb to parse the bottle filename."
|
2013-07-04 11:23:09 +01:00
|
|
|
end
|
|
|
|
|
2013-02-09 19:06:54 -08:00
|
|
|
bottle_path = Pathname.pwd/filename
|
|
|
|
sha1 = nil
|
2012-03-07 17:29:05 -05:00
|
|
|
|
2013-03-11 18:56:26 +00:00
|
|
|
prefix = HOMEBREW_PREFIX.to_s
|
|
|
|
tmp_prefix = '/tmp'
|
|
|
|
cellar = HOMEBREW_CELLAR.to_s
|
|
|
|
tmp_cellar = '/tmp/Cellar'
|
|
|
|
|
2012-03-07 17:29:05 -05:00
|
|
|
HOMEBREW_CELLAR.cd do
|
2013-09-21 15:15:50 +01:00
|
|
|
ohai "Bottling #{filename}..."
|
2012-03-07 17:29:05 -05:00
|
|
|
# Use gzip, faster to compress than bzip2, faster to uncompress than bzip2
|
|
|
|
# or an uncompressed tarball (and more bandwidth friendly).
|
2013-02-09 19:06:54 -08:00
|
|
|
safe_system 'tar', 'czf', bottle_path, "#{f.name}/#{f.version}"
|
|
|
|
sha1 = bottle_path.sha1
|
2013-03-11 18:56:26 +00:00
|
|
|
relocatable = false
|
|
|
|
|
2013-09-21 15:15:50 +01:00
|
|
|
ohai "Detecting if #{filename} is relocatable..."
|
2013-03-11 18:56:26 +00:00
|
|
|
keg = Keg.new f.prefix
|
|
|
|
keg.lock do
|
|
|
|
# Relocate bottle library references before testing for built-in
|
|
|
|
# references to the Cellar e.g. Qt's QMake annoyingly does this.
|
|
|
|
keg.relocate_install_names prefix, tmp_prefix, cellar, tmp_cellar
|
|
|
|
|
2013-09-10 21:56:39 +01:00
|
|
|
if prefix == '/usr/local'
|
|
|
|
prefix_check = HOMEBREW_PREFIX/'opt'
|
|
|
|
else
|
|
|
|
prefix_check = HOMEBREW_PREFIX
|
|
|
|
end
|
|
|
|
|
|
|
|
relocatable = !keg_contains(prefix_check, keg)
|
2013-03-11 18:56:26 +00:00
|
|
|
relocatable = !keg_contains(HOMEBREW_CELLAR, keg) if relocatable
|
|
|
|
|
|
|
|
# And do the same thing in reverse to change the library references
|
|
|
|
# back to how they were.
|
|
|
|
keg.relocate_install_names tmp_prefix, prefix, tmp_cellar, cellar
|
|
|
|
end
|
|
|
|
|
2013-06-04 20:39:09 +01:00
|
|
|
bottle = Bottle.new
|
|
|
|
bottle.prefix HOMEBREW_PREFIX
|
|
|
|
bottle.cellar relocatable ? :any : HOMEBREW_CELLAR
|
|
|
|
bottle.revision bottle_revision
|
|
|
|
bottle.sha1 sha1 => bottle_tag
|
2013-03-11 18:56:26 +00:00
|
|
|
|
2012-03-07 17:29:05 -05:00
|
|
|
puts "./#{filename}"
|
2013-06-04 20:39:09 +01:00
|
|
|
bottle_output bottle
|
2012-03-07 17:29:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-21 15:16:16 +01:00
|
|
|
def merge
|
|
|
|
merge_hash = {}
|
|
|
|
ARGV.named.each do |argument|
|
|
|
|
formula_name = bottle_filename_formula_name argument
|
|
|
|
merge_hash[formula_name] ||= []
|
|
|
|
bottle_block = IO.read argument
|
|
|
|
merge_hash[formula_name] << bottle_block
|
|
|
|
end
|
|
|
|
merge_hash.keys.each do |formula_name|
|
|
|
|
BottleMerger.reset_bottle
|
|
|
|
ohai formula_name
|
|
|
|
bottle_blocks = merge_hash[formula_name]
|
|
|
|
bottle_blocks.each do |bottle_block|
|
2013-06-08 16:48:43 +01:00
|
|
|
BottleMerger.class_eval bottle_block
|
|
|
|
end
|
|
|
|
bottle = BottleMerger.new.bottle
|
|
|
|
bottle_output bottle if bottle
|
|
|
|
end
|
2013-09-21 15:16:16 +01:00
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def bottle
|
|
|
|
merge if ARGV.include? '--merge'
|
2013-06-08 16:48:43 +01:00
|
|
|
|
|
|
|
ARGV.formulae.each do |f|
|
2013-06-23 13:02:02 -07:00
|
|
|
bottle_formula f
|
2012-03-07 17:29:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|