Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkage: add --strict flag to detect opportunistic linkage #12454

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Library/Homebrew/cli/args.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module Homebrew
module CLI
class Args < OpenStruct
sig { returns(T::Boolean) }
def strict?; end

sig { returns(T::Boolean) }
def HEAD?; end

Expand Down
7 changes: 5 additions & 2 deletions Library/Homebrew/dev-cmd/linkage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def linkage_args
switch "--test",
description: "Show only missing libraries and exit with a non-zero status if any missing "\
"libraries are found."
switch "--strict",
depends_on: "--test",
description: "Exit with a non-zero status if any undeclared dependencies with linkage are found."
switch "--reverse",
description: "For every library that a keg references, print its dylib path followed by the "\
"binaries that link to it."
Expand All @@ -46,8 +49,8 @@ def linkage
result = LinkageChecker.new(keg, cache_db: db)

if args.test?
result.display_test_output
Homebrew.failed = true if result.broken_library_linkage?
result.display_test_output(strict: args.strict?)
Homebrew.failed = true if result.broken_library_linkage?(strict: args.strict?)
elsif args.reverse?
result.display_reverse_output
else
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ def display_reverse_output
end
end

def display_test_output(puts_output: true)
def display_test_output(puts_output: true, strict: false)
display_items "Missing libraries", broken_dylibs_with_expectations, puts_output: puts_output
display_items "Unused missing linkage information", unexpected_present_dylibs, puts_output: puts_output
display_items "Broken dependencies", @broken_deps, puts_output: puts_output
display_items "Unwanted system libraries", @unwanted_system_dylibs, puts_output: puts_output
display_items "Conflicting libraries", @version_conflict_deps, puts_output: puts_output
display_items "Undeclared dependencies with linkage", @undeclared_deps, puts_output: puts_output if strict
end

sig { returns(T::Boolean) }
def broken_library_linkage?
sig { params(strict: T::Boolean).returns(T::Boolean) }
def broken_library_linkage?(strict: false)
issues = [@broken_deps, @unwanted_system_dylibs, @version_conflict_deps]
issues << @undeclared_deps if strict
[issues, unexpected_broken_dylibs, unexpected_present_dylibs].flatten.any?(&:present?)
end

Expand Down