Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions Library/Homebrew/extend/os/mac/formula_cellar_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def check_shadowed_headers
<<~EOS
Header files that shadow system header files were installed to "#{formula.include}"
The offending files are:
#{files * "\n "}
#{files * "\n "}
EOS
end

Expand All @@ -41,7 +41,7 @@ def check_openssl_links
These object files were linked against the deprecated system OpenSSL or
the system's private LibreSSL.
Adding `depends_on "openssl"` to the formula may help.
#{system_openssl * "\n "}
#{system_openssl * "\n "}
EOS
end

Expand All @@ -58,7 +58,7 @@ def check_python_framework_links(lib)
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 "}
#{framework_links * "\n "}
EOS
end

Expand Down Expand Up @@ -88,12 +88,38 @@ def check_linkage
end
end

def check_flat_namespace(formula)
return unless formula.prefix.directory?
return if formula.tap.present? && tap_audit_exception(:flat_namespace_allowlist, formula.name)

keg = Keg.new(formula.prefix)
flat_namespace_files = keg.mach_o_files.reject do |file|
next true unless file.dylib?

macho = MachO.open(file)
if MachO::Utils.fat_magic?(macho.magic)
macho.machos.map(&:header).all? { |h| h.flag? :MH_TWOLEVEL }
else
macho.header.flag? :MH_TWOLEVEL
end
end
return if flat_namespace_files.empty?

<<~EOS
Libraries were compiled with a flat namespace.
This can cause linker errors due to name collisions, and
is often due to a bug in detecting the macOS version.
#{flat_namespace_files * "\n "}
EOS
end

def audit_installed
generic_audit_installed
problem_if_output(check_shadowed_headers)
problem_if_output(check_openssl_links)
problem_if_output(check_python_framework_links(formula.lib))
check_linkage
problem_if_output(check_flat_namespace(formula))
end

def valid_library_extension?(filename)
Expand Down