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
diff --git a/src/main/java/com/google/devtools/build/skyframe/EvaluationResult.java b/src/main/java/com/google/devtools/build/skyframe/EvaluationResult.java
index e518dca..92738b0 100644
--- a/src/main/java/com/google/devtools/build/skyframe/EvaluationResult.java
+++ b/src/main/java/com/google/devtools/build/skyframe/EvaluationResult.java
@@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nullable;
+
/**
* The result of a Skyframe {@link Evaluator#eval} call. Will contain all the
* successfully evaluated values, retrievable through {@link #get}. As well, the {@link ErrorInfo}
@@ -38,17 +40,19 @@
private final Map<SkyKey, T> resultMap;
private final Map<SkyKey, ErrorInfo> errorMap;
+ private final WalkableGraph walkableGraph;
/**
* Constructor for the "completed" case. Used only by {@link Builder}.
*/
private EvaluationResult(Map<SkyKey, T> result, Map<SkyKey, ErrorInfo> errorMap,
- boolean hasError) {
+ boolean hasError, @Nullable WalkableGraph walkableGraph) {
Preconditions.checkState(errorMap.isEmpty() || hasError,
"result=%s, errorMap=%s", result, errorMap);
this.resultMap = Preconditions.checkNotNull(result);
this.errorMap = Preconditions.checkNotNull(errorMap);
this.hasError = hasError;
+ this.walkableGraph = walkableGraph;
}
/**
@@ -109,6 +113,11 @@
return names;
}
+ @Nullable
+ public WalkableGraph getWalkableGraph() {
+ return walkableGraph;
+ }
+
/**
* Returns some error info. Convenience method equivalent to
* Iterables.getFirst({@link #errorMap()}, null).getValue().
@@ -140,6 +149,7 @@
private final Map<SkyKey, T> result = new HashMap<>();
private final Map<SkyKey, ErrorInfo> errors = new HashMap<>();
private boolean hasError = false;
+ private WalkableGraph walkableGraph = null;
@SuppressWarnings("unchecked")
public Builder<T> addResult(SkyKey key, SkyValue value) {
@@ -152,8 +162,20 @@
return this;
}
+ public Builder<T> setWalkableGraph(WalkableGraph walkableGraph) {
+ this.walkableGraph = walkableGraph;
+ return this;
+ }
+
+ public Builder<T> mergeFrom(EvaluationResult<T> otherResult) {
+ result.putAll(otherResult.resultMap);
+ errors.putAll(otherResult.errorMap);
+ hasError |= otherResult.hasError;
+ return this;
+ }
+
public EvaluationResult<T> build() {
- return new EvaluationResult<>(result, errors, hasError);
+ return new EvaluationResult<>(result, errors, hasError, walkableGraph);
}
public void setHasError(boolean hasError) {