2017-08-03 00:41:51 -04:00
|
|
|
#: * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] [`--include-requirements`] <formulae>:
|
2016-04-08 16:28:43 +02:00
|
|
|
#: Show dependencies for <formulae>. When given multiple formula arguments,
|
2016-05-01 17:09:42 +02:00
|
|
|
#: show the intersection of dependencies for <formulae>.
|
2016-04-08 16:28:43 +02:00
|
|
|
#:
|
|
|
|
#: If `--1` is passed, only show dependencies one level down, instead of
|
|
|
|
#: recursing.
|
|
|
|
#:
|
|
|
|
#: If `-n` is passed, show dependencies in topological order.
|
|
|
|
#:
|
|
|
|
#: If `--union` is passed, show the union of dependencies for <formulae>,
|
|
|
|
#: instead of the intersection.
|
|
|
|
#:
|
2016-08-25 22:30:43 -07:00
|
|
|
#: If `--full-name` is passed, list dependencies by their full name.
|
|
|
|
#:
|
2016-05-01 17:09:42 +02:00
|
|
|
#: If `--installed` is passed, only list those dependencies that are
|
|
|
|
#: currently installed.
|
2016-04-08 16:28:43 +02:00
|
|
|
#:
|
2016-04-16 00:20:04 +08:00
|
|
|
#: By default, `deps` shows required and recommended dependencies for
|
|
|
|
#: <formulae>. To include the `:build` type dependencies, pass `--include-build`.
|
2018-03-05 10:36:39 +00:00
|
|
|
#: Similarly, pass `--include-optional` to include `:optional` dependencies or
|
2018-03-14 15:41:18 +00:00
|
|
|
#: `--include-test` to include (non-recursive) `:test` dependencies.
|
2016-04-16 00:20:04 +08:00
|
|
|
#: To skip `:recommended` type dependencies, pass `--skip-recommended`.
|
2017-08-03 00:41:51 -04:00
|
|
|
#: To include requirements in addition to dependencies, pass `--include-requirements`.
|
2016-05-01 17:09:42 +02:00
|
|
|
#:
|
2017-08-03 00:41:51 -04:00
|
|
|
#: * `deps` `--tree` [`--1`] [<filters>] [`--annotate`] (<formulae>|`--installed`):
|
2016-05-01 17:09:42 +02:00
|
|
|
#: Show dependencies as a tree. When given multiple formula arguments, output
|
|
|
|
#: individual trees for every formula.
|
|
|
|
#:
|
2017-08-03 00:41:51 -04:00
|
|
|
#: If `--1` is passed, only one level of children is displayed.
|
|
|
|
#:
|
2016-05-01 17:09:42 +02:00
|
|
|
#: If `--installed` is passed, output a tree for every installed formula.
|
|
|
|
#:
|
|
|
|
#: The <filters> placeholder is any combination of options `--include-build`,
|
2018-03-05 10:36:39 +00:00
|
|
|
#: `--include-optional`, `--include-test`, `--skip-recommended`, and
|
|
|
|
#: `--include-requirements` as documented above.
|
2017-08-03 00:41:51 -04:00
|
|
|
#:
|
|
|
|
#: If `--annotate` is passed, the build, optional, and recommended dependencies
|
|
|
|
#: are marked as such in the output.
|
2016-05-01 17:09:42 +02:00
|
|
|
#:
|
|
|
|
#: * `deps` [<filters>] (`--installed`|`--all`):
|
|
|
|
#: Show dependencies for installed or all available formulae. Every line of
|
|
|
|
#: output starts with the formula name, followed by a colon and all direct
|
|
|
|
#: dependencies of that formula.
|
|
|
|
#:
|
|
|
|
#: The <filters> placeholder is any combination of options `--include-build`,
|
2018-03-05 10:36:39 +00:00
|
|
|
#: `--include-optional`, `--include-test`, and `--skip-recommended` as
|
|
|
|
#: documented above.
|
2016-04-08 16:28:43 +02:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
# The undocumented `--for-each` option will switch into the mode used by `deps --all`,
|
|
|
|
# but only list dependencies for specified formula, one specified formula per line.
|
|
|
|
# This is used for debugging the `--installed`/`--all` display mode.
|
|
|
|
|
2015-05-23 16:07:10 +02:00
|
|
|
# encoding: UTF-8
|
2017-05-29 18:24:52 +01:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "formula"
|
|
|
|
require "ostruct"
|
2019-01-23 08:34:24 +05:30
|
|
|
require "cli_parser"
|
2010-09-25 12:49:09 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2019-01-23 08:34:24 +05:30
|
|
|
def deps_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
|
|
|
`deps` [<options>] <formulae>
|
|
|
|
|
|
|
|
Show dependencies for <formulae>. When given multiple formula arguments,
|
|
|
|
show the intersection of dependencies for <formulae>.
|
|
|
|
EOS
|
|
|
|
switch "--1",
|
|
|
|
description: "Only show dependencies one level down, instead of recursing."
|
|
|
|
switch "-n",
|
|
|
|
description: "Show dependencies in topological order."
|
|
|
|
switch "--union",
|
|
|
|
description: "Show the union of dependencies for <formulae>, instead of the intersection."
|
|
|
|
switch "--full-name",
|
|
|
|
description: "List dependencies by their full name."
|
|
|
|
switch "--installed",
|
|
|
|
description: "Only list those dependencies that are currently installed."
|
|
|
|
switch "--all",
|
|
|
|
description: "List all the dependencies for all available formuale."
|
|
|
|
switch "--include-build",
|
|
|
|
description: "Show `:build` type dependencies for <formulae>."
|
|
|
|
switch "--include-optional",
|
|
|
|
description: "Show `:optional` dependecies for <formulae>."
|
|
|
|
switch "--include-test",
|
|
|
|
description: "Show `:test` dependencies for <formulae> (non-recursive)."
|
|
|
|
switch "--skip-recommended",
|
|
|
|
description: "Skip `:recommended` type dependencies for <formulae>."
|
|
|
|
switch "--include-requirements",
|
|
|
|
description: "Include requirements in addition to dependencies for <formulae>."
|
|
|
|
switch "--tree",
|
|
|
|
description: "Show dependencies as a tree. When given multiple formula arguments "\
|
|
|
|
"output individual trees for every formula."
|
|
|
|
switch "--for-each",
|
|
|
|
description: "Switch into the mode used by `deps --all`, but only list dependencies "\
|
|
|
|
"for specified formula one specified formula per line. This is used for "\
|
|
|
|
"debugging the `--installed`/`--all` display mode."
|
|
|
|
switch :verbose
|
|
|
|
switch :debug
|
2019-01-29 19:39:41 +00:00
|
|
|
conflicts "--installed", "--all"
|
2019-01-23 08:34:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def deps
|
2019-01-23 08:34:24 +05:30
|
|
|
deps_args.parse
|
2013-06-22 12:54:46 -05:00
|
|
|
mode = OpenStruct.new(
|
2019-01-23 08:34:24 +05:30
|
|
|
installed?: args.installed?,
|
|
|
|
tree?: args.tree?,
|
|
|
|
all?: args.all?,
|
|
|
|
topo_order?: args.n?,
|
|
|
|
union?: args.union?,
|
|
|
|
for_each?: args.for_each?,
|
2013-06-22 12:54:46 -05:00
|
|
|
)
|
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
if mode.tree?
|
|
|
|
if mode.installed?
|
2019-01-23 08:34:24 +05:30
|
|
|
puts_deps_tree Formula.installed.sort, !args.send("1?")
|
2017-08-03 00:41:51 -04:00
|
|
|
else
|
2019-01-23 08:34:24 +05:30
|
|
|
raise FormulaUnspecifiedError if args.remaining.empty?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2019-01-23 08:34:24 +05:30
|
|
|
puts_deps_tree ARGV.formulae, !args.send("1?")
|
2017-08-03 00:41:51 -04:00
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
return
|
2013-06-22 12:54:46 -05:00
|
|
|
elsif mode.all?
|
2017-10-14 06:42:53 +01:00
|
|
|
puts_deps Formula.sort
|
2018-03-26 10:55:29 +01:00
|
|
|
return
|
2019-01-23 08:34:24 +05:30
|
|
|
elsif !args.remaining.empty? && mode.for_each?
|
2018-03-26 10:55:29 +01:00
|
|
|
puts_deps ARGV.formulae
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-01-23 08:34:24 +05:30
|
|
|
@only_installed_arg = args.installed? &&
|
|
|
|
!args.include_build? &&
|
|
|
|
!args.include_test? &&
|
|
|
|
!args.include_optional? &&
|
|
|
|
!args.skip_recommended?
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2019-01-23 08:34:24 +05:30
|
|
|
if args.remaining.empty?
|
2015-05-31 12:56:00 +02:00
|
|
|
raise FormulaUnspecifiedError unless mode.installed?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2017-10-14 06:42:53 +01:00
|
|
|
puts_deps Formula.installed.sort
|
2018-03-26 10:55:29 +01:00
|
|
|
return
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2019-01-23 08:34:24 +05:30
|
|
|
all_deps = deps_for_formulae(ARGV.formulae, !args.send("1?"), &(mode.union? ? :| : :&))
|
2018-03-26 10:55:29 +01:00
|
|
|
all_deps = condense_requirements(all_deps)
|
|
|
|
all_deps.select!(&:installed?) if mode.installed?
|
|
|
|
all_deps.map!(&method(:dep_display_name))
|
|
|
|
all_deps.uniq!
|
|
|
|
all_deps.sort! unless mode.topo_order?
|
|
|
|
puts all_deps
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
2013-06-09 12:59:42 -05:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
def condense_requirements(deps)
|
2019-01-23 08:34:24 +05:30
|
|
|
return deps if args.include_requirements?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2018-03-26 10:55:29 +01:00
|
|
|
deps.select { |dep| dep.is_a? Dependency }
|
2017-08-03 00:41:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def dep_display_name(dep)
|
|
|
|
str = if dep.is_a? Requirement
|
2019-01-23 08:34:24 +05:30
|
|
|
if args.include_requirements?
|
2018-01-14 13:27:43 +00:00
|
|
|
":#{dep.display_s}"
|
2017-08-03 00:41:51 -04:00
|
|
|
else
|
|
|
|
# This shouldn't happen, but we'll put something here to help debugging
|
|
|
|
"::#{dep.name}"
|
|
|
|
end
|
2019-01-23 08:34:24 +05:30
|
|
|
elsif args.full_name?
|
2018-03-26 10:55:29 +01:00
|
|
|
dep.to_formula.full_name
|
2017-08-03 00:41:51 -04:00
|
|
|
else
|
2018-03-26 10:55:29 +01:00
|
|
|
dep.name
|
2017-08-03 00:41:51 -04:00
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2019-01-23 08:34:24 +05:30
|
|
|
if args.annotate?
|
2017-08-03 00:41:51 -04:00
|
|
|
str = "#{str} [build]" if dep.build?
|
2018-03-05 10:36:39 +00:00
|
|
|
str = "#{str} [test]" if dep.test?
|
2018-11-12 17:56:06 -05:00
|
|
|
str = "#{str} [optional]" if dep.optional?
|
2017-08-03 00:41:51 -04:00
|
|
|
str = "#{str} [recommended]" if dep.recommended?
|
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
str
|
2016-12-20 03:39:30 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def deps_for_formula(f, recursive = false)
|
2018-03-24 16:55:16 +00:00
|
|
|
includes, ignores = argv_includes_ignores(ARGV)
|
2015-03-20 21:31:33 +00:00
|
|
|
|
2018-03-26 10:55:29 +01:00
|
|
|
deps = f.runtime_dependencies if @only_installed_arg
|
|
|
|
|
2013-10-29 17:27:21 -04:00
|
|
|
if recursive
|
2018-03-26 10:55:29 +01:00
|
|
|
deps ||= recursive_includes(Dependency, f, includes, ignores)
|
|
|
|
reqs = recursive_includes(Requirement, f, includes, ignores)
|
2013-10-29 17:27:21 -04:00
|
|
|
else
|
2018-03-26 10:55:29 +01:00
|
|
|
deps ||= reject_ignores(f.deps, ignores, includes)
|
|
|
|
reqs = reject_ignores(f.requirements, ignores, includes)
|
2013-10-29 17:27:21 -04:00
|
|
|
end
|
2014-02-27 12:56:42 -06:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
deps + reqs.to_a
|
2013-10-29 17:27:21 -04:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def deps_for_formulae(formulae, recursive = false, &block)
|
2018-09-02 20:14:54 +01:00
|
|
|
formulae.map { |f| deps_for_formula(f, recursive) }.reduce(&block)
|
2013-06-22 12:54:45 -05:00
|
|
|
end
|
|
|
|
|
2013-06-22 12:54:45 -05:00
|
|
|
def puts_deps(formulae)
|
2016-12-20 03:39:30 -05:00
|
|
|
formulae.each do |f|
|
2017-08-03 00:41:51 -04:00
|
|
|
deps = deps_for_formula(f)
|
|
|
|
deps = condense_requirements(deps)
|
2018-03-26 10:55:29 +01:00
|
|
|
deps.sort_by!(&:name)
|
|
|
|
deps.map!(&method(:dep_display_name))
|
2016-12-20 03:39:30 -05:00
|
|
|
puts "#{f.full_name}: #{deps.join(" ")}"
|
|
|
|
end
|
2013-06-22 12:54:45 -05:00
|
|
|
end
|
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
def puts_deps_tree(formulae, recursive = false)
|
2013-06-22 12:54:45 -05:00
|
|
|
formulae.each do |f|
|
2017-08-03 00:41:51 -04:00
|
|
|
puts f.full_name
|
|
|
|
@dep_stack = []
|
|
|
|
recursive_deps_tree(f, "", recursive)
|
2013-06-22 12:54:45 -05:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
def recursive_deps_tree(f, prefix, recursive)
|
|
|
|
reqs = f.requirements
|
|
|
|
deps = f.deps
|
|
|
|
dependables = reqs + deps
|
2019-01-23 08:34:24 +05:30
|
|
|
dependables.reject!(&:optional?) unless args.include_optional?
|
|
|
|
dependables.reject!(&:build?) unless args.include_build?
|
|
|
|
dependables.reject!(&:test?) unless args.include_test?
|
|
|
|
dependables.reject!(&:recommended?) if args.skip_recommended?
|
2017-08-03 00:41:51 -04:00
|
|
|
max = dependables.length - 1
|
|
|
|
@dep_stack.push f.name
|
|
|
|
dependables.each_with_index do |dep, i|
|
2019-01-23 08:34:24 +05:30
|
|
|
next if !args.include_requirements? && dep.is_a?(Requirement)
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
tree_lines = if i == max
|
2016-12-20 03:59:15 -05:00
|
|
|
"└──"
|
|
|
|
else
|
|
|
|
"├──"
|
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
display_s = "#{tree_lines} #{dep_display_name(dep)}"
|
|
|
|
is_circular = @dep_stack.include?(dep.name)
|
|
|
|
display_s = "#{display_s} (CIRCULAR DEPENDENCY)" if is_circular
|
|
|
|
puts "#{prefix}#{display_s}"
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
next if !recursive || is_circular
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
prefix_addition = if i == max
|
|
|
|
" "
|
2016-12-20 03:59:15 -05:00
|
|
|
else
|
2017-08-03 00:41:51 -04:00
|
|
|
"│ "
|
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
if dep.is_a? Dependency
|
|
|
|
recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_addition, true)
|
2016-12-20 03:59:15 -05:00
|
|
|
end
|
2013-06-09 12:59:42 -05:00
|
|
|
end
|
2018-03-26 10:55:29 +01:00
|
|
|
|
2017-08-03 00:41:51 -04:00
|
|
|
@dep_stack.pop
|
2013-06-09 12:59:42 -05:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|