| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							|  |  |  | require "bottles" | 
					
						
							|  |  |  | require "tab" | 
					
						
							|  |  |  | require "keg" | 
					
						
							|  |  |  | require "formula_versions" | 
					
						
							|  |  |  | require "utils/inreplace" | 
					
						
							|  |  |  | require "erb" | 
					
						
							|  |  |  | require "extend/pathname" | 
					
						
							| 
									
										
										
										
											2012-03-07 17:29:05 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 21:21:42 +01:00
										 |  |  | BOTTLE_ERB = <<-EOS
 | 
					
						
							|  |  |  |   bottle do | 
					
						
							| 
									
										
										
										
											2015-07-03 21:42:09 +08:00
										 |  |  |     <% if  !root_url.start_with?(BottleSpecification::DEFAULT_DOMAIN) %> | 
					
						
							| 
									
										
										
										
											2014-05-09 17:38:12 +09:00
										 |  |  |     root_url "<%= root_url %>" | 
					
						
							|  |  |  |     <% end  %> | 
					
						
							| 
									
										
										
										
											2014-07-12 22:43:35 -05:00
										 |  |  |     <% if  prefix != BottleSpecification::DEFAULT_PREFIX %> | 
					
						
							| 
									
										
										
										
											2014-01-18 21:40:52 +00:00
										 |  |  |     prefix "<%= prefix %>" | 
					
						
							| 
									
										
										
										
											2013-09-21 21:21:42 +01:00
										 |  |  |     <% end  %> | 
					
						
							|  |  |  |     <% if  cellar.is_a? Symbol %> | 
					
						
							|  |  |  |     cellar :<%= cellar %> | 
					
						
							| 
									
										
										
										
											2014-07-12 22:43:35 -05:00
										 |  |  |     <% elsif  cellar != BottleSpecification::DEFAULT_CELLAR %> | 
					
						
							| 
									
										
										
										
											2014-01-18 21:40:52 +00:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:55:22 +01:00
										 |  |  | MAXIMUM_STRING_MATCHES = 100
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def keg_contains(string, keg, ignores) | 
					
						
							| 
									
										
										
										
											2015-12-26 23:00:38 +01:00
										 |  |  |     @put_string_exists_header, @put_filenames = nil | 
					
						
							| 
									
										
										
										
											2015-02-26 19:13:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def print_filename(string, filename) | 
					
						
							| 
									
										
										
										
											2015-02-26 19:13:10 +00:00
										 |  |  |       unless @put_string_exists_header | 
					
						
							|  |  |  |         opoo "String '#{string}' still exists in these files:" | 
					
						
							|  |  |  |         @put_string_exists_header = true | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-10-31 01:20:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-26 19:13:10 +00:00
										 |  |  |       @put_filenames ||= [] | 
					
						
							|  |  |  |       unless @put_filenames.include? filename | 
					
						
							|  |  |  |         puts "#{Tty.red}#{filename}#{Tty.reset}" | 
					
						
							|  |  |  |         @put_filenames << filename | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-02-20 14:29:43 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 20:46:42 -06:00
										 |  |  |     result = false | 
					
						
							| 
									
										
										
										
											2013-10-31 01:20:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 20:46:42 -06:00
										 |  |  |     keg.each_unique_file_matching(string) do |file| | 
					
						
							| 
									
										
										
										
											2015-07-10 19:51:43 +08:00
										 |  |  |       # skip document file. | 
					
						
							|  |  |  |       next if Metafiles::EXTENSIONS.include? file.extname | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       if file.mach_o_executable? || file.dylib? || 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 } | 
					
						
							| 
									
										
										
										
											2015-02-20 14:29:43 +00:00
										 |  |  |         result ||= linked_libraries.any? | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2015-02-20 14:29:43 +00:00
										 |  |  |         print_filename(string, file) if linked_libraries.any? | 
					
						
							| 
									
										
										
										
											2014-01-20 15:26:18 -08:00
										 |  |  |         linked_libraries.each do |lib| | 
					
						
							|  |  |  |           puts " #{Tty.gray}-->#{Tty.reset} links to #{lib}" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-31 01:20:28 -07:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:55:22 +01:00
										 |  |  |       text_matches = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 01:20:28 -07:00
										 |  |  |       # Use strings to search through the file for each string | 
					
						
							| 
									
										
										
										
											2014-07-05 13:50:54 -05:00
										 |  |  |       Utils.popen_read("strings", "-t", "x", "-", file.to_s) do |io| | 
					
						
							| 
									
										
										
										
											2013-12-14 15:43:15 -06:00
										 |  |  |         until io.eof? | 
					
						
							|  |  |  |           str = io.readline.chomp | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |           next if ignores.any? { |i| i =~ str } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2015-09-11 16:49:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |           result = true | 
					
						
							| 
									
										
										
										
											2015-09-23 14:55:22 +01:00
										 |  |  |           text_matches << [match, offset] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ARGV.verbose? && text_matches.any? | 
					
						
							|  |  |  |         print_filename string, file | 
					
						
							|  |  |  |         text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset| | 
					
						
							|  |  |  |           puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2015-02-20 14:29:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:55:22 +01:00
										 |  |  |         if text_matches.size > MAXIMUM_STRING_MATCHES | 
					
						
							|  |  |  |           puts "Only the first #{MAXIMUM_STRING_MATCHES} matches were output" | 
					
						
							| 
									
										
										
										
											2013-12-14 15:43:15 -06:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-31 01:20:28 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-12-17 20:46:42 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 16:49:39 +08:00
										 |  |  |     absolute_symlinks_start_with_string = [] | 
					
						
							|  |  |  |     absolute_symlinks_rest = [] | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2015-09-11 16:49:39 +08:00
										 |  |  |         if link.to_s.start_with?(string) | 
					
						
							|  |  |  |           absolute_symlinks_start_with_string << pn | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           absolute_symlinks_rest << pn | 
					
						
							| 
									
										
										
										
											2014-03-18 19:03:24 -05:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         result = true | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 16:49:39 +08:00
										 |  |  |     if ARGV.verbose? | 
					
						
							|  |  |  |       if absolute_symlinks_start_with_string.any? | 
					
						
							|  |  |  |         opoo "Absolute symlink starting with #{string}:" | 
					
						
							|  |  |  |         absolute_symlinks_start_with_string.each do |pn| | 
					
						
							|  |  |  |           puts "  #{pn} -> #{pn.resolved_path}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if absolute_symlinks_rest.any? | 
					
						
							|  |  |  |         opoo "Absolute symlink:" | 
					
						
							|  |  |  |         absolute_symlinks_rest.each do |pn| | 
					
						
							|  |  |  |           puts "  #{pn} -> #{pn.resolved_path}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 20:46:42 -06:00
										 |  |  |     result | 
					
						
							| 
									
										
										
										
											2013-03-11 18:56:26 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def bottle_output(bottle) | 
					
						
							| 
									
										
										
										
											2013-09-21 21:21:42 +01:00
										 |  |  |     erb = ERB.new BOTTLE_ERB | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "") | 
					
						
							| 
									
										
										
										
											2013-06-04 20:39:09 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def bottle_formula(f) | 
					
						
							| 
									
										
										
										
											2012-03-15 10:57:34 +13:00
										 |  |  |     unless f.installed? | 
					
						
							| 
									
										
										
										
											2015-05-27 20:44:51 +08:00
										 |  |  |       return ofail "Formula not installed or up-to-date: #{f.full_name}" | 
					
						
							| 
									
										
										
										
											2012-03-15 10:57:34 +13:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-26 13:15:29 +08:00
										 |  |  |     unless f.tap | 
					
						
							|  |  |  |       return ofail "Formula not from core or any taps: #{f.full_name}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 20:06:27 +08:00
										 |  |  |     if f.bottle_disabled? | 
					
						
							|  |  |  |       ofail "Formula has disabled bottle: #{f.full_name}" | 
					
						
							|  |  |  |       puts f.bottle_disable_reason | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-25 11:31:57 -07:00
										 |  |  |     unless built_as_bottle? f | 
					
						
							| 
									
										
										
										
											2015-05-27 20:44:51 +08:00
										 |  |  |       return ofail "Formula not installed with '--build-bottle': #{f.full_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 | 
					
						
							| 
									
										
										
										
											2015-05-27 20:44:51 +08:00
										 |  |  |       return ofail "Formula has no stable version: #{f.full_name}" | 
					
						
							| 
									
										
										
										
											2014-02-15 11:28:48 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     if ARGV.include? "--no-revision" | 
					
						
							| 
									
										
										
										
											2015-05-28 23:57:02 -04:00
										 |  |  |       bottle_revision = 0
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |     elsif ARGV.include? "--keep-old" | 
					
						
							|  |  |  |       bottle_revision = f.bottle_specification.revision | 
					
						
							| 
									
										
										
										
											2015-05-28 23:57:02 -04:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2015-05-27 20:44:51 +08:00
										 |  |  |       ohai "Determining #{f.full_name} bottle revision..." | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       versions = FormulaVersions.new(f) | 
					
						
							| 
									
										
										
										
											2015-04-13 12:57:03 -04:00
										 |  |  |       bottle_revisions = versions.bottle_version_map("origin/master")[f.pkg_version] | 
					
						
							| 
									
										
										
										
											2015-05-28 23:57:02 -04:00
										 |  |  |       bottle_revisions.pop if bottle_revisions.last.to_i > 0
 | 
					
						
							|  |  |  |       bottle_revision = bottle_revisions.any? ? bottle_revisions.max.to_i + 1 : 0
 | 
					
						
							| 
									
										
										
										
											2013-12-10 15:16:22 -06:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     filename = Bottle::Filename.create(f, bottle_tag, bottle_revision) | 
					
						
							| 
									
										
										
										
											2013-02-09 19:06:54 -08:00
										 |  |  |     bottle_path = Pathname.pwd/filename | 
					
						
							| 
									
										
										
										
											2012-03-07 17:29:05 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |     tar_filename = filename.to_s.sub(/.gz$/, "") | 
					
						
							|  |  |  |     tar_path = Pathname.pwd/tar_filename | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2015-09-11 19:13:52 +08:00
										 |  |  |     skip_relocation = false | 
					
						
							| 
									
										
										
										
											2013-12-04 22:37:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |     keg.lock do | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |       original_tab = nil | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |       begin | 
					
						
							|  |  |  |         keg.relocate_install_names prefix, Keg::PREFIX_PLACEHOLDER, | 
					
						
							| 
									
										
										
										
											2015-11-08 23:01:03 +01:00
										 |  |  |           cellar, Keg::CELLAR_PLACEHOLDER | 
					
						
							| 
									
										
										
										
											2015-09-11 18:55:46 +08:00
										 |  |  |         keg.relocate_text_files prefix, Keg::PREFIX_PLACEHOLDER, | 
					
						
							|  |  |  |           cellar, Keg::CELLAR_PLACEHOLDER | 
					
						
							| 
									
										
										
										
											2015-09-11 19:13:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 09:06:22 +00:00
										 |  |  |         keg.delete_pyc_files! | 
					
						
							| 
									
										
										
										
											2013-12-04 22:37:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 15:52:45 +08:00
										 |  |  |         Tab.clear_cache | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |         tab = Tab.for_keg(keg) | 
					
						
							|  |  |  |         original_tab = tab.dup | 
					
						
							| 
									
										
										
										
											2015-12-16 02:12:50 +01:00
										 |  |  |         tab.poured_from_bottle = false | 
					
						
							|  |  |  |         tab.HEAD = nil | 
					
						
							|  |  |  |         tab.time = nil | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |         tab.write | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-14 19:01:31 +08:00
										 |  |  |         keg.find {|k| File.utime(File.atime(k), tab.source_modified_time, k) } | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 14:46:05 -05:00
										 |  |  |         cd cellar do | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |           safe_system "tar", "cf", tar_path, "#{f.name}/#{f.pkg_version}" | 
					
						
							| 
									
										
										
										
											2016-01-14 19:01:31 +08:00
										 |  |  |           File.utime(File.atime(tar_path), tab.source_modified_time, tar_path) | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |           relocatable_tar_path = "#{f}-bottle.tar" | 
					
						
							|  |  |  |           mv tar_path, relocatable_tar_path | 
					
						
							| 
									
										
										
										
											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). | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |           safe_system "gzip", "-f", relocatable_tar_path | 
					
						
							|  |  |  |           mv "#{relocatable_tar_path}.gz", bottle_path | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 14:56:38 -05:00
										 |  |  |         if bottle_path.size > 1*1024*1024
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |           ohai "Detecting if #{filename} is relocatable..." | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-12-04 22:37:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         if prefix == "/usr/local" | 
					
						
							| 
									
										
										
										
											2014-07-17 14:46:05 -05:00
										 |  |  |           prefix_check = File.join(prefix, "opt") | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2014-07-17 14:46:05 -05:00
										 |  |  |           prefix_check = prefix | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-20 14:29:43 +00:00
										 |  |  |         ignores = [] | 
					
						
							|  |  |  |         if f.deps.any? { |dep| dep.name == "go" } | 
					
						
							|  |  |  |           ignores << %r{#{HOMEBREW_CELLAR}/go/[\d\.]+/libexec} | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         relocatable = !keg_contains(prefix_check, keg, ignores) | 
					
						
							|  |  |  |         relocatable = !keg_contains(cellar, keg, ignores) && relocatable | 
					
						
							| 
									
										
										
										
											2015-09-11 19:13:52 +08:00
										 |  |  |         skip_relocation = relocatable && !keg.require_install_name_tool? | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2015-12-15 14:21:27 +00:00
										 |  |  |           original_tab.write | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |           keg.relocate_install_names Keg::PREFIX_PLACEHOLDER, prefix, | 
					
						
							| 
									
										
										
										
											2015-11-08 23:01:03 +01:00
										 |  |  |             Keg::CELLAR_PLACEHOLDER, cellar | 
					
						
							| 
									
										
										
										
											2016-01-26 15:50:17 +08:00
										 |  |  |           keg.relocate_text_files Keg::PREFIX_PLACEHOLDER, prefix, | 
					
						
							|  |  |  |             Keg::CELLAR_PLACEHOLDER, cellar | 
					
						
							| 
									
										
										
										
											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-11-24 08:25:05 +00:00
										 |  |  |     root_url = ARGV.value("root-url") | 
					
						
							|  |  |  |     # Use underscored version for legacy reasons. Remove at some point. | 
					
						
							|  |  |  |     root_url ||= ARGV.value("root_url") | 
					
						
							| 
									
										
										
										
											2014-05-09 17:38:12 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     bottle = BottleSpecification.new | 
					
						
							| 
									
										
										
										
											2014-05-09 17:38:12 +09:00
										 |  |  |     bottle.root_url(root_url) if root_url | 
					
						
							| 
									
										
										
										
											2015-09-11 19:13:52 +08:00
										 |  |  |     if relocatable | 
					
						
							|  |  |  |       if skip_relocation | 
					
						
							|  |  |  |         bottle.cellar :any_skip_relocation | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         bottle.cellar :any | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       bottle.cellar cellar | 
					
						
							| 
									
										
										
										
											2015-09-11 19:15:22 +08:00
										 |  |  |       bottle.prefix prefix | 
					
						
							| 
									
										
										
										
											2015-09-11 19:13:52 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-12-12 19:46:37 -06:00
										 |  |  |     bottle.revision bottle_revision | 
					
						
							| 
									
										
										
										
											2015-02-24 23:25:57 +00:00
										 |  |  |     bottle.sha256 bottle_path.sha256 => bottle_tag | 
					
						
							| 
									
										
										
										
											2013-03-11 18:56:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |     old_spec = f.bottle_specification | 
					
						
							|  |  |  |     if ARGV.include?("--keep-old") && !old_spec.checksums.empty? | 
					
						
							| 
									
										
										
										
											2015-09-11 11:16:15 +01:00
										 |  |  |       bad_fields = [:root_url, :prefix, :cellar, :revision].select do |field| | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |         old_spec.send(field) != bottle.send(field) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-09-12 16:33:11 +08:00
										 |  |  |       bad_fields.delete(:cellar) if old_spec.cellar == :any && bottle.cellar == :any_skip_relocation | 
					
						
							| 
									
										
										
										
											2015-09-11 11:16:15 +01:00
										 |  |  |       if bad_fields.any? | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |         bottle_path.unlink if bottle_path.exist? | 
					
						
							| 
									
										
										
										
											2015-09-11 11:16:15 +01:00
										 |  |  |         odie "--keep-old is passed but there are changes in: #{bad_fields.join ", "}" | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     if ARGV.include? "--rb" | 
					
						
							| 
									
										
										
										
											2015-05-27 23:00:42 +08:00
										 |  |  |       File.open("#{filename.prefix}.bottle.rb", "w") do |file| | 
					
						
							|  |  |  |         file.write("\# #{f.full_name}\n") | 
					
						
							|  |  |  |         file.write(output) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-09-21 21:24:50 +01:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |     write = ARGV.include? "--write" | 
					
						
							|  |  |  |     keep_old = ARGV.include? "--keep-old" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 15:16:16 +01:00
										 |  |  |     merge_hash = {} | 
					
						
							|  |  |  |     ARGV.named.each do |argument| | 
					
						
							| 
									
										
										
										
											2015-05-27 23:00:42 +08:00
										 |  |  |       bottle_block = IO.read(argument) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       formula_name = bottle_block.lines.first.sub(/^# /, "").chomp | 
					
						
							| 
									
										
										
										
											2013-09-21 15:16:16 +01:00
										 |  |  |       merge_hash[formula_name] ||= [] | 
					
						
							|  |  |  |       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 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |       f = Formulary.factory(formula_name) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 20:06:27 +08:00
										 |  |  |       if f.bottle_disabled? | 
					
						
							|  |  |  |         ofail "Formula #{f.full_name} has disabled bottle" | 
					
						
							|  |  |  |         puts f.bottle_disable_reason | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |       bottle = if keep_old | 
					
						
							|  |  |  |         f.bottle_specification.dup | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         BottleSpecification.new | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       bottle.extend(BottleMerger) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |       bottle_blocks.each { |block| bottle.instance_eval(block) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |       old_spec = f.bottle_specification | 
					
						
							|  |  |  |       if keep_old && !old_spec.checksums.empty? | 
					
						
							| 
									
										
										
										
											2015-09-11 18:36:40 +08:00
										 |  |  |          bad_fields = [:root_url, :prefix, :cellar, :revision].select do |field| | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |            old_spec.send(field) != bottle.send(field) | 
					
						
							|  |  |  |          end | 
					
						
							| 
									
										
										
										
											2015-09-12 16:33:11 +08:00
										 |  |  |          bad_fields.delete(:cellar) if old_spec.cellar == :any && bottle.cellar == :any_skip_relocation | 
					
						
							| 
									
										
										
										
											2015-09-11 18:36:40 +08:00
										 |  |  |          if bad_fields.any? | 
					
						
							|  |  |  |            ofail "--keep-old is passed but there are changes in: #{bad_fields.join ", "}" | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |            next | 
					
						
							|  |  |  |          end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 21:30:57 +01:00
										 |  |  |       output = bottle_output bottle | 
					
						
							|  |  |  |       puts output | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:47:22 +08:00
										 |  |  |       if write | 
					
						
							| 
									
										
										
										
											2014-01-31 19:07:49 +01:00
										 |  |  |         update_or_add = nil | 
					
						
							| 
									
										
										
										
											2013-12-27 16:43:34 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 19:23:42 -05:00
										 |  |  |         Utils::Inreplace.inreplace(f.path) do |s| | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |           if s.include? "bottle do" | 
					
						
							|  |  |  |             update_or_add = "update" | 
					
						
							| 
									
										
										
										
											2014-01-31 19:07:49 +01:00
										 |  |  |             string = s.sub!(/  bottle do.+?end\n/m, output) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |             odie "Bottle block update failed!" unless string | 
					
						
							| 
									
										
										
										
											2013-09-21 21:30:57 +01:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |             update_or_add = "add" | 
					
						
							|  |  |  |             if s.include? "stable do" | 
					
						
							| 
									
										
										
										
											2015-02-21 18:57:29 +08:00
										 |  |  |               indent = s.slice(/^ +stable do/).length - "stable do".length | 
					
						
							|  |  |  |               string = s.sub!(/^ {#{indent}}stable do(.|\n)+?^ {#{indent}}end\n/m, '\0' + output + "\n") | 
					
						
							|  |  |  |             else | 
					
						
							| 
									
										
										
										
											2015-06-07 16:44:03 +08:00
										 |  |  |               string = s.sub!( | 
					
						
							|  |  |  |                 /(
 | 
					
						
							| 
									
										
										
										
											2016-01-11 00:26:48 +07:00
										 |  |  |                   \ {2}(                                                         # two spaces at the beginning | 
					
						
							|  |  |  |                     (url|head)\ ['"][\S\ ]+['"]                                  # url or head with a string
 | 
					
						
							| 
									
										
										
										
											2015-06-07 16:44:03 +08:00
										 |  |  |                     ( | 
					
						
							| 
									
										
										
										
											2016-01-11 00:26:48 +07:00
										 |  |  |                       ,[\S\ ]*$                                                  # url may have options | 
					
						
							|  |  |  |                       (\n^\ {3}[\S\ ]+$)*                                        # options can be in multiple lines | 
					
						
							| 
									
										
										
										
											2015-06-07 16:44:03 +08:00
										 |  |  |                     )?| | 
					
						
							| 
									
										
										
										
											2016-01-11 00:26:48 +07:00
										 |  |  |                     (homepage|desc|sha1|sha256|version|mirror)\ ['"][\S\ ]+['"]| # specs with a string
 | 
					
						
							|  |  |  |                     revision\ \d+                                                # revision with a number | 
					
						
							|  |  |  |                   )\n+                                                           # multiple empty lines | 
					
						
							| 
									
										
										
										
											2015-06-07 16:44:03 +08:00
										 |  |  |                  )+ | 
					
						
							|  |  |  |                /mx, '\0' + output + "\n")
 | 
					
						
							| 
									
										
										
										
											2015-02-21 18:57:29 +08:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |             odie "Bottle block addition failed!" unless string | 
					
						
							| 
									
										
										
										
											2013-09-21 21:30:57 +01:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 15:12:02 +08:00
										 |  |  |         unless ARGV.include? "--no-commit" | 
					
						
							|  |  |  |           f.path.parent.cd do | 
					
						
							|  |  |  |             safe_system "git", "commit", "--no-edit", "--verbose", | 
					
						
							|  |  |  |               "--message=#{f.name}: #{update_or_add} #{f.pkg_version} bottle.", | 
					
						
							|  |  |  |               "--", f.path | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-06-18 19:31:18 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bottle | 
					
						
							| 
									
										
										
										
											2015-09-10 17:03:51 +08:00
										 |  |  |     if ARGV.include? "--merge" | 
					
						
							|  |  |  |       merge | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       ARGV.resolved_formulae.each do |f| | 
					
						
							|  |  |  |         bottle_formula f | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-03-07 17:29:05 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |