Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.3.0] Fix query --output=proto --order_output=deps not returning targets in topological order #18870

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ public void output(
}

protected Iterable<Target> getOrderedTargets(Digraph<Target> result, QueryOptions options) {
Iterable<Node<Target>> orderedResult =
options.orderOutput == OrderOutput.DEPS
? result.getTopologicalOrder()
: result.getTopologicalOrder(new FormatUtils.TargetOrdering());
return Iterables.transform(orderedResult, Node::getLabel);
if (options.orderOutput == OrderOutput.FULL) {
// Get targets in total order, the difference here from topological ordering is the sorting of
// nodes before post-order visitation (which ensures determinism at a time cost).
return Iterables.transform(
result.getTopologicalOrder(new FormatUtils.TargetOrdering()), Node::getLabel);
} else if (options.orderOutput == OrderOutput.DEPS) {
// Get targets in topological order.
return Iterables.transform(result.getTopologicalOrder(), Node::getLabel);
}
return result.getLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.graph.Digraph;
import com.google.devtools.build.lib.graph.Node;
import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeFormatter;
Expand All @@ -61,7 +59,6 @@
import com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult;
import com.google.devtools.build.lib.query2.proto.proto2api.Build.SourceFile;
import com.google.devtools.build.lib.query2.query.aspectresolvers.AspectResolver;
import com.google.devtools.build.lib.query2.query.output.QueryOptions.OrderOutput;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -169,16 +166,6 @@ public ThreadSafeOutputFormatterCallback<Target> createStreamCallback(
createPostFactoStreamCallback(out, options, env.getMainRepoMapping()));
}

private static Iterable<Target> getSortedLabels(Digraph<Target> result) {
return Iterables.transform(
result.getTopologicalOrder(new FormatUtils.TargetOrdering()), Node::getLabel);
}

@Override
protected Iterable<Target> getOrderedTargets(Digraph<Target> result, QueryOptions options) {
return options.orderOutput == OrderOutput.FULL ? getSortedLabels(result) : result.getLabels();
}

/** Converts a logical {@link Target} object into a {@link Build.Target} protobuffer. */
public Build.Target toTargetProtoBuffer(Target target) throws InterruptedException {
return toTargetProtoBuffer(target, /*extraDataForAttrHash=*/ "");
Expand Down