Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Make PackageOutputFormatter use PackageIdentifier instead of package …
Browse files Browse the repository at this point in the history
…name.

Fixes bazelbuild#3122.

RELNOTES: bazel query --output package now displays packages from external repository with the format "@reponame//package". Packages in the main repository continue to have the format "package".
PiperOrigin-RevId: 158327492
  • Loading branch information
aj-michael authored and katre committed Jun 8, 2017
1 parent ff688bf commit 7dec005
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 57 deletions.
59 changes: 3 additions & 56 deletions site/docs/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -1231,63 +1231,10 @@ <h3 id="output-package">Print the set of packages</h3>
</p>

<p>
In conjunction with the <code>deps(...)</code> query, this output
option can be used to find the set of packages that must be checked
out in order to build a given set of targets.
Packages in external repositories are formatted as
<code>@repo//foo/bar</code> while packages in the main repository are
formatted as <code>foo/bar</code>.
</p>

<h3 id="output-graph">Display a graph of the result</h3>
<pre>--output graph</pre>
<p>
This option causes the query result to be printed as a directed
graph in the popular AT&amp;T GraphViz format. Typically the
result is saved to a file, such as <code>.png</code> or <code>.svg</code>.
(If the <code>dot</code> program is not installed on your workstation, you
can install it using the command <code>sudo apt-get install graphviz</code>.)
See the example section below for a sample invocation.
</p>

<p>
This output format is particularly useful for <code>allpath</code>,
<code>deps</code>, or <code>rdeps</code> queries, where the result
includes a <em>set of paths</em> that cannot be easily visualized when
rendered in a linear form, such as with <code>--output label</code>.
</p>

<p>
By default, the graph is rendered in a <em>factored</em> form. That is,
topologically-equivalent nodes are merged together into a single
node with multiple labels. This makes the graph more compact
and readable, because typical result graphs contain highly
repetitive patterns. For example, a <code>java_library</code> rule
may depend on hundreds of Java source files all generated by the
same <code>genrule</code>; in the factored graph, all these files
are represented by a single node. This behavior may be disabled
with the <code>--nograph:factored</code> option.
</p>

<h4><code>--graph:node_limit <var>n</var></code></h4>
<p>
The option specifies the maximum length of the label string for a
graph node in the output. Longer labels will be truncated; -1
disables truncation. Due to the factored form in which graphs are
usually printed, the node labels may be very long. GraphViz cannot
handle labels exceeding 1024 characters, which is the default value
of this option. This option has no effect unless
<code>--output=graph</code> is being used.
</p>

<h4><code>--[no]graph:factored</code></h4>
<p>
By default, graphs are displayed in factored form, as explained
<a href='#output-graph'>above</a>.
When <code>--nograph:factored</code> is specified, graphs are
printed without factoring. This makes visualization using GraphViz
impractical, but the simpler format may ease processing by other
tools (e.g. grep). This option has no effect
unless <code>--output=graph</code> is being used.
</p>

<h3 id="output-xml">XML</h3>
<pre>--output xml</pre>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public OutputFormatterCallback<Target> createPostFactoStreamCallback(
public void processOutput(Iterable<Target> partialResult) {

for (Target target : partialResult) {
packageNames.add(target.getLabel().getPackageName());
packageNames.add(target.getPackage().getPackageIdentifier().toString());
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/shell/bazel/local_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ EOF
expect_log "//external:my_repo"
}

function test_repository_package_query() {
mkdir a b b/b
echo "local_repository(name='b', path='b')" > WORKSPACE
echo "sh_library(name='a', deps=['@b//b'])" > a/BUILD
touch b/WORKSPACE
echo "sh_library(name='b')" > b/b/BUILD
bazel query --output package "deps(//a)" >& $TEST_log || fail "query failed"
expect_log "a"
expect_log "@b//b"
}

function test_warning() {
local bar=$TEST_TMPDIR/bar
rm -rf "$bar"
Expand Down

0 comments on commit 7dec005

Please sign in to comment.