aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/deps.rb134
-rw-r--r--Library/Homebrew/cmd/pin.rb3
-rw-r--r--Library/Homebrew/cmd/postinstall.rb2
-rw-r--r--Library/Homebrew/cmd/search.rb23
-rw-r--r--Library/Homebrew/cmd/unpin.rb4
5 files changed, 121 insertions, 45 deletions
diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb
index bbf0c1b0b..de7aa4a51 100644
--- a/Library/Homebrew/cmd/deps.rb
+++ b/Library/Homebrew/cmd/deps.rb
@@ -1,4 +1,4 @@
-#: * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] <formulae>:
+#: * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] [`--include-requirements`] <formulae>:
#: Show dependencies for <formulae>. When given multiple formula arguments,
#: show the intersection of dependencies for <formulae>.
#:
@@ -19,15 +19,22 @@
#: <formulae>. To include the `:build` type dependencies, pass `--include-build`.
#: Similarly, pass `--include-optional` to include `:optional` dependencies.
#: To skip `:recommended` type dependencies, pass `--skip-recommended`.
+#: To include requirements in addition to dependencies, pass `--include-requirements`.
#:
-#: * `deps` `--tree` [<filters>] (<formulae>|`--installed`):
+#: * `deps` `--tree` [`--1`] [<filters>] [`--annotate`] (<formulae>|`--installed`):
#: Show dependencies as a tree. When given multiple formula arguments, output
#: individual trees for every formula.
#:
+#: If `--1` is passed, only one level of children is displayed.
+#:
#: If `--installed` is passed, output a tree for every installed formula.
#:
#: The <filters> placeholder is any combination of options `--include-build`,
-#: `--include-optional`, and `--skip-recommended` as documented above.
+#: `--include-optional`, `--skip-recommended`, and `--include-requirements` as
+#: documented above.
+#:
+#: If `--annotate` is passed, the build, optional, and recommended dependencies
+#: are marked as such in the output.
#:
#: * `deps` [<filters>] (`--installed`|`--all`):
#: Show dependencies for installed or all available formulae. Every line of
@@ -37,6 +44,10 @@
#: The <filters> placeholder is any combination of options `--include-build`,
#: `--include-optional`, and `--skip-recommended` as documented above.
+# 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.
+
# encoding: UTF-8
require "formula"
@@ -52,20 +63,26 @@ module Homebrew
all?: ARGV.include?("--all"),
topo_order?: ARGV.include?("-n"),
union?: ARGV.include?("--union"),
+ for_each?: ARGV.include?("--for-each"),
)
- if mode.installed? && mode.tree?
- puts_deps_tree Formula.installed
+ if mode.tree?
+ if mode.installed?
+ puts_deps_tree Formula.installed, !ARGV.one?
+ else
+ raise FormulaUnspecifiedError if ARGV.named.empty?
+ puts_deps_tree ARGV.formulae, !ARGV.one?
+ end
elsif mode.all?
puts_deps Formula
- elsif mode.tree?
- raise FormulaUnspecifiedError if ARGV.named.empty?
- puts_deps_tree ARGV.formulae
elsif ARGV.named.empty?
raise FormulaUnspecifiedError unless mode.installed?
puts_deps Formula.installed
+ elsif mode.for_each?
+ puts_deps ARGV.formulae
else
all_deps = deps_for_formulae(ARGV.formulae, !ARGV.one?, &(mode.union? ? :| : :&))
+ all_deps = condense_requirements(all_deps)
all_deps = all_deps.select(&:installed?) if mode.installed?
all_deps = all_deps.map(&method(:dep_display_name)).uniq
all_deps.sort! unless mode.topo_order?
@@ -73,24 +90,59 @@ module Homebrew
end
end
- def dep_display_name(d)
- ARGV.include?("--full-name") ? d.to_formula.full_name : d.name
+ def condense_requirements(deps)
+ if ARGV.include?("--include-requirements")
+ deps
+ else
+ deps.map do |dep|
+ if dep.is_a? Dependency
+ dep
+ elsif dep.default_formula?
+ dep.to_dependency
+ end
+ end.compact
+ end
+ end
+
+ def dep_display_name(dep)
+ str = if dep.is_a? Requirement
+ if ARGV.include?("--include-requirements")
+ if dep.default_formula?
+ ":#{dep.display_s} (#{dep_display_name(dep.to_dependency)})"
+ else
+ ":#{dep.display_s}"
+ end
+ elsif dep.default_formula?
+ dep_display_name(dep.to_dependency)
+ else
+ # This shouldn't happen, but we'll put something here to help debugging
+ "::#{dep.name}"
+ end
+ else
+ ARGV.include?("--full-name") ? dep.to_formula.full_name : dep.name
+ end
+ if ARGV.include?("--annotate")
+ str = "#{str} [build]" if dep.build?
+ str = "#{str} [optional" if dep.optional?
+ str = "#{str} [recommended]" if dep.recommended?
+ end
+ str
end
def deps_for_formula(f, recursive = false)
includes = []
ignores = []
- if ARGV.include? "--include-build"
+ if ARGV.include?("--include-build")
includes << "build?"
else
ignores << "build?"
end
- if ARGV.include? "--include-optional"
+ if ARGV.include?("--include-optional")
includes << "optional?"
else
ignores << "optional?"
end
- ignores << "recommended?" if ARGV.include? "--skip-recommended"
+ ignores << "recommended?" if ARGV.include?("--skip-recommended")
if recursive
deps = f.recursive_dependencies do |dependent, dep|
@@ -120,7 +172,7 @@ module Homebrew
end
end
- deps + reqs.select(&:default_formula?).map(&:to_dependency)
+ deps + reqs.to_a
end
def deps_for_formulae(formulae, recursive = false, &block)
@@ -129,41 +181,55 @@ module Homebrew
def puts_deps(formulae)
formulae.each do |f|
- deps = deps_for_formula(f).sort_by(&:name).map(&method(:dep_display_name))
+ deps = deps_for_formula(f)
+ deps = condense_requirements(deps)
+ deps = deps.sort_by(&:name).map(&method(:dep_display_name))
puts "#{f.full_name}: #{deps.join(" ")}"
end
end
- def puts_deps_tree(formulae)
+ def puts_deps_tree(formulae, recursive = false)
formulae.each do |f|
- puts "#{f.full_name} (required dependencies)"
- recursive_deps_tree(f, "")
+ puts f.full_name
+ @dep_stack = []
+ recursive_deps_tree(f, "", recursive)
puts
end
end
- def recursive_deps_tree(f, prefix)
- reqs = f.requirements.select(&:default_formula?)
- deps = f.deps.default
- max = reqs.length - 1
- reqs.each_with_index do |req, i|
- chr = if i == max && deps.empty?
+ def recursive_deps_tree(f, prefix, recursive)
+ reqs = f.requirements
+ deps = f.deps
+ dependables = reqs + deps
+ dependables = dependables.reject(&:optional?) unless ARGV.include?("--include-optional")
+ dependables = dependables.reject(&:build?) unless ARGV.include?("--include-build")
+ dependables = dependables.reject(&:recommended?) if ARGV.include?("--skip-recommended")
+ max = dependables.length - 1
+ @dep_stack.push f.name
+ dependables.each_with_index do |dep, i|
+ next if !ARGV.include?("--include-requirements") && dep.is_a?(Requirement) && !dep.default_formula?
+ tree_lines = if i == max
"└──"
else
"├──"
end
- puts prefix + "#{chr} :#{dep_display_name(req.to_dependency)}"
- end
- max = deps.length - 1
- deps.each_with_index do |dep, i|
- chr = if i == max
- "└──"
+ 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}"
+ next if !recursive || is_circular
+ prefix_addition = if i == max
+ " "
else
- "├──"
+ "│ "
+ end
+ if dep.is_a?(Requirement) && dep.default_formula?
+ recursive_deps_tree(Formulary.factory(dep.to_dependency.name), prefix + prefix_addition, true)
+ end
+ if dep.is_a? Dependency
+ recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_addition, true)
end
- prefix_ext = (i == max) ? " " : "│ "
- puts prefix + "#{chr} #{dep_display_name(dep)}"
- recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_ext)
end
+ @dep_stack.pop
end
end
diff --git a/Library/Homebrew/cmd/pin.rb b/Library/Homebrew/cmd/pin.rb
index c5087f6d4..5a14f853c 100644
--- a/Library/Homebrew/cmd/pin.rb
+++ b/Library/Homebrew/cmd/pin.rb
@@ -1,6 +1,7 @@
#: * `pin` <formulae>:
#: Pin the specified <formulae>, preventing them from being upgraded when
-#: issuing the `brew upgrade` command. See also `unpin`.
+#: issuing the `brew upgrade <formulae>` command (but can still be upgraded
+#: as dependencies for other formulae). See also `unpin`.
require "formula"
diff --git a/Library/Homebrew/cmd/postinstall.rb b/Library/Homebrew/cmd/postinstall.rb
index f5d091227..02fd8a5f6 100644
--- a/Library/Homebrew/cmd/postinstall.rb
+++ b/Library/Homebrew/cmd/postinstall.rb
@@ -29,8 +29,6 @@ module Homebrew
args << "--devel"
end
- Sandbox.print_sandbox_message if Sandbox.formula?(formula)
-
Utils.safe_fork do
if Sandbox.formula?(formula)
sandbox = Sandbox.new
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index b2d069744..0718a3af4 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -34,7 +34,7 @@ module Homebrew
elsif ARGV.include? "--opensuse"
exec_browser "https://software.opensuse.org/search?q=#{ARGV.next}"
elsif ARGV.include? "--fedora"
- exec_browser "https://admin.fedoraproject.org/pkgdb/packages/%2A#{ARGV.next}%2A/"
+ exec_browser "https://apps.fedoraproject.org/packages/s/#{ARGV.next}"
elsif ARGV.include? "--ubuntu"
exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all"
elsif ARGV.include? "--desc"
@@ -43,27 +43,29 @@ module Homebrew
Descriptions.search(regex, :desc).print
elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX
query = ARGV.first
- user, repo, name = query.split("/", 3)
begin
result = Formulary.factory(query).name
+ results = Array(result)
rescue FormulaUnavailableError
- result = search_tap(user, repo, name)
+ _, _, name = query.split("/", 3)
+ results = search_taps(name)
end
- results = Array(result)
puts Formatter.columns(results) unless results.empty?
else
query = ARGV.first
regex = query_regexp(query)
local_results = search_formulae(regex)
puts Formatter.columns(local_results) unless local_results.empty?
+
tap_results = search_taps(query)
puts Formatter.columns(tap_results) unless tap_results.empty?
if $stdout.tty?
count = local_results.length + tap_results.length
+ ohai "Searching blacklisted, migrated and deleted formulae..."
if reason = Homebrew::MissingFormula.reason(query, silent: true)
if count > 0
puts
@@ -101,9 +103,15 @@ module Homebrew
end
def search_taps(query)
+ return [] if ENV["HOMEBREW_NO_GITHUB_API"]
+
+ # Use stderr to avoid breaking parsed output
+ $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue)
+
valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze
- matches = GitHub.search_code("user:Homebrew", "user:caskroom", "filename:#{query}", "extension:rb")
- [*matches].map do |match|
+ matches = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb")
+
+ matches.map do |match|
dirname, filename = File.split(match["path"])
next unless valid_dirnames.include?(dirname)
tap = Tap.fetch(match["repository"]["full_name"])
@@ -113,6 +121,9 @@ module Homebrew
end
def search_formulae(regex)
+ # Use stderr to avoid breaking parsed output
+ $stderr.puts Formatter.headline("Searching local taps...", color: :blue)
+
aliases = Formula.alias_full_names
results = (Formula.full_names + aliases).grep(regex).sort
diff --git a/Library/Homebrew/cmd/unpin.rb b/Library/Homebrew/cmd/unpin.rb
index a669df1ec..e15a156ea 100644
--- a/Library/Homebrew/cmd/unpin.rb
+++ b/Library/Homebrew/cmd/unpin.rb
@@ -1,6 +1,6 @@
#: * `unpin` <formulae>:
-#: Unpin <formulae>, allowing them to be upgraded by `brew upgrade`. See also
-#: `pin`.
+#: Unpin <formulae>, allowing them to be upgraded by `brew upgrade <formulae>`.
+#: See also `pin`.
require "formula"