Skip to content
Snippets Groups Projects
Unverified Commit 0ed673ab authored by Xu Cheng's avatar Xu Cheng
Browse files

formula_cellar_checks: add check_linkage


This means linkage checks will be invoked during `brew install` and `brew audit`

Closes #470.

Signed-off-by: default avatarXu Cheng <xucheng@me.com>
parent 13730a9d
No related branches found
No related tags found
No related merge requests found
require "options"
module Dependable
RESERVED_TAGS = [:build, :optional, :recommended, :run]
RESERVED_TAGS = [:build, :optional, :recommended, :run, :linked]
def build?
tags.include? :build
......
require "os/mac/linkage_checker"
module FormulaCellarChecks
def check_shadowed_headers
return if ["libtool", "subversion", "berkeley-db"].any? do |formula_name|
......@@ -56,10 +58,33 @@ module FormulaCellarChecks
EOS
end
def check_linkage
return unless formula.prefix.directory?
keg = Keg.new(formula.prefix)
checker = LinkageChecker.new(keg, formula)
if checker.broken_dylibs?
audit_check_output <<-EOS.undent
The installation was broken.
Broken dylib links found:
#{checker.broken_dylibs.to_a * "\n "}
EOS
end
if checker.undeclared_deps?
audit_check_output <<-EOS.undent
Formulae are required to declare all linked dependencies.
Please add all linked dependencies to the formula with:
#{checker.undeclared_deps.map { |d| "depends_on \"#{d}\" => :linked"} * "\n "}
EOS
end
end
def audit_installed
generic_audit_installed
audit_check_output(check_shadowed_headers)
audit_check_output(check_openssl_links)
audit_check_output(check_python_framework_links(formula.lib))
check_linkage
end
end
......@@ -3,12 +3,13 @@ require "keg"
require "formula"
class LinkageChecker
attr_reader :keg
attr_reader :keg, :formula
attr_reader :brewed_dylibs, :system_dylibs, :broken_dylibs, :variable_dylibs
attr_reader :undeclared_deps, :reverse_links
def initialize(keg)
def initialize(keg, formula = nil)
@keg = keg
@formula = formula || resolve_formula(keg)
@brewed_dylibs = Hash.new { |h, k| h[k] = Set.new }
@system_dylibs = Set.new
@broken_dylibs = Set.new
......@@ -34,25 +35,43 @@ class LinkageChecker
rescue Errno::ENOENT
@broken_dylibs << dylib
else
@brewed_dylibs[owner.name] << dylib
tap = Tab.for_keg(owner).tap
f = if tap.nil? || tap.core_tap?
owner.name
else
"#{tap}/#{owner.name}"
end
@brewed_dylibs[f] << dylib
end
end
end
end
begin
f = Formulary.from_rack(keg.rack)
f.build = Tab.for_keg(keg)
@undeclared_deps = check_undeclared_deps if formula
end
def check_undeclared_deps
filter_out = proc do |dep|
dep.build? || (dep.optional? && !dep.option_names.any? { |n| f.build.with?(n) })
next true if dep.build?
dep.optional? && !dep.option_names.any? { |n| formula.build.with?(n) }
end
declared_deps = formula.deps.reject { |dep| filter_out.call(dep) }.map(&:name)
declared_requirement_deps = formula.requirements.reject { |req| filter_out.call(req) }.map(&:default_formula).compact
declared_dep_names = (declared_deps + declared_requirement_deps).map { |dep| dep.split("/").last }
undeclared_deps = @brewed_dylibs.keys.select do |full_name|
name = full_name.split("/").last
next false if name == formula.name
!declared_dep_names.include?(name)
end
undeclared_deps.sort do |a,b|
if a.include?("/") && !b.include?("/")
1
elsif !a.include?("/") && b.include?("/")
-1
else
a <=> b
end
end
declared_deps = f.deps.reject { |dep| filter_out.call(dep) }.map(&:name) +
f.requirements.reject { |req| filter_out.call(req) }.map(&:default_formula).compact
@undeclared_deps = @brewed_dylibs.keys - declared_deps.map { |dep| dep.split("/").last }
@undeclared_deps -= [f.name]
rescue FormulaUnavailableError
opoo "Formula unavailable: #{keg.name}"
end
end
def display_normal_output
......@@ -79,8 +98,6 @@ class LinkageChecker
def display_test_output
display_items "Missing libraries", @broken_dylibs
puts "No broken dylib links" if @broken_dylibs.empty?
display_items "Possible undeclared dependencies", @undeclared_deps
puts "No undeclared dependencies" if @undeclared_deps.empty?
end
def broken_dylibs?
......@@ -110,4 +127,12 @@ class LinkageChecker
end
end
end
def resolve_formula(keg)
f = Formulary.from_rack(keg.rack)
f.build = Tab.for_keg(keg)
f
rescue FormulaUnavailableError
opoo "Formula unavailable: #{keg.name}"
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment