| 
									
										
										
										
											2014-06-26 19:06:31 -05:00
										 |  |  | class Keg | 
					
						
							| 
									
										
										
										
											2013-12-04 22:37:57 -06:00
										 |  |  |   PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@".freeze | 
					
						
							|  |  |  |   CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@".freeze | 
					
						
							| 
									
										
										
										
											2016-09-18 16:31:58 +01:00
										 |  |  |   REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@".freeze | 
					
						
							| 
									
										
										
										
											2013-12-04 22:37:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-09 13:52:05 +01:00
										 |  |  |   def fix_dynamic_linkage | 
					
						
							| 
									
										
										
										
											2015-09-11 16:32:14 +08:00
										 |  |  |     symlink_files.each do |file| | 
					
						
							|  |  |  |       link = file.readlink | 
					
						
							|  |  |  |       # Don't fix relative symlinks | 
					
						
							|  |  |  |       next unless link.absolute? | 
					
						
							|  |  |  |       if link.to_s.start_with?(HOMEBREW_CELLAR.to_s) || link.to_s.start_with?(HOMEBREW_PREFIX.to_s) | 
					
						
							|  |  |  |         FileUtils.ln_sf(link.relative_path_from(file.parent), file) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-05-10 00:19:14 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |   alias generic_fix_dynamic_linkage fix_dynamic_linkage | 
					
						
							| 
									
										
										
										
											2010-05-10 00:19:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |   def relocate_dynamic_linkage(_old_prefix, _new_prefix, _old_cellar, _new_cellar) | 
					
						
							| 
									
										
										
										
											2016-07-09 13:52:05 +01:00
										 |  |  |     [] | 
					
						
							| 
									
										
										
										
											2015-09-11 18:55:46 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-10-31 01:08:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 16:31:58 +01:00
										 |  |  |   def relocate_text_files(old_prefix, new_prefix, old_cellar, new_cellar, | 
					
						
							|  |  |  |                           old_repository, new_repository) | 
					
						
							| 
									
										
										
										
											2015-07-23 16:29:37 +08:00
										 |  |  |     files = text_files | libtool_files | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     files.group_by { |f| f.stat.ino }.each_value do |first, *rest| | 
					
						
							| 
									
										
										
										
											2014-03-27 14:17:13 -05:00
										 |  |  |       s = first.open("rb", &:read) | 
					
						
							| 
									
										
										
										
											2014-03-27 21:42:09 -05:00
										 |  |  |       changed = s.gsub!(old_cellar, new_cellar) | 
					
						
							|  |  |  |       changed = s.gsub!(old_prefix, new_prefix) || changed | 
					
						
							| 
									
										
										
										
											2016-09-18 16:31:58 +01:00
										 |  |  |       changed = s.gsub!(old_repository, new_repository) || changed | 
					
						
							| 
									
										
										
										
											2014-03-27 21:42:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 14:40:28 +00:00
										 |  |  |       next unless changed | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-05 23:07:28 -05:00
										 |  |  |       begin | 
					
						
							| 
									
										
										
										
											2014-03-27 21:42:09 -05:00
										 |  |  |         first.atomic_write(s) | 
					
						
							| 
									
										
										
										
											2014-09-25 14:34:28 -05:00
										 |  |  |       rescue SystemCallError | 
					
						
							| 
									
										
										
										
											2014-04-05 23:07:28 -05:00
										 |  |  |         first.ensure_writable do | 
					
						
							|  |  |  |           first.open("wb") { |f| f.write(s) } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |         rest.each { |file| FileUtils.ln(first, file, force: true) } | 
					
						
							| 
									
										
										
										
											2015-11-20 14:40:28 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-10-31 01:08:57 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-03-11 18:56:26 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |   def detect_cxx_stdlibs(_options = {}) | 
					
						
							| 
									
										
										
										
											2016-07-09 13:52:05 +01:00
										 |  |  |     [] | 
					
						
							| 
									
										
										
										
											2013-10-06 01:51:31 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def each_unique_file_matching(string) | 
					
						
							| 
									
										
										
										
											2014-07-05 13:50:54 -05:00
										 |  |  |     Utils.popen_read("/usr/bin/fgrep", "-lr", string, to_s) do |io| | 
					
						
							| 
									
										
										
										
											2013-12-17 20:46:42 -06:00
										 |  |  |       hardlinks = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       until io.eof? | 
					
						
							|  |  |  |         file = Pathname.new(io.readline.chomp) | 
					
						
							|  |  |  |         next if file.symlink? | 
					
						
							|  |  |  |         yield file if hardlinks.add? file.stat.ino | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-26 19:06:31 -05:00
										 |  |  |   def lib | 
					
						
							|  |  |  |     path.join("lib") | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-09-04 10:49:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 11:56:34 -07:00
										 |  |  |   def text_files | 
					
						
							|  |  |  |     text_files = [] | 
					
						
							| 
									
										
										
										
											2016-07-29 15:53:05 -06:00
										 |  |  |     return text_files unless File.exist?("/usr/bin/file") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 03:11:27 +01:00
										 |  |  |     # file has known issues with reading files on other locales. Has | 
					
						
							|  |  |  |     # been fixed upstream for some time, but a sufficiently new enough | 
					
						
							|  |  |  |     # file with that fix is only available in macOS Sierra. | 
					
						
							|  |  |  |     # http://bugs.gw.com/view.php?id=292 | 
					
						
							|  |  |  |     with_custom_locale("C") do | 
					
						
							| 
									
										
										
										
											2016-10-12 11:37:34 -04:00
										 |  |  |       files = Set.new path.find.reject { |pn| | 
					
						
							| 
									
										
										
										
											2016-10-12 11:35:37 +01:00
										 |  |  |         next true if pn.symlink? | 
					
						
							|  |  |  |         next true if pn.directory? | 
					
						
							|  |  |  |         next true if Metafiles::EXTENSIONS.include?(pn.extname) | 
					
						
							|  |  |  |         if pn.text_executable? | 
					
						
							|  |  |  |           text_files << pn | 
					
						
							|  |  |  |           next true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         false | 
					
						
							| 
									
										
										
										
											2016-10-10 21:46:19 -04:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-10-12 11:37:34 -04:00
										 |  |  |       output, _status = Open3.capture2("/usr/bin/xargs -0 /usr/bin/file --no-dereference --print0", | 
					
						
							|  |  |  |                                        stdin_data: files.to_a.join("\0")) | 
					
						
							|  |  |  |       output.each_line do |line| | 
					
						
							|  |  |  |         path, info = line.split("\0") | 
					
						
							|  |  |  |         next unless info.to_s.include?("text") | 
					
						
							|  |  |  |         path = Pathname.new(path) | 
					
						
							|  |  |  |         next unless files.include?(path) | 
					
						
							|  |  |  |         text_files << path | 
					
						
							| 
									
										
										
										
											2015-07-20 12:06:13 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-10-31 01:08:57 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 11:56:34 -07:00
										 |  |  |     text_files | 
					
						
							| 
									
										
										
										
											2015-07-10 19:51:43 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-07-23 16:29:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def libtool_files | 
					
						
							|  |  |  |     libtool_files = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-24 22:06:14 +01:00
										 |  |  |     path.find do |pn| | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       next if pn.symlink? || pn.directory? || pn.extname != ".la" | 
					
						
							| 
									
										
										
										
											2015-07-23 16:29:37 +08:00
										 |  |  |       libtool_files << pn | 
					
						
							| 
									
										
										
										
											2016-04-24 22:06:14 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-07-23 16:29:37 +08:00
										 |  |  |     libtool_files | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-09-11 16:32:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def symlink_files | 
					
						
							|  |  |  |     symlink_files = [] | 
					
						
							|  |  |  |     path.find do |pn| | 
					
						
							|  |  |  |       symlink_files << pn if pn.symlink? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     symlink_files | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-07-09 13:52:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |   def self.file_linked_libraries(_file, _string) | 
					
						
							| 
									
										
										
										
											2016-07-09 13:52:05 +01:00
										 |  |  |     [] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-05-10 00:19:14 +01:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2016-07-09 13:52:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/keg_relocate" |