From e6b9dc2f8d94e5611b7c45cc7692c49b999904df Mon Sep 17 00:00:00 2001 From: Nathan Harmata Date: Tue, 20 Sep 2016 17:20:41 +0000 Subject: Introduce a new method on the StreamedFormatter interface for creating a callback for streaming a precomputed result. -- MOS_MIGRATED_REVID=133720742 --- .../build/lib/query2/output/OutputFormatter.java | 55 ++++++++++++++++++---- .../lib/query2/output/ProtoOutputFormatter.java | 9 +++- .../build/lib/query2/output/QueryOutputUtils.java | 3 +- .../lib/query2/output/XmlOutputFormatter.java | 7 +++ .../build/lib/runtime/commands/QueryCommand.java | 2 +- 5 files changed, 65 insertions(+), 11 deletions(-) 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 f47d94942b..8a3c4b6318 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 @@ -31,6 +31,7 @@ import com.google.devtools.build.lib.packages.License; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.query2.engine.OutputFormatterCallback; +import com.google.devtools.build.lib.query2.engine.QueryEnvironment; import com.google.devtools.build.lib.query2.output.QueryOptions.OrderOutput; import com.google.devtools.build.lib.syntax.EvalUtils; import com.google.devtools.build.lib.syntax.Printer; @@ -154,7 +155,8 @@ public abstract class OutputFormatter implements Serializable { * the graph maintained by the QueryEnvironment), and print it to "out". */ public abstract void output(QueryOptions options, Digraph result, PrintStream out, - AspectResolver aspectProvider) throws IOException, InterruptedException; + AspectResolver aspectProvider) + throws IOException, InterruptedException; /** * Unordered streamed output formatter (wrt. dependency ordering). @@ -177,8 +179,18 @@ public abstract class OutputFormatter implements Serializable { * *

Takes any options specified via the most recent call to {@link #setOptions} into * consideration. + * + *

Intended to be use for streaming out during evaluation of a query. + */ + OutputFormatterCallback createStreamCallback( + PrintStream out, QueryOptions options, @Nullable QueryEnvironment env); + + /** + * Same as {@link #createStreamCallback}, but intended to be used for outputting the + * already-computed result of a query. */ - OutputFormatterCallback createStreamCallback(PrintStream out, QueryOptions options); + OutputFormatterCallback createPostFactoStreamCallback( + PrintStream out, QueryOptions options); } /** @@ -209,11 +221,14 @@ public abstract class OutputFormatter implements Serializable { } @Override - public void output(QueryOptions options, Digraph result, PrintStream out, + public void output( + QueryOptions options, + Digraph result, + PrintStream out, AspectResolver aspectResolver) throws IOException, InterruptedException { setOptions(options, aspectResolver); OutputFormatterCallback.processAllTargets( - createStreamCallback(out, options), getOrderedTargets(result, options)); + createPostFactoStreamCallback(out, options), getOrderedTargets(result, options)); } } @@ -235,7 +250,7 @@ public abstract class OutputFormatter implements Serializable { } @Override - public OutputFormatterCallback createStreamCallback( + public OutputFormatterCallback createPostFactoStreamCallback( final PrintStream out, final QueryOptions options) { return new OutputFormatterCallback() { @@ -253,6 +268,12 @@ public abstract class OutputFormatter implements Serializable { } }; } + + @Override + public OutputFormatterCallback createStreamCallback( + PrintStream out, QueryOptions options, QueryEnvironment env) { + return createPostFactoStreamCallback(out, options); + } } /** @@ -279,7 +300,7 @@ public abstract class OutputFormatter implements Serializable { } @Override - public OutputFormatterCallback createStreamCallback( + public OutputFormatterCallback createPostFactoStreamCallback( final PrintStream out, final QueryOptions options) { return new OutputFormatterCallback() { private final Set packageNames = Sets.newTreeSet(); @@ -302,6 +323,12 @@ public abstract class OutputFormatter implements Serializable { } }; } + + @Override + public OutputFormatterCallback createStreamCallback( + PrintStream out, QueryOptions options, QueryEnvironment env) { + return createPostFactoStreamCallback(out, options); + } } /** @@ -318,7 +345,7 @@ public abstract class OutputFormatter implements Serializable { } @Override - public OutputFormatterCallback createStreamCallback( + public OutputFormatterCallback createPostFactoStreamCallback( final PrintStream out, final QueryOptions options) { return new OutputFormatterCallback() { @@ -339,6 +366,12 @@ public abstract class OutputFormatter implements Serializable { } }; } + + @Override + public OutputFormatterCallback createStreamCallback( + PrintStream out, QueryOptions options, QueryEnvironment env) { + return createPostFactoStreamCallback(out, options); + } } /** @@ -354,7 +387,7 @@ public abstract class OutputFormatter implements Serializable { } @Override - public OutputFormatterCallback createStreamCallback( + public OutputFormatterCallback createPostFactoStreamCallback( final PrintStream out, final QueryOptions options) { return new OutputFormatterCallback() { private final Set