| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |     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 | 
					
						
							|  |  |  |       ohai "Bottling #{f.name} #{f.version}..." | 
					
						
							|  |  |  |       # 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 17:29:05 -05:00
										 |  |  |       puts "./#{filename}" | 
					
						
							|  |  |  |       puts "bottle do" | 
					
						
							| 
									
										
										
										
											2013-03-11 18:56:26 +00:00
										 |  |  |       puts "  prefix #{prefix}" if prefix | 
					
						
							| 
									
										
										
										
											2013-02-28 22:14:59 +00:00
										 |  |  |       puts "  cellar #{cellar}" if cellar | 
					
						
							| 
									
										
										
										
											2013-02-09 19:06:54 -08:00
										 |  |  |       puts "  revision #{bottle_revision}" if bottle_revision > 0
 | 
					
						
							|  |  |  |       puts "  sha1 '#{sha1}' => :#{MacOS.cat}" | 
					
						
							| 
									
										
										
										
											2012-03-07 17:29:05 -05:00
										 |  |  |       puts "end" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bottle | 
					
						
							|  |  |  |     ARGV.formulae.each do|f| | 
					
						
							|  |  |  |       bottle_formula Formula.factory f | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |