2020-11-25 17:03:23 +01:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-28 10:39:15 -05:00
|
|
|
require "cache_store"
|
2018-02-28 09:13:17 -08:00
|
|
|
require "linkage_checker"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2016-04-17 21:25:11 -04:00
|
|
|
|
|
|
|
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) }
|
2018-07-30 18:25:38 +05:30
|
|
|
def linkage_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2021-01-15 15:04:02 -05:00
|
|
|
description <<~EOS
|
2019-08-19 22:44:50 -04:00
|
|
|
Check the library links from the given <formula> kegs. If no <formula> are
|
2019-08-20 00:04:14 -04:00
|
|
|
provided, check all kegs. Raises an error if run on uninstalled formulae.
|
2018-09-28 21:39:52 +05:30
|
|
|
EOS
|
|
|
|
switch "--test",
|
2022-06-28 10:09:59 +01:00
|
|
|
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."
|
2021-11-19 17:42:17 +08:00
|
|
|
switch "--strict",
|
|
|
|
depends_on: "--test",
|
|
|
|
description: "Exit with a non-zero status if any undeclared dependencies with linkage are found."
|
2018-09-28 21:39:52 +05:30
|
|
|
switch "--reverse",
|
2022-06-28 10:09:59 +01:00
|
|
|
description: "For every library that a keg references, print its dylib path followed by the " \
|
2019-04-30 08:44:35 +01:00
|
|
|
"binaries that link to it."
|
2018-09-28 21:39:52 +05:30
|
|
|
switch "--cached",
|
2022-06-28 10:09:59 +01:00
|
|
|
description: "Print the cached linkage values stored in `HOMEBREW_CACHE`, set by a previous " \
|
2019-04-30 08:44:35 +01:00
|
|
|
"`brew linkage` run."
|
2021-01-10 14:26:40 -05:00
|
|
|
|
|
|
|
named_args :installed_formula
|
2018-06-02 20:45:50 +05:30
|
|
|
end
|
2018-07-30 18:25:38 +05:30
|
|
|
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|
|
2021-05-19 12:59:53 -04:00
|
|
|
kegs = if args.named.to_default_kegs.empty?
|
2021-12-23 14:49:05 -05:00
|
|
|
Formula.installed.map(&:any_installed_keg).compact
|
2018-08-03 11:15:58 -07:00
|
|
|
else
|
2021-05-19 12:59:53 -04:00
|
|
|
args.named.to_default_kegs
|
2018-08-03 11:15:58 -07:00
|
|
|
end
|
|
|
|
kegs.each do |keg|
|
|
|
|
ohai "Checking #{keg.name} linkage" if kegs.size > 1
|
2018-01-16 17:37:59 -05:00
|
|
|
|
2018-06-29 19:57:39 +01:00
|
|
|
result = LinkageChecker.new(keg, cache_db: db)
|
2018-01-16 17:37:59 -05:00
|
|
|
|
2018-06-02 20:45:50 +05:30
|
|
|
if args.test?
|
2021-11-19 17:42:17 +08:00
|
|
|
result.display_test_output(strict: args.strict?)
|
|
|
|
Homebrew.failed = true if result.broken_library_linkage?(strict: args.strict?)
|
2018-06-02 20:45:50 +05:30
|
|
|
elsif args.reverse?
|
2018-02-24 17:32:29 -05:00
|
|
|
result.display_reverse_output
|
|
|
|
else
|
|
|
|
result.display_normal_output
|
|
|
|
end
|
|
|
|
end
|
2016-04-17 21:25:11 -04:00
|
|
|
end
|
|
|
|
end
|
2016-04-19 13:55:47 +08:00
|
|
|
end
|