| 
									
										
										
										
											2016-05-13 00:23:14 -07:00
										 |  |  | require "utils/shell" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | module FormulaCellarChecks | 
					
						
							| 
									
										
										
										
											2016-09-21 09:07:04 +02:00
										 |  |  |   def check_env_path(bin) | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |     # warn the user if stuff was installed outside of their PATH | 
					
						
							|  |  |  |     return unless bin.directory? | 
					
						
							| 
									
										
										
										
											2016-07-09 13:51:53 +01:00
										 |  |  |     return if bin.children.empty? | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-17 09:34:43 -07:00
										 |  |  |     prefix_bin = (HOMEBREW_PREFIX/bin.basename) | 
					
						
							|  |  |  |     return unless prefix_bin.directory? | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-17 09:34:43 -07:00
										 |  |  |     prefix_bin = prefix_bin.realpath | 
					
						
							|  |  |  |     return if ORIGINAL_PATHS.include? prefix_bin | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       #{prefix_bin} is not in your PATH | 
					
						
							| 
									
										
										
										
											2016-05-13 00:23:14 -07:00
										 |  |  |       You can amend this by altering your #{Utils::Shell.shell_profile} file | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_manpages | 
					
						
							|  |  |  |     # Check for man pages that aren't in share/man | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     return unless (formula.prefix+"man").directory? | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       A top-level "man" directory was found | 
					
						
							|  |  |  |       Homebrew requires that man pages live under share. | 
					
						
							|  |  |  |       This can often be fixed by passing "--mandir=\#{man}" to configure. | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_infopages | 
					
						
							|  |  |  |     # Check for info pages that aren't in share/info | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     return unless (formula.prefix+"info").directory? | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       A top-level "info" directory was found | 
					
						
							|  |  |  |       Homebrew suggests that info pages live under share. | 
					
						
							|  |  |  |       This can often be fixed by passing "--infodir=\#{info}" to configure. | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_jars | 
					
						
							| 
									
										
										
										
											2014-10-29 22:38:49 -05:00
										 |  |  |     return unless formula.lib.directory? | 
					
						
							|  |  |  |     jars = formula.lib.children.select { |g| g.extname == ".jar" } | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |     return if jars.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							| 
									
										
										
										
											2014-10-29 22:38:49 -05:00
										 |  |  |       JARs were installed to "#{formula.lib}" | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |       Installing JARs to "lib" can cause conflicts between packages. | 
					
						
							|  |  |  |       For Java software, it is typically better for the formula to | 
					
						
							|  |  |  |       install to "libexec" and then symlink or wrap binaries into "bin". | 
					
						
							|  |  |  |       See "activemq", "jruby", etc. for examples. | 
					
						
							|  |  |  |       The offending files are: | 
					
						
							|  |  |  |         #{jars * "\n        "} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_non_libraries | 
					
						
							| 
									
										
										
										
											2014-10-29 22:38:49 -05:00
										 |  |  |     return unless formula.lib.directory? | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     valid_extensions = %w[.a .dylib .framework .jnilib .la .o .so
 | 
					
						
							|  |  |  |                           .jar .prl .pm .sh] | 
					
						
							| 
									
										
										
										
											2014-10-29 22:38:49 -05:00
										 |  |  |     non_libraries = formula.lib.children.select do |g| | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |       next if g.directory? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       !valid_extensions.include? g.extname | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |     return if non_libraries.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							| 
									
										
										
										
											2014-10-29 22:38:49 -05:00
										 |  |  |       Non-libraries were installed to "#{formula.lib}" | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |       Installing non-libraries to "lib" is discouraged. | 
					
						
							|  |  |  |       The offending files are: | 
					
						
							|  |  |  |         #{non_libraries * "\n        "} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def check_non_executables(bin) | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |     return unless bin.directory? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     non_exes = bin.children.select { |g| g.directory? || !g.executable? } | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |     return if non_exes.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       Non-executables were installed to "#{bin}" | 
					
						
							|  |  |  |       The offending files are: | 
					
						
							|  |  |  |         #{non_exes * "\n        "} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-11-10 12:51:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def check_generic_executables(bin) | 
					
						
							| 
									
										
										
										
											2013-11-10 12:51:24 -08:00
										 |  |  |     return unless bin.directory? | 
					
						
							| 
									
										
										
										
											2014-05-21 09:03:51 -07:00
										 |  |  |     generic_names = %w[run service start stop] | 
					
						
							| 
									
										
										
										
											2014-05-21 10:54:24 -05:00
										 |  |  |     generics = bin.children.select { |g| generic_names.include? g.basename.to_s } | 
					
						
							| 
									
										
										
										
											2013-11-10 12:51:24 -08:00
										 |  |  |     return if generics.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       Generic binaries were installed to "#{bin}" | 
					
						
							|  |  |  |       Binaries with generic names are likely to conflict with other software, | 
					
						
							|  |  |  |       and suggest that this software should be installed to "libexec" and then | 
					
						
							|  |  |  |       symlinked as needed. | 
					
						
							| 
									
										
										
										
											2013-11-10 12:51:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |       The offending files are: | 
					
						
							|  |  |  |         #{generics * "\n        "} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2013-11-10 12:51:24 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-10-01 23:32:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def check_easy_install_pth(lib) | 
					
						
							| 
									
										
										
										
											2015-05-05 13:45:11 -07:00
										 |  |  |     pth_found = Dir["#{lib}/python{2.7,3}*/site-packages/easy-install.pth"].map { |f| File.dirname(f) } | 
					
						
							| 
									
										
										
										
											2014-10-01 18:40:04 -07:00
										 |  |  |     return if pth_found.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       easy-install.pth files were found | 
					
						
							|  |  |  |       These .pth files are likely to cause link conflicts. Please invoke | 
					
						
							| 
									
										
										
										
											2015-02-04 21:54:16 -08:00
										 |  |  |       setup.py using Language::Python.setup_install_args. | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:00 -05:00
										 |  |  |       The offending files are | 
					
						
							|  |  |  |         #{pth_found * "\n        "} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2014-10-01 18:40:04 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 21:42:43 -07:00
										 |  |  |   def check_elisp_dirname(share, name) | 
					
						
							| 
									
										
										
										
											2015-08-01 15:42:56 -07:00
										 |  |  |     return unless (share/"emacs/site-lisp").directory? | 
					
						
							| 
									
										
										
										
											2015-10-31 21:42:43 -07:00
										 |  |  |     # Emacs itself can do what it wants | 
					
						
							|  |  |  |     return if name == "emacs" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bad_dir_name = (share/"emacs/site-lisp").children.any? do |child| | 
					
						
							|  |  |  |       child.directory? && child.basename.to_s != name | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-07-05 14:15:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 21:42:43 -07:00
										 |  |  |     return unless bad_dir_name | 
					
						
							|  |  |  |     <<-EOS
 | 
					
						
							|  |  |  |       Emacs Lisp files were installed into the wrong site-lisp subdirectory. | 
					
						
							|  |  |  |       They should be installed into: | 
					
						
							|  |  |  |       #{share}/emacs/site-lisp/#{name} | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_elisp_root(share, name) | 
					
						
							|  |  |  |     return unless (share/"emacs/site-lisp").directory? | 
					
						
							| 
									
										
										
										
											2015-07-05 14:15:19 -07:00
										 |  |  |     # Emacs itself can do what it wants | 
					
						
							|  |  |  |     return if name == "emacs" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     elisps = (share/"emacs/site-lisp").children.select { |file| %w[.el .elc].include? file.extname } | 
					
						
							|  |  |  |     return if elisps.empty? | 
					
						
							|  |  |  |     <<-EOS.undent
 | 
					
						
							|  |  |  |       Emacs Lisp files were linked directly to #{HOMEBREW_PREFIX}/share/emacs/site-lisp | 
					
						
							| 
									
										
										
										
											2015-10-31 21:42:43 -07:00
										 |  |  |       This may cause conflicts with other packages. | 
					
						
							|  |  |  |       They should instead be installed into: | 
					
						
							| 
									
										
										
										
											2015-07-05 14:15:19 -07:00
										 |  |  |       #{share}/emacs/site-lisp/#{name} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       The offending files are: | 
					
						
							|  |  |  |         #{elisps * "\n        "} | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:01 -05:00
										 |  |  |   def audit_installed | 
					
						
							|  |  |  |     audit_check_output(check_manpages) | 
					
						
							|  |  |  |     audit_check_output(check_infopages) | 
					
						
							|  |  |  |     audit_check_output(check_jars) | 
					
						
							|  |  |  |     audit_check_output(check_non_libraries) | 
					
						
							| 
									
										
										
										
											2014-10-29 22:38:49 -05:00
										 |  |  |     audit_check_output(check_non_executables(formula.bin)) | 
					
						
							|  |  |  |     audit_check_output(check_generic_executables(formula.bin)) | 
					
						
							|  |  |  |     audit_check_output(check_non_executables(formula.sbin)) | 
					
						
							|  |  |  |     audit_check_output(check_generic_executables(formula.sbin)) | 
					
						
							|  |  |  |     audit_check_output(check_easy_install_pth(formula.lib)) | 
					
						
							| 
									
										
										
										
											2015-10-31 21:42:43 -07:00
										 |  |  |     audit_check_output(check_elisp_dirname(formula.share, formula.name)) | 
					
						
							|  |  |  |     audit_check_output(check_elisp_root(formula.share, formula.name)) | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:01 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |   alias generic_audit_installed audit_installed | 
					
						
							| 
									
										
										
										
											2014-10-13 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-01 23:32:53 -05:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def relative_glob(dir, pattern) | 
					
						
							| 
									
										
										
										
											2014-10-17 12:01:27 -05:00
										 |  |  |     File.directory?(dir) ? Dir.chdir(dir) { Dir[pattern] } : [] | 
					
						
							| 
									
										
										
										
											2014-10-01 23:32:53 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-07-15 19:28:10 -07:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2016-07-09 13:51:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/formula_cellar_checks" |