2018-02-28 10:39:15 -05:00
|
|
|
require "cache_store"
|
2018-02-28 09:13:17 -08:00
|
|
|
require "linkage_checker"
|
2016-07-14 13:14:03 +08:00
|
|
|
|
2016-07-09 13:51:53 +01:00
|
|
|
module FormulaCellarChecks
|
|
|
|
def check_shadowed_headers
|
|
|
|
return if ["libtool", "subversion", "berkeley-db"].any? do |formula_name|
|
|
|
|
formula.name.start_with?(formula_name)
|
|
|
|
end
|
|
|
|
|
2017-08-01 21:11:41 +02:00
|
|
|
return if formula.name =~ /^php(@?\d+\.?\d*?)?$/
|
2017-01-06 12:02:10 +01:00
|
|
|
|
2016-07-09 13:51:53 +01:00
|
|
|
return if MacOS.version < :mavericks && formula.name.start_with?("postgresql")
|
|
|
|
return if MacOS.version < :yosemite && formula.name.start_with?("memcached")
|
|
|
|
|
|
|
|
return if formula.keg_only? || !formula.include.directory?
|
|
|
|
|
|
|
|
files = relative_glob(formula.include, "**/*.h")
|
|
|
|
files &= relative_glob("#{MacOS.sdk_path}/usr/include", "**/*.h")
|
|
|
|
files.map! { |p| File.join(formula.include, p) }
|
|
|
|
|
|
|
|
return if files.empty?
|
|
|
|
|
2017-10-15 02:28:32 +02:00
|
|
|
<<~EOS
|
2016-07-09 13:51:53 +01:00
|
|
|
Header files that shadow system header files were installed to "#{formula.include}"
|
|
|
|
The offending files are:
|
|
|
|
#{files * "\n "}
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_openssl_links
|
|
|
|
return unless formula.prefix.directory?
|
|
|
|
keg = Keg.new(formula.prefix)
|
|
|
|
system_openssl = keg.mach_o_files.select do |obj|
|
|
|
|
dlls = obj.dynamically_linked_libraries
|
2016-09-04 16:28:51 -07:00
|
|
|
dlls.any? { |dll| %r{/usr/lib/lib(crypto|ssl|tls)\..*dylib}.match dll }
|
2016-07-09 13:51:53 +01:00
|
|
|
end
|
|
|
|
return if system_openssl.empty?
|
|
|
|
|
2017-10-15 02:28:32 +02:00
|
|
|
<<~EOS
|
2016-07-09 13:51:53 +01:00
|
|
|
object files were linked against system openssl
|
2016-09-04 16:28:51 -07:00
|
|
|
These object files were linked against the deprecated system OpenSSL or
|
|
|
|
the system's private LibreSSL.
|
2016-07-09 13:51:53 +01:00
|
|
|
Adding `depends_on "openssl"` to the formula may help.
|
|
|
|
#{system_openssl * "\n "}
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_python_framework_links(lib)
|
|
|
|
python_modules = Pathname.glob lib/"python*/site-packages/**/*.so"
|
|
|
|
framework_links = python_modules.select do |obj|
|
|
|
|
dlls = obj.dynamically_linked_libraries
|
|
|
|
dlls.any? { |dll| /Python\.framework/.match dll }
|
|
|
|
end
|
|
|
|
return if framework_links.empty?
|
|
|
|
|
2017-10-15 02:28:32 +02:00
|
|
|
<<~EOS
|
2016-07-09 13:51:53 +01:00
|
|
|
python modules have explicit framework links
|
|
|
|
These python extension modules were linked directly to a Python
|
|
|
|
framework binary. They should be linked with -undefined dynamic_lookup
|
|
|
|
instead of -lpython or -framework Python.
|
|
|
|
#{framework_links * "\n "}
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
2016-07-14 13:14:03 +08:00
|
|
|
def check_linkage
|
|
|
|
return unless formula.prefix.directory?
|
|
|
|
keg = Keg.new(formula.prefix)
|
2018-02-24 17:32:29 -05:00
|
|
|
|
2018-02-27 13:05:19 -05:00
|
|
|
DatabaseCache.new(:linkage) { |database_cache| LinkageChecker.new(keg, database_cache, true, formula) }
|
2016-07-14 13:14:03 +08:00
|
|
|
|
2016-09-23 22:02:23 +02:00
|
|
|
return unless checker.broken_dylibs?
|
2017-10-15 02:28:32 +02:00
|
|
|
output = <<~EOS
|
2017-08-07 11:21:55 +01:00
|
|
|
#{formula} has broken dynamic library links:
|
2017-08-08 11:08:03 +01:00
|
|
|
#{checker.broken_dylibs.to_a * "\n "}
|
2016-09-23 22:02:23 +02:00
|
|
|
EOS
|
2017-08-07 11:21:55 +01:00
|
|
|
tab = Tab.for_keg(keg)
|
|
|
|
if tab.poured_from_bottle
|
2017-10-15 02:28:32 +02:00
|
|
|
output += <<~EOS
|
2017-08-07 11:21:55 +01:00
|
|
|
Rebuild this from source with:
|
2017-08-07 11:48:45 +01:00
|
|
|
brew reinstall --build-from-source #{formula}
|
2017-08-07 11:21:55 +01:00
|
|
|
If that's successful, file an issue#{formula.tap ? " here:\n #{formula.tap.issues_url}" : "."}
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
problem_if_output output
|
2016-07-14 13:14:03 +08:00
|
|
|
end
|
|
|
|
|
2016-07-09 13:51:53 +01:00
|
|
|
def audit_installed
|
|
|
|
generic_audit_installed
|
2017-04-18 08:17:24 +01:00
|
|
|
problem_if_output(check_shadowed_headers)
|
|
|
|
problem_if_output(check_openssl_links)
|
|
|
|
problem_if_output(check_python_framework_links(formula.lib))
|
2016-07-14 13:14:03 +08:00
|
|
|
check_linkage
|
2016-07-09 13:51:53 +01:00
|
|
|
end
|
|
|
|
end
|