diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java index 6935ffbfb3c60a..41ca55ef63b445 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java @@ -255,7 +255,8 @@ private static ImmutableMap getTransitiveConfig out, skyframeExecutor, accessor, - kct -> getFwdDeps(ImmutableList.of(kct))), + kct -> getFwdDeps(ImmutableList.of(kct)), + getMainRepoMapping()), new StarlarkOutputFormatterCallback( eventHandler, cqueryOptions, out, skyframeExecutor, accessor), new FilesOutputFormatterCallback( diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java index 7630ee31036905..1cb2c5373f97de 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java @@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.graph.Digraph; import com.google.devtools.build.lib.graph.Node; @@ -65,12 +66,14 @@ Iterable getDirectDeps(KeyedConfiguredTarget target) }; @Override - public String getLabel(Node node) { + public String getLabel(Node node, + RepositoryMapping mainRepositoryMapping) { // Node payloads are ConfiguredTargets. Output node labels are target labels + config // hashes. KeyedConfiguredTarget kct = node.getLabel(); return String.format( - "%s (%s)", kct.getLabel(), shortId(getConfiguration(kct.getConfigurationKey()))); + "%s (%s)", kct.getLabel().getDisplayForm(mainRepositoryMapping), + shortId(getConfiguration(kct.getConfigurationKey()))); } @Override @@ -79,15 +82,19 @@ public Comparator comparator() { } }; + private final RepositoryMapping mainRepoMapping; + GraphOutputFormatterCallback( ExtendedEventHandler eventHandler, CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, TargetAccessor accessor, - DepsRetriever depsRetriever) { + DepsRetriever depsRetriever, + RepositoryMapping mainRepoMapping) { super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false); this.depsRetriever = depsRetriever; + this.mainRepoMapping = mainRepoMapping; } @Override @@ -117,7 +124,8 @@ public void processOutput(Iterable partialResult) // select() conditions don't matter for cquery because cquery operates post-analysis // phase, when select()s have been resolved and removed from the graph. /*maxConditionalEdges=*/ 0, - options.graphFactored); + options.graphFactored, + mainRepoMapping); graphWriter.write(graph, /*conditionalEdges=*/ null, outputStream); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputFormatter.java index ab8a5a4046b1f5..024f106cbd3c73 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputFormatter.java +++ b/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputFormatter.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.query2.query.output; import com.google.common.hash.HashFunction; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.graph.Digraph; import com.google.devtools.build.lib.graph.Node; @@ -41,9 +42,9 @@ public String getName() { private final TargetOrdering targetOrdering = new FormatUtils.TargetOrdering(); @Override - public String getLabel(Node node) { + public String getLabel(Node node, RepositoryMapping mainRepositoryMapping) { // Node payloads are Targets. Output node labels are target labels. - return node.getLabel().getLabel().toString(); + return node.getLabel().getLabel().getDisplayForm(mainRepositoryMapping); } @Override @@ -69,7 +70,8 @@ public void output( sortLabels, options.graphNodeStringLimit, options.graphConditionalEdgesLimit, - options.graphFactored); + options.graphFactored, + env.getMainRepoMapping()); graphWriter.write(result, new ConditionalEdges(result), out); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputWriter.java b/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputWriter.java index 5ab5514ef05e5b..f80336290fdbbf 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputWriter.java +++ b/src/main/java/com/google/devtools/build/lib/query2/query/output/GraphOutputWriter.java @@ -19,6 +19,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.collect.CollectionUtils; import com.google.devtools.build.lib.collect.EquivalenceRelation; import com.google.devtools.build.lib.graph.Digraph; @@ -54,7 +55,7 @@ public interface NodeReader { *

This is not the same as a build {@link Label}. This is just the text associated with a * node in a GraphViz graph. */ - String getLabel(Node node); + String getLabel(Node node, RepositoryMapping mainRepositoryMapping); /** Returns a comparator for the build graph nodes that form the payloads of GraphViz nodes. */ Comparator comparator(); @@ -67,6 +68,7 @@ public interface NodeReader { private final int maxConditionalEdges; private final boolean mergeEquivalentNodes; private final Ordering> nodeComparator; + private final RepositoryMapping mainRepoMapping; private static final int RESERVED_LABEL_CHARS = "\\n...and 9999999 more items".length(); @@ -90,13 +92,15 @@ public GraphOutputWriter( boolean sortLabels, int maxLabelSize, int maxConditionalEdges, - boolean mergeEquivalentNodes) { + boolean mergeEquivalentNodes, + RepositoryMapping mainRepoMapping) { this.nodeReader = nodeReader; this.lineTerminator = lineTerminator; this.sortLabels = sortLabels; this.maxLabelSize = maxLabelSize; this.maxConditionalEdges = maxConditionalEdges; this.mergeEquivalentNodes = mergeEquivalentNodes; + this.mainRepoMapping = mainRepoMapping; nodeComparator = Ordering.from(nodeReader.comparator()).onResultOf(Node::getLabel); } @@ -120,7 +124,7 @@ public void write( private void outputUnfactored( Digraph graph, @Nullable ConditionalEdges conditionalEdges, PrintWriter out) { graph.visitNodesBeforeEdges( - new DotOutputVisitor(out, nodeReader::getLabel) { + new DotOutputVisitor(out, node -> nodeReader.getLabel(node, mainRepoMapping)) { @Override public void beginVisit() { super.beginVisit(); @@ -180,7 +184,7 @@ private void outputFactored( StringBuilder buf = new StringBuilder(); int count = 0; for (Node eqNode : node.getLabel()) { - String labelString = nodeReader.getLabel(eqNode); + String labelString = nodeReader.getLabel(eqNode, mainRepoMapping); if (!firstItem) { buf.append("\\n"); diff --git a/src/main/java/com/google/devtools/build/lib/query2/query/output/LocationOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/query/output/LocationOutputFormatter.java index 347ab273f4027c..b6cb2487e36969 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/query/output/LocationOutputFormatter.java +++ b/src/main/java/com/google/devtools/build/lib/query2/query/output/LocationOutputFormatter.java @@ -87,7 +87,7 @@ public void processOutput(Iterable partialResult) throws IOException { .append(": ") .append(target.getTargetKind()) .append(" ") - .append(target.getLabel().getCanonicalForm()) + .append(target.getLabel().getDisplayForm(env.getMainRepoMapping())) .append(lineTerm); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/query/output/MaxrankOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/query/output/MaxrankOutputFormatter.java index 8394109ecbc11f..e808297f8093a2 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/query/output/MaxrankOutputFormatter.java +++ b/src/main/java/com/google/devtools/build/lib/query2/query/output/MaxrankOutputFormatter.java @@ -104,7 +104,7 @@ int rank(Node>> node) { final String lineTerm = options.getLineTerminator(); PrintStream printStream = new PrintStream(out); for (RankAndLabel item : output) { - printStream.print(item + lineTerm); + printStream.print(item.toDisplayString(env.getMainRepoMapping()) + lineTerm); } flushAndCheckError(printStream); } diff --git a/src/main/java/com/google/devtools/build/lib/query2/query/output/MinrankOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/query/output/MinrankOutputFormatter.java index 7500ca36866ff8..575c15b45325a2 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/query/output/MinrankOutputFormatter.java +++ b/src/main/java/com/google/devtools/build/lib/query2/query/output/MinrankOutputFormatter.java @@ -110,7 +110,7 @@ public void output( if (outputToOrder != null) { Collections.sort(outputToOrder); for (RankAndLabel item : outputToOrder) { - printStream.print(item + lineTerm); + printStream.print(item.toDisplayString(env.getMainRepoMapping()) + lineTerm); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/query/output/RankAndLabel.java b/src/main/java/com/google/devtools/build/lib/query2/query/output/RankAndLabel.java index 516b930926e723..3b957829231527 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/query/output/RankAndLabel.java +++ b/src/main/java/com/google/devtools/build/lib/query2/query/output/RankAndLabel.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.query2.query.output; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; class RankAndLabel implements Comparable { private final int rank; @@ -39,6 +40,10 @@ public int compareTo(RankAndLabel o) { @Override public String toString() { - return rank + " " + label.getCanonicalForm(); + return toDisplayString(RepositoryMapping.ALWAYS_FALLBACK); + } + + public String toDisplayString(RepositoryMapping mainRepoMapping) { + return rank + " " + label.getDisplayForm(mainRepoMapping); } } \ No newline at end of file diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java index f10fc441d284fa..e90a83170e593e 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; @@ -80,7 +81,8 @@ private List getOutput(String queryExpression) throws Exception { new PrintStream(output), getHelper().getSkyframeExecutor(), env.getAccessor(), - ct -> env.getFwdDeps(ImmutableList.of(ct))); + ct -> env.getFwdDeps(ImmutableList.of(ct)), + RepositoryMapping.ALWAYS_FALLBACK); env.evaluateQuery(expression, callback); return Arrays.asList(output.toString().split(System.lineSeparator())); }