| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def deps | 
					
						
							| 
									
										
										
										
											2013-06-22 12:54:46 -05:00
										 |  |  |     mode = OpenStruct.new( | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |       installed?: ARGV.include?("--installed"), | 
					
						
							|  |  |  |       tree?: ARGV.include?("--tree"), | 
					
						
							|  |  |  |       all?: ARGV.include?("--all"), | 
					
						
							|  |  |  |       topo_order?: ARGV.include?("-n"), | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:54 +00:00
										 |  |  |       union?: ARGV.include?("--union"), | 
					
						
							| 
									
										
										
										
											2017-08-03 00:41:51 -04:00
										 |  |  |       for_each?: ARGV.include?("--for-each"), | 
					
						
							| 
									
										
										
										
											2013-06-22 12:54:46 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 00:41:51 -04:00
										 |  |  |     if mode.tree? | 
					
						
							|  |  |  |       if mode.installed? | 
					
						
							| 
									
										
										
										
											2017-10-14 06:42:53 +01:00
										 |  |  |         puts_deps_tree Formula.installed.sort, !ARGV.one? | 
					
						
							| 
									
										
										
										
											2017-08-03 00:41:51 -04:00
										 |  |  |       else | 
					
						
							|  |  |  |         raise FormulaUnspecifiedError if ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 00:41:51 -04:00
										 |  |  |         puts_deps_tree ARGV.formulae, !ARGV.one? | 
					
						
							|  |  |  |       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 | 
					
						
							|  |  |  |     elsif !ARGV.named.empty? && mode.for_each? | 
					
						
							|  |  |  |       puts_deps ARGV.formulae | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @only_installed_arg = ARGV.include?("--installed") && | 
					
						
							|  |  |  |                           !ARGV.include?("--include-build") && | 
					
						
							|  |  |  |                           !ARGV.include?("--include-test") && | 
					
						
							|  |  |  |                           !ARGV.include?("--include-optional") && | 
					
						
							|  |  |  |                           !ARGV.include?("--skip-recommended") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ARGV.named.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
										 |  |  | 
 | 
					
						
							|  |  |  |     all_deps = deps_for_formulae(ARGV.formulae, !ARGV.one?, &(mode.union? ? :| : :&)) | 
					
						
							|  |  |  |     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) | 
					
						
							| 
									
										
										
										
											2018-03-26 10:55:29 +01:00
										 |  |  |     return deps if ARGV.include?("--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 | 
					
						
							|  |  |  |       if ARGV.include?("--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 | 
					
						
							| 
									
										
										
										
											2018-03-26 10:55:29 +01:00
										 |  |  |     elsif ARGV.include?("--full-name") | 
					
						
							|  |  |  |       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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 00:41:51 -04:00
										 |  |  |     if ARGV.include?("--annotate") | 
					
						
							|  |  |  |       str = "#{str}  [build]" if dep.build? | 
					
						
							| 
									
										
										
										
											2018-03-05 10:36:39 +00:00
										 |  |  |       str = "#{str}  [test]" if dep.test? | 
					
						
							| 
									
										
										
										
											2017-08-03 00:41:51 -04:00
										 |  |  |       str = "#{str}  [optional" if dep.optional? | 
					
						
							|  |  |  |       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 | 
					
						
							| 
									
										
										
										
											2018-03-26 10:55:29 +01:00
										 |  |  |     dependables.reject!(&:optional?) unless ARGV.include?("--include-optional") | 
					
						
							|  |  |  |     dependables.reject!(&:build?) unless ARGV.include?("--include-build") | 
					
						
							|  |  |  |     dependables.reject!(&:test?) unless ARGV.include?("--include-test") | 
					
						
							|  |  |  |     dependables.reject!(&:recommended?) if ARGV.include?("--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| | 
					
						
							| 
									
										
										
										
											2018-01-14 13:27:43 +00:00
										 |  |  |       next if !ARGV.include?("--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 |