close
Skip to content

Commit 7dec005

Browse files
aj-michaelkatre
authored andcommitted
Make PackageOutputFormatter use PackageIdentifier instead of package 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
1 parent ff688bf commit 7dec005

3 files changed

Lines changed: 15 additions & 57 deletions

File tree

‎site/docs/query.html‎

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,63 +1231,10 @@ <h3 id="output-package">Print the set of packages</h3>
12311231
</p>
12321232

12331233
<p>
1234-
In conjunction with the <code>deps(...)</code> query, this output
1235-
option can be used to find the set of packages that must be checked
1236-
out in order to build a given set of targets.
1234+
Packages in external repositories are formatted as
1235+
<code>@repo//foo/bar</code> while packages in the main repository are
1236+
formatted as <code>foo/bar</code>.
12371237
</p>
1238-
1239-
<h3 id="output-graph">Display a graph of the result</h3>
1240-
<pre>--output graph</pre>
1241-
<p>
1242-
This option causes the query result to be printed as a directed
1243-
graph in the popular AT&amp;T GraphViz format. Typically the
1244-
result is saved to a file, such as <code>.png</code> or <code>.svg</code>.
1245-
(If the <code>dot</code> program is not installed on your workstation, you
1246-
can install it using the command <code>sudo apt-get install graphviz</code>.)
1247-
See the example section below for a sample invocation.
1248-
</p>
1249-
1250-
<p>
1251-
This output format is particularly useful for <code>allpath</code>,
1252-
<code>deps</code>, or <code>rdeps</code> queries, where the result
1253-
includes a <em>set of paths</em> that cannot be easily visualized when
1254-
rendered in a linear form, such as with <code>--output label</code>.
1255-
</p>
1256-
1257-
<p>
1258-
By default, the graph is rendered in a <em>factored</em> form. That is,
1259-
topologically-equivalent nodes are merged together into a single
1260-
node with multiple labels. This makes the graph more compact
1261-
and readable, because typical result graphs contain highly
1262-
repetitive patterns. For example, a <code>java_library</code> rule
1263-
may depend on hundreds of Java source files all generated by the
1264-
same <code>genrule</code>; in the factored graph, all these files
1265-
are represented by a single node. This behavior may be disabled
1266-
with the <code>--nograph:factored</code> option.
1267-
</p>
1268-
1269-
<h4><code>--graph:node_limit <var>n</var></code></h4>
1270-
<p>
1271-
The option specifies the maximum length of the label string for a
1272-
graph node in the output. Longer labels will be truncated; -1
1273-
disables truncation. Due to the factored form in which graphs are
1274-
usually printed, the node labels may be very long. GraphViz cannot
1275-
handle labels exceeding 1024 characters, which is the default value
1276-
of this option. This option has no effect unless
1277-
<code>--output=graph</code> is being used.
1278-
</p>
1279-
1280-
<h4><code>--[no]graph:factored</code></h4>
1281-
<p>
1282-
By default, graphs are displayed in factored form, as explained
1283-
<a href='#output-graph'>above</a>.
1284-
When <code>--nograph:factored</code> is specified, graphs are
1285-
printed without factoring. This makes visualization using GraphViz
1286-
impractical, but the simpler format may ease processing by other
1287-
tools (e.g. grep). This option has no effect
1288-
unless <code>--output=graph</code> is being used.
1289-
</p>
1290-
12911238
<h3 id="output-xml">XML</h3>
12921239
<pre>--output xml</pre>
12931240
<p>

‎src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public OutputFormatterCallback<Target> createPostFactoStreamCallback(
331331
public void processOutput(Iterable<Target> partialResult) {
332332

333333
for (Target target : partialResult) {
334-
packageNames.add(target.getLabel().getPackageName());
334+
packageNames.add(target.getPackage().getPackageIdentifier().toString());
335335
}
336336
}
337337

‎src/test/shell/bazel/local_repository_test.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,17 @@ EOF
427427
expect_log "//external:my_repo"
428428
}
429429

430+
function test_repository_package_query() {
431+
mkdir a b b/b
432+
echo "local_repository(name='b', path='b')" > WORKSPACE
433+
echo "sh_library(name='a', deps=['@b//b'])" > a/BUILD
434+
touch b/WORKSPACE
435+
echo "sh_library(name='b')" > b/b/BUILD
436+
bazel query --output package "deps(//a)" >& $TEST_log || fail "query failed"
437+
expect_log "a"
438+
expect_log "@b//b"
439+
}
440+
430441
function test_warning() {
431442
local bar=$TEST_TMPDIR/bar
432443
rm -rf "$bar"

0 commit comments

Comments
 (0)