aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2015-02-26 17:09:18 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-26 17:09:18 +0000
commite72d5222d47ad7b7857f4a3f4eaa6225f6cc8433 (patch)
tree1bfc8fdc221e9669c4dbf315be6a90eacdf7521e /src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
parent8f7358a32428a83324195c8783664281ee2fc3b0 (diff)
Add a SkyQueryEnvironment which runs queries by examining the Skyframe graph.
This environment eagerly preloads the transitive closure of a specified query "universe", and so may not be as efficient as the standard query for limited-scope queries. It is activated when the universe is specified and ordered results are not requested (since it is currently unable to order results). Tests were modified/added to exercise this environment where deemed interesting. Some ugly hacks were done to add coverage in AbstractQueryTest and friends, because currently even if the full depot is loaded (using //...), individual target patterns most likely won't be present in the graph. A better way to deal with this situation, suggested by felly, is probably to extract target pattern resolution logic to an auxiliary function so that query is able to resolve target patterns without mutating the graph, and then call into the read-only graph with the resolved patterns. That may be done in a follow-up, in which case the "scope" of every query could be //... . -- MOS_MIGRATED_REVID=87257028
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
index ede8ecec2e..8c1c2b11d8 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
@@ -17,6 +17,8 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.cmdline.ResolvedTargets;
+import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.graph.Digraph;
import com.google.devtools.build.lib.graph.Node;
@@ -43,6 +45,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -51,6 +54,7 @@ import java.util.Set;
public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> {
private static final int MAX_DEPTH_FULL_SCAN_LIMIT = 20;
+ private final TargetPatternEvaluator targetPatternEvaluator;
private final TransitivePackageLoader transitivePackageLoader;
private final TargetProvider targetProvider;
private final Digraph<Target> graph = new Digraph<>();
@@ -81,9 +85,8 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
EventHandler eventHandler,
Set<Setting> settings,
Iterable<QueryFunction> extraFunctions) {
- super(targetPatternEvaluator, keepGoing, strictScope, labelFilter, eventHandler, settings,
- extraFunctions
- );
+ super(keepGoing, strictScope, labelFilter, eventHandler, settings, extraFunctions);
+ this.targetPatternEvaluator = targetPatternEvaluator;
this.transitivePackageLoader = transitivePackageLoader;
this.targetProvider = packageProvider;
this.errorObserver = new ErrorPrintingTargetEdgeErrorObserver(this.eventHandler);
@@ -93,6 +96,10 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
@Override
public BlazeQueryEvalResult<Target> evaluateQuery(QueryExpression expr) throws QueryException {
+ // Some errors are reported as QueryExceptions and others as ERROR events (if --keep_going). The
+ // result is set to have an error iff there were errors emitted during the query, so we reset
+ // errors here.
+ eventHandler.resetErrors();
QueryEvalResult<Target> queryEvalResult = super.evaluateQuery(expr);
return new BlazeQueryEvalResult<>(queryEvalResult.getSuccess(), queryEvalResult.getResultSet(),
graph);
@@ -334,6 +341,19 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
return dependentFiles;
}
+ protected Map<String, ResolvedTargets<Target>> preloadOrThrow(Collection<String> patterns)
+ throws TargetParsingException {
+ try {
+ // Note that this may throw a RuntimeException if deps are missing in Skyframe and this is
+ // being called from within a SkyFunction.
+ return targetPatternEvaluator.preloadTargetPatterns(
+ eventHandler, patterns, keepGoing);
+ } catch (InterruptedException e) {
+ // TODO(bazel-team): Propagate the InterruptedException from here [skyframe-loading].
+ throw new TargetParsingException("interrupted");
+ }
+ }
+
private static void addIfUniqueLabel(Node<Target> node, Set<Label> labels, Set<Target> nodes) {
if (labels.add(node.getLabel().getLabel())) {
nodes.add(node.getLabel());