aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorMike McQuaid2013-03-11 18:56:26 +0000
committerMike McQuaid2013-03-11 18:58:37 +0000
commit0f9910d352e460fe7d93544d91cdc1eb53a9631c (patch)
treebd424a5196ae9896a632a1686fdb9debffef4442 /Library/Homebrew/cmd
parent258d70028f359e88b3300fdd1b8442428ef75826 (diff)
downloadbrew-0f9910d352e460fe7d93544d91cdc1eb53a9631c.tar.bz2
Relocate bottles using install_name_tool.
This has two parts: 1. Bottles are temporarily relocated on bottling and tested if that is sufficient for them to contain no longer reference the prefix or cellar. If so, they are marked as relocatable. 2. On installation if bottles are marked as relocatable they will be relocated using install_name_tool to the current prefix and cellar. Closes Homebrew/homebrew#18374.
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/bottle.rb48
1 files changed, 39 insertions, 9 deletions
diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb
index cda1d776d..6f703d4b3 100644
--- a/Library/Homebrew/cmd/bottle.rb
+++ b/Library/Homebrew/cmd/bottle.rb
@@ -1,8 +1,13 @@
require 'formula'
require 'bottles'
require 'tab'
+require 'keg'
module Homebrew extend self
+ def keg_contains string, keg
+ quiet_system 'fgrep', '--recursive', '--quiet', '--max-count=1', string, keg
+ end
+
def bottle_formula f
unless f.installed?
return ofail "Formula not installed: #{f.name}"
@@ -18,23 +23,48 @@ module Homebrew extend self
bottle_path = Pathname.pwd/filename
sha1 = nil
+ prefix = HOMEBREW_PREFIX.to_s
+ tmp_prefix = '/tmp'
+ cellar = HOMEBREW_CELLAR.to_s
+ tmp_cellar = '/tmp/Cellar'
+
HOMEBREW_CELLAR.cd do
ohai "Bottling #{f.name} #{f.version}..."
- bottle_relocatable = !quiet_system(
- 'grep', '--recursive', '--quiet', '--max-count=1',
- HOMEBREW_CELLAR, "#{f.name}/#{f.version}")
- cellar = nil
- if bottle_relocatable
- cellar = ':any'
- elsif HOMEBREW_CELLAR.to_s != '/usr/local/Cellar'
- cellar = "'#{HOMEBREW_CELLAR}'"
- end
# Use gzip, faster to compress than bzip2, faster to uncompress than bzip2
# or an uncompressed tarball (and more bandwidth friendly).
safe_system 'tar', 'czf', bottle_path, "#{f.name}/#{f.version}"
sha1 = bottle_path.sha1
+ relocatable = false
+
+ 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
+
+ relocatable = !keg_contains(HOMEBREW_PREFIX, keg)
+ 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
+
+ prefix = cellar = nil
+ if relocatable
+ cellar = ':any'
+ else
+ if HOMEBREW_PREFIX.to_s != '/usr/local'
+ prefix = "'#{HOMEBREW_PREFIX}"
+ end
+ if HOMEBREW_CELLAR.to_s != '/usr/local/Cellar'
+ cellar = "'#{HOMEBREW_CELLAR}'"
+ end
+ end
+
puts "./#{filename}"
puts "bottle do"
+ puts " prefix #{prefix}" if prefix
puts " cellar #{cellar}" if cellar
puts " revision #{bottle_revision}" if bottle_revision > 0
puts " sha1 '#{sha1}' => :#{MacOS.cat}"