60 lines
1.7 KiB
Ruby
Raw Normal View History

2020-11-25 17:03:23 +01:00
# typed: true
# frozen_string_literal: true
require "cache_store"
require "linkage_checker"
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
2016-09-26 01:44:51 +02:00
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def linkage_args
Homebrew::CLI::Parser.new do
2018-09-28 21:39:52 +05:30
usage_banner <<~EOS
`linkage` [<options>] [<formula>]
2018-09-28 21:39:52 +05:30
Check the library links from the given <formula> kegs. If no <formula> are
provided, check all kegs. Raises an error if run on uninstalled formulae.
2018-09-28 21:39:52 +05:30
EOS
switch "--test",
description: "Show only missing libraries and exit with a non-zero status if any missing "\
2019-04-30 08:44:35 +01:00
"libraries are found."
2018-09-28 21:39:52 +05:30
switch "--reverse",
2019-04-30 08:44:35 +01:00
description: "For every library that a keg references, print its dylib path followed by the "\
"binaries that link to it."
2018-09-28 21:39:52 +05:30
switch "--cached",
2019-04-30 08:44:35 +01:00
description: "Print the cached linkage values stored in `HOMEBREW_CACHE`, set by a previous "\
"`brew linkage` run."
2018-06-02 20:45:50 +05:30
end
end
def linkage
2020-07-30 18:40:10 +02:00
args = linkage_args.parse
2018-06-02 20:45:50 +05:30
2018-05-22 14:46:14 +01:00
CacheStoreDatabase.use(:linkage) do |db|
kegs = if args.named.to_kegs.empty?
Formula.installed.map(&:any_installed_keg).reject(&:nil?)
else
args.named.to_kegs
end
kegs.each do |keg|
ohai "Checking #{keg.name} linkage" if kegs.size > 1
result = LinkageChecker.new(keg, cache_db: db)
2018-06-02 20:45:50 +05:30
if args.test?
result.display_test_output
Homebrew.failed = true if result.broken_library_linkage?
2018-06-02 20:45:50 +05:30
elsif args.reverse?
result.display_reverse_output
else
result.display_normal_output
end
end
end
end
end