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'
|
2013-09-21 15:16:45 +01:00
|
|
|
require 'cmd/versions'
|
2013-09-21 21:30:57 +01:00
|
|
|
require 'utils/inreplace'
|
2013-09-21 21:21:42 +01:00
|
|
|
require 'erb'
|
2013-10-31 01:20:28 -07:00
|
|
|
require 'extend/pathname'
|
2012-03-07 17:29:05 -05:00
|
|
|
|
2013-09-21 21:21:42 +01:00
|
|
|
BOTTLE_ERB = <<-EOS
|
|
|
|
bottle do
|
2014-01-18 21:40:52 +00:00
|
|
|
<% if prefix.to_s != "/usr/local" %>
|
|
|
|
prefix "<%= prefix %>"
|
2013-09-21 21:21:42 +01:00
|
|
|
<% end %>
|
|
|
|
<% if cellar.is_a? Symbol %>
|
|
|
|
cellar :<%= cellar %>
|
2014-01-18 21:40:52 +00:00
|
|
|
<% elsif cellar.to_s != "/usr/local/Cellar" %>
|
|
|
|
cellar "<%= cellar %>"
|
2013-09-21 21:21:42 +01:00
|
|
|
<% end %>
|
|
|
|
<% if revision > 0 %>
|
|
|
|
revision <%= revision %>
|
|
|
|
<% end %>
|
2013-09-23 17:30:47 +01:00
|
|
|
<% checksums.each do |checksum_type, checksum_values| %>
|
|
|
|
<% checksum_values.each do |checksum_value| %>
|
|
|
|
<% checksum, osx = checksum_value.shift %>
|
2014-01-18 21:40:52 +00:00
|
|
|
<%= checksum_type %> "<%= checksum %>" => :<%= osx %>
|
2013-09-21 21:21:42 +01:00
|
|
|
<% end %>
|
2013-09-23 17:30:47 +01:00
|
|
|
<% end %>
|
2013-09-21 21:21:42 +01:00
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2012-03-07 17:29:05 -05:00
|
|
|
module Homebrew extend self
|
2013-09-21 21:30:57 +01:00
|
|
|
class << self
|
|
|
|
include Utils::Inreplace
|
|
|
|
end
|
|
|
|
|
2013-03-11 18:56:26 +00:00
|
|
|
def keg_contains string, keg
|
2013-10-31 01:20:28 -07:00
|
|
|
if not ARGV.homebrew_developer?
|
|
|
|
return quiet_system 'fgrep', '--recursive', '--quiet', '--max-count=1', string, keg
|
|
|
|
end
|
|
|
|
|
2013-12-17 20:46:42 -06:00
|
|
|
result = false
|
|
|
|
index = 0
|
2013-10-31 01:20:28 -07:00
|
|
|
|
2013-12-17 20:46:42 -06:00
|
|
|
keg.each_unique_file_matching(string) do |file|
|
2014-01-20 15:26:18 -08:00
|
|
|
if ARGV.verbose?
|
|
|
|
opoo "String '#{string}' still exists in these files:" if index.zero?
|
|
|
|
puts "#{Tty.red}#{file}#{Tty.reset}"
|
|
|
|
end
|
2013-10-31 01:20:28 -07:00
|
|
|
|
2013-12-05 16:39:39 -06:00
|
|
|
# Check dynamic library linkage. Importantly, do not run otool on static
|
|
|
|
# libraries, which will falsely report "linkage" to themselves.
|
|
|
|
if file.mach_o_executable? or file.dylib? or file.mach_o_bundle?
|
2013-12-14 09:35:58 -06:00
|
|
|
linked_libraries = file.dynamically_linked_libraries
|
2013-12-05 16:39:39 -06:00
|
|
|
linked_libraries = linked_libraries.select { |lib| lib.include? string }
|
2013-12-14 09:35:58 -06:00
|
|
|
else
|
|
|
|
linked_libraries = []
|
2013-12-05 16:39:39 -06:00
|
|
|
end
|
2013-10-31 01:20:28 -07:00
|
|
|
|
2014-01-20 15:26:18 -08:00
|
|
|
if ARGV.verbose?
|
|
|
|
linked_libraries.each do |lib|
|
|
|
|
puts " #{Tty.gray}-->#{Tty.reset} links to #{lib}"
|
|
|
|
end
|
2013-10-31 01:20:28 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
# Use strings to search through the file for each string
|
2013-12-14 15:43:15 -06:00
|
|
|
IO.popen("strings -t x - '#{file}'") do |io|
|
|
|
|
until io.eof?
|
|
|
|
str = io.readline.chomp
|
2013-10-31 01:20:28 -07:00
|
|
|
|
2013-12-14 15:43:15 -06:00
|
|
|
next unless str.include? string
|
|
|
|
|
|
|
|
offset, match = str.split(" ", 2)
|
|
|
|
|
|
|
|
next if linked_libraries.include? match # Don't bother reporting a string if it was found by otool
|
2014-01-20 15:26:18 -08:00
|
|
|
if ARGV.verbose?
|
|
|
|
puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}"
|
|
|
|
end
|
2013-12-14 15:43:15 -06:00
|
|
|
end
|
2013-10-31 01:20:28 -07:00
|
|
|
end
|
2013-12-17 20:46:42 -06:00
|
|
|
|
|
|
|
index += 1
|
|
|
|
result = true
|
2013-10-31 01:20:28 -07:00
|
|
|
end
|
2013-12-17 20:46:42 -06:00
|
|
|
|
2014-03-18 19:03:24 -05:00
|
|
|
index = 0
|
2014-03-27 17:05:17 -05:00
|
|
|
keg.find do |pn|
|
2014-03-18 19:03:24 -05:00
|
|
|
if pn.symlink? && (link = pn.readlink).absolute?
|
|
|
|
if link.to_s.start_with?(string)
|
|
|
|
opoo "Absolute symlink starting with #{string}:" if index.zero?
|
|
|
|
puts " #{pn} -> #{pn.resolved_path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
index += 1
|
|
|
|
result = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-17 20:46:42 -06:00
|
|
|
result
|
2013-03-11 18:56:26 +00:00
|
|
|
end
|
|
|
|
|
2013-06-04 20:39:09 +01:00
|
|
|
def bottle_output bottle
|
2013-09-21 21:21:42 +01:00
|
|
|
erb = ERB.new BOTTLE_ERB
|
|
|
|
erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, '')
|
2013-06-04 20:39:09 +01:00
|
|
|
end
|
|
|
|
|
2012-03-07 17:29:05 -05:00
|
|
|
def bottle_formula f
|
2012-03-15 10:57:34 +13:00
|
|
|
unless f.installed?
|
2014-01-04 14:50:13 +00:00
|
|
|
return ofail "Formula not installed or up-to-date: #{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
|
|
|
|
2014-02-15 11:28:48 +00:00
|
|
|
unless f.stable
|
|
|
|
return ofail "Formula has no stable version: #{f.name}"
|
|
|
|
end
|
|
|
|
|
2013-12-10 15:16:22 -06:00
|
|
|
if ARGV.include? '--no-revision'
|
|
|
|
bottle_revision = 0
|
|
|
|
else
|
2014-03-05 20:12:51 -06:00
|
|
|
max = f.bottle_version_map('origin/master')[f.pkg_version].max
|
2013-12-10 15:16:22 -06:00
|
|
|
bottle_revision = max ? max + 1 : 0
|
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
filename = bottle_filename(
|
|
|
|
:name => f.name,
|
|
|
|
:version => f.pkg_version,
|
|
|
|
:revision => bottle_revision,
|
|
|
|
:tag => bottle_tag
|
|
|
|
)
|
2013-07-04 11:23:09 +01:00
|
|
|
|
|
|
|
if bottle_filename_formula_name(filename).empty?
|
2014-02-22 17:15:28 +00:00
|
|
|
return ofail "Add a new regex to bottle_version.rb to parse #{f.version} from #{filename}"
|
2013-07-04 11:23:09 +01:00
|
|
|
end
|
|
|
|
|
2013-02-09 19:06:54 -08:00
|
|
|
bottle_path = Pathname.pwd/filename
|
2012-03-07 17:29:05 -05:00
|
|
|
|
2013-03-11 18:56:26 +00:00
|
|
|
prefix = HOMEBREW_PREFIX.to_s
|
|
|
|
cellar = HOMEBREW_CELLAR.to_s
|
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
ohai "Bottling #{filename}..."
|
2013-09-21 21:21:42 +01:00
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
keg = Keg.new(f.prefix)
|
|
|
|
relocatable = false
|
2013-12-04 22:37:57 -06:00
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
keg.lock do
|
|
|
|
begin
|
|
|
|
keg.relocate_install_names prefix, Keg::PREFIX_PLACEHOLDER,
|
|
|
|
cellar, Keg::CELLAR_PLACEHOLDER, :keg_only => f.keg_only?
|
2014-03-13 09:06:22 +00:00
|
|
|
keg.delete_pyc_files!
|
2013-12-04 22:37:57 -06:00
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
HOMEBREW_CELLAR.cd do
|
2013-12-04 22:37:57 -06:00
|
|
|
# Use gzip, faster to compress than bzip2, faster to uncompress than bzip2
|
|
|
|
# or an uncompressed tarball (and more bandwidth friendly).
|
2014-03-05 20:12:51 -06:00
|
|
|
safe_system 'tar', 'czf', bottle_path, "#{f.name}/#{f.pkg_version}"
|
2013-12-12 19:46:37 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
if File.size?(bottle_path) > 1*1024*1024
|
|
|
|
ohai "Detecting if #{filename} is relocatable..."
|
|
|
|
end
|
2013-12-04 22:37:57 -06:00
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
if prefix == '/usr/local'
|
|
|
|
prefix_check = HOMEBREW_PREFIX/'opt'
|
|
|
|
else
|
|
|
|
prefix_check = HOMEBREW_PREFIX
|
|
|
|
end
|
|
|
|
|
|
|
|
relocatable = !keg_contains(prefix_check, keg)
|
|
|
|
relocatable = !keg_contains(HOMEBREW_CELLAR, keg) && relocatable
|
2014-01-20 15:26:18 -08:00
|
|
|
puts if !relocatable && ARGV.verbose?
|
2013-12-12 19:46:37 -06:00
|
|
|
rescue Interrupt
|
|
|
|
ignore_interrupts { bottle_path.unlink if bottle_path.exist? }
|
|
|
|
raise
|
|
|
|
ensure
|
|
|
|
ignore_interrupts do
|
|
|
|
keg.relocate_install_names Keg::PREFIX_PLACEHOLDER, prefix,
|
|
|
|
Keg::CELLAR_PLACEHOLDER, cellar, :keg_only => f.keg_only?
|
2013-12-04 22:37:57 -06:00
|
|
|
end
|
|
|
|
end
|
2013-12-12 19:46:37 -06:00
|
|
|
end
|
2013-12-04 22:37:57 -06:00
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
bottle = BottleSpecification.new
|
2013-12-12 19:46:37 -06:00
|
|
|
bottle.prefix HOMEBREW_PREFIX
|
|
|
|
bottle.cellar relocatable ? :any : HOMEBREW_CELLAR
|
|
|
|
bottle.revision bottle_revision
|
|
|
|
bottle.sha1 bottle_path.sha1 => bottle_tag
|
2013-03-11 18:56:26 +00:00
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
output = bottle_output bottle
|
2013-03-11 18:56:26 +00:00
|
|
|
|
2013-12-12 19:46:37 -06:00
|
|
|
puts "./#{filename}"
|
|
|
|
puts output
|
2013-09-21 21:24:50 +01:00
|
|
|
|
|
|
|
if ARGV.include? '--rb'
|
|
|
|
bottle_base = filename.gsub(bottle_suffix(bottle_revision), '')
|
|
|
|
File.open "#{bottle_base}.bottle.rb", 'w' do |file|
|
|
|
|
file.write output
|
|
|
|
end
|
|
|
|
end
|
2012-03-07 17:29:05 -05:00
|
|
|
end
|
|
|
|
|
2014-03-11 09:16:14 -05:00
|
|
|
module BottleMerger
|
|
|
|
def bottle(&block)
|
|
|
|
instance_eval(&block)
|
|
|
|
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
|
2014-03-10 14:56:02 -05:00
|
|
|
|
|
|
|
merge_hash.each do |formula_name, bottle_blocks|
|
2013-09-21 15:16:16 +01:00
|
|
|
ohai formula_name
|
2014-03-10 14:56:02 -05:00
|
|
|
|
2014-03-11 09:16:14 -05:00
|
|
|
bottle = BottleSpecification.new.extend(BottleMerger)
|
2014-03-10 14:56:02 -05:00
|
|
|
bottle_blocks.each { |block| bottle.instance_eval(block) }
|
|
|
|
|
2013-09-21 21:30:57 +01:00
|
|
|
output = bottle_output bottle
|
|
|
|
puts output
|
|
|
|
|
|
|
|
if ARGV.include? '--write'
|
|
|
|
f = Formula.factory formula_name
|
2014-01-31 19:07:49 +01:00
|
|
|
update_or_add = nil
|
2013-12-27 16:43:34 -06:00
|
|
|
|
|
|
|
inreplace f.path do |s|
|
2014-01-31 19:07:49 +01:00
|
|
|
if s.include? 'bottle do'
|
2014-02-09 14:34:37 +00:00
|
|
|
update_or_add = 'update'
|
2014-01-31 19:07:49 +01:00
|
|
|
string = s.sub!(/ bottle do.+?end\n/m, output)
|
2014-02-09 14:34:37 +00:00
|
|
|
odie 'Bottle block update failed!' unless string
|
2013-09-21 21:30:57 +01:00
|
|
|
else
|
2014-02-09 14:34:37 +00:00
|
|
|
update_or_add = 'add'
|
2014-03-04 17:34:12 +00:00
|
|
|
string = s.sub!(/( (url|sha1|sha256|head|version) ['"][\S ]+['"]\n+)+/m, '\0' + output + "\n")
|
2014-01-31 19:07:49 +01:00
|
|
|
odie 'Bottle block addition failed!' unless string
|
2013-09-21 21:30:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-01 10:25:07 -08:00
|
|
|
safe_system 'git', 'commit', '--no-edit', '--verbose',
|
|
|
|
"--message=#{f.name}: #{update_or_add} #{f.version} bottle.",
|
2013-12-27 16:43:34 -06:00
|
|
|
'--', f.path
|
2013-09-21 21:30:57 +01:00
|
|
|
end
|
2013-06-08 16:48:43 +01:00
|
|
|
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
|