From 7dec00574aa91327693f6ba7e90bff5bc834253e Mon Sep 17 00:00:00 2001 From: ajmichael Date: Wed, 7 Jun 2017 18:36:02 -0400 Subject: [PATCH] Make PackageOutputFormatter use PackageIdentifier instead of package name. Fixes #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 --- site/docs/query.html | 59 +------------------ .../lib/query2/output/OutputFormatter.java | 2 +- src/test/shell/bazel/local_repository_test.sh | 11 ++++ 3 files changed, 15 insertions(+), 57 deletions(-) diff --git a/site/docs/query.html b/site/docs/query.html index dbe80e484689d0..7c30dfbfabdb19 100644 --- a/site/docs/query.html +++ b/site/docs/query.html @@ -1231,63 +1231,10 @@

Print the set of packages

- In conjunction with the deps(...) 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 + @repo//foo/bar while packages in the main repository are + formatted as foo/bar.

- -

Display a graph of the result

-
--output graph
-

- This option causes the query result to be printed as a directed - graph in the popular AT&T GraphViz format. Typically the - result is saved to a file, such as .png or .svg. - (If the dot program is not installed on your workstation, you - can install it using the command sudo apt-get install graphviz.) - See the example section below for a sample invocation. -

- -

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

- -

- By default, the graph is rendered in a factored 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 java_library rule - may depend on hundreds of Java source files all generated by the - same genrule; in the factored graph, all these files - are represented by a single node. This behavior may be disabled - with the --nograph:factored option. -

- -

--graph:node_limit n

-

- 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 - --output=graph is being used. -

- -

--[no]graph:factored

-

- By default, graphs are displayed in factored form, as explained - above. - When --nograph:factored 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 --output=graph is being used. -

-

XML

--output xml

diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java index 2fa79b68a26aeb..78231f9d8c3a74 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java +++ b/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java @@ -331,7 +331,7 @@ public OutputFormatterCallback createPostFactoStreamCallback( public void processOutput(Iterable partialResult) { for (Target target : partialResult) { - packageNames.add(target.getLabel().getPackageName()); + packageNames.add(target.getPackage().getPackageIdentifier().toString()); } } diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh index bc3a08a46e7d89..6e9e8538f7fdb1 100755 --- a/src/test/shell/bazel/local_repository_test.sh +++ b/src/test/shell/bazel/local_repository_test.sh @@ -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"