aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java16
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/ErrorPrintingTargetEdgeErrorObserver.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java35
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java51
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/TargetEdgeErrorObserver.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java34
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java16
10 files changed, 98 insertions, 93 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
index 07df0c6ce0..5df559945e 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
@@ -33,7 +33,6 @@ import com.google.devtools.build.lib.query2.engine.QueryExpression;
import com.google.devtools.build.lib.query2.engine.QueryUtil.AggregateAllCallback;
import com.google.devtools.build.lib.query2.engine.VariableContext;
import com.google.devtools.build.lib.util.Preconditions;
-
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
@@ -165,7 +164,8 @@ public abstract class AbstractBlazeQueryEnvironment<T>
}
}
- public abstract Target getTarget(Label label) throws TargetNotFoundException, QueryException;
+ public abstract Target getTarget(Label label)
+ throws TargetNotFoundException, QueryException, InterruptedException;
protected boolean validateScope(Label label, boolean strict) throws QueryException {
if (!labelFilter.apply(label)) {
@@ -181,7 +181,7 @@ public abstract class AbstractBlazeQueryEnvironment<T>
}
public Set<T> evalTargetPattern(QueryExpression caller, String pattern)
- throws QueryException {
+ throws QueryException, InterruptedException {
try {
preloadOrThrow(caller, ImmutableList.of(pattern));
} catch (TargetParsingException e) {
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 a29c2c6093..ad6b54002a 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
@@ -48,7 +48,6 @@ import com.google.devtools.build.lib.query2.engine.Uniquifier;
import com.google.devtools.build.lib.query2.engine.VariableContext;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -136,7 +135,8 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
@Override
public void getTargetsMatchingPattern(
- QueryExpression caller, String pattern, Callback<Target> callback) throws QueryException {
+ QueryExpression caller, String pattern, Callback<Target> callback)
+ throws QueryException, InterruptedException {
// We can safely ignore the boolean error flag. The evaluateQuery() method above wraps the
// entire query computation in an error sensor.
diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java
index 81de429aa0..d345a27194 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java
@@ -38,7 +38,6 @@ import com.google.devtools.build.lib.query2.engine.QueryExpression;
import com.google.devtools.build.lib.query2.engine.QueryVisibility;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.Preconditions;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -71,8 +70,9 @@ final class BlazeTargetAccessor implements TargetAccessor<Target> {
}
@Override
- public List<Target> getLabelListAttr(QueryExpression caller, Target target, String attrName,
- String errorMsgPrefix) throws QueryException {
+ public List<Target> getLabelListAttr(
+ QueryExpression caller, Target target, String attrName, String errorMsgPrefix)
+ throws QueryException, InterruptedException {
Preconditions.checkArgument(target instanceof Rule);
List<Target> result = new ArrayList<>();
@@ -163,7 +163,8 @@ final class BlazeTargetAccessor implements TargetAccessor<Target> {
}
@Override
- public Set<QueryVisibility<Target>> getVisibility(Target target) throws QueryException {
+ public Set<QueryVisibility<Target>> getVisibility(Target target)
+ throws QueryException, InterruptedException {
ImmutableSet.Builder<QueryVisibility<Target>> result = ImmutableSet.builder();
result.add(QueryVisibility.samePackage(target, this));
convertVisibility(result, target);
@@ -172,9 +173,8 @@ final class BlazeTargetAccessor implements TargetAccessor<Target> {
// CAUTION: keep in sync with ConfiguredTargetFactory#convertVisibility()
private void convertVisibility(
- ImmutableSet.Builder<QueryVisibility<Target>> packageSpecifications,
- Target target)
- throws QueryException {
+ ImmutableSet.Builder<QueryVisibility<Target>> packageSpecifications, Target target)
+ throws QueryException, InterruptedException {
RuleVisibility ruleVisibility = target.getVisibility();
if (ruleVisibility instanceof ConstantRuleVisibility) {
if (((ConstantRuleVisibility) ruleVisibility).isPubliclyVisible()) {
@@ -203,7 +203,7 @@ final class BlazeTargetAccessor implements TargetAccessor<Target> {
private void convertGroupVisibility(
PackageGroup group, ImmutableSet.Builder<QueryVisibility<Target>> packageSpecifications)
- throws QueryException, TargetNotFoundException {
+ throws QueryException, TargetNotFoundException, InterruptedException {
for (Label include : group.getIncludes()) {
convertGroupVisibility((PackageGroup) queryEnvironment.getTarget(include),
packageSpecifications);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/ErrorPrintingTargetEdgeErrorObserver.java b/src/main/java/com/google/devtools/build/lib/query2/ErrorPrintingTargetEdgeErrorObserver.java
index b129d59c2b..11b6f790d5 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/ErrorPrintingTargetEdgeErrorObserver.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/ErrorPrintingTargetEdgeErrorObserver.java
@@ -45,7 +45,8 @@ class ErrorPrintingTargetEdgeErrorObserver extends TargetEdgeErrorObserver {
@ThreadSafety.ThreadSafe
@Override
- public void missingEdge(Target target, Label label, NoSuchThingException e) {
+ public void missingEdge(Target target, Label label, NoSuchThingException e)
+ throws InterruptedException {
eventHandler.handle(Event.error(TargetUtils.getLocationMaybe(target),
TargetUtils.formatMissingEdge(target, label, e)));
super.missingEdge(target, label, e);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java b/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java
index 84098386fd..c0236010f2 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java
@@ -41,7 +41,6 @@ import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.pkgcache.PackageProvider;
import com.google.devtools.build.lib.pkgcache.TargetEdgeObserver;
-
import java.util.Collection;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
@@ -292,13 +291,12 @@ final class LabelVisitor {
}
/**
- * Visit the specified labels and follow the transitive closure of their
- * outbound dependencies.
+ * Visit the specified labels and follow the transitive closure of their outbound dependencies.
*
* @param targets the targets to visit
*/
@ThreadSafe
- public void visitTargets(Iterable<Target> targets) {
+ public void visitTargets(Iterable<Target> targets) throws InterruptedException {
for (Target target : targets) {
visit(null, null, target, 0, 0);
}
@@ -340,13 +338,15 @@ final class LabelVisitor {
private Runnable newVisitRunnable(final Target from, final Attribute attr, final Label label,
final int depth, final int count) {
- return new Runnable () {
+ return new Runnable() {
@Override
public void run() {
try {
- visit(from, attr, packageProvider.getTarget(eventHandler, label), depth + 1, count);
- } catch (NoSuchThingException e) {
- observeError(from, label, e);
+ try {
+ visit(from, attr, packageProvider.getTarget(eventHandler, label), depth + 1, count);
+ } catch (NoSuchThingException e) {
+ observeError(from, label, e);
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
@@ -381,7 +381,8 @@ final class LabelVisitor {
* @param rule the rule to visit
*/
@ThreadSafe
- private void visitRule(final Rule rule, final int depth, final int count) {
+ private void visitRule(final Rule rule, final int depth, final int count)
+ throws InterruptedException {
// Follow all labels defined by this rule:
AggregatingAttributeMapper.of(rule).visitLabels(new AttributeMap.AcceptsLabelAttribute() {
@Override
@@ -404,11 +405,11 @@ final class LabelVisitor {
/**
* Visits the target and its package.
*
- * <p>Potentially blocking invocations into the package cache are
- * enqueued in the worker pool if CONCURRENT.
+ * <p>Potentially blocking invocations into the package cache are enqueued in the worker pool if
+ * CONCURRENT.
*/
- private void visit(
- Target from, Attribute attribute, final Target target, int depth, int count) {
+ private void visit(Target from, Attribute attribute, final Target target, int depth, int count)
+ throws InterruptedException {
if (target == null) {
throw new NullPointerException(
String.format("'%s' attribute '%s'",
@@ -439,12 +440,11 @@ final class LabelVisitor {
}
/**
- * Visit the specified target.
- * Called in a worker thread if CONCURRENT.
+ * Visit the specified target. Called in a worker thread if CONCURRENT.
*
* @param target the target to visit
*/
- private void visitTargetNode(Target target, int depth, int count) {
+ private void visitTargetNode(Target target, int depth, int count) throws InterruptedException {
Integer minTargetDepth = visitedTargets.putIfAbsent(target.getLabel(), depth);
if (minTargetDepth != null) {
// The target was already visited at a greater depth.
@@ -493,7 +493,8 @@ final class LabelVisitor {
}
}
- private void observeError(Target from, Label label, NoSuchThingException e) {
+ private void observeError(Target from, Label label, NoSuchThingException e)
+ throws InterruptedException {
for (TargetEdgeObserver observer : observers) {
observer.missingEdge(from, label, e);
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index 40d8a89810..2260282eb8 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -18,8 +18,6 @@ import com.google.common.base.Ascii;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
@@ -82,6 +80,7 @@ import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.EvaluationResult;
+import com.google.devtools.build.skyframe.InterruptibleSupplier;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -146,7 +145,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
// The following fields are set in the #beforeEvaluateQuery method.
protected WalkableGraph graph;
- private Supplier<ImmutableSet<PathFragment>> blacklistPatternsSupplier;
+ private InterruptibleSupplier<ImmutableSet<PathFragment>> blacklistPatternsSupplier;
private RecursivePackageProviderBackedTargetPatternResolver resolver;
public SkyQueryEnvironment(
@@ -186,7 +185,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
checkEvaluationResult(result, universeKey);
graph = result.getWalkableGraph();
- blacklistPatternsSupplier = Suppliers.memoize(new BlacklistSupplier(graph));
+ blacklistPatternsSupplier = InterruptibleSupplier.Memoize.of(new BlacklistSupplier(graph));
ImmutableList<TargetPatternKey> universeTargetPatternKeys =
PrepareDepsOfPatternsFunction.getTargetPatternKeys(
@@ -345,7 +344,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
return new QueryEvalResult(!eventHandler.hasErrors(), empty.get());
}
- private Map<Target, Collection<Target>> makeTargetsMap(Map<SkyKey, Iterable<SkyKey>> input) {
+ private Map<Target, Collection<Target>> makeTargetsMap(Map<SkyKey, Iterable<SkyKey>> input)
+ throws InterruptedException {
ImmutableMap.Builder<Target, Collection<Target>> result = ImmutableMap.builder();
Map<SkyKey, Target> allTargets =
@@ -365,15 +365,17 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
return result.build();
}
- private Map<Target, Collection<Target>> getRawFwdDeps(Iterable<Target> targets) {
+ private Map<Target, Collection<Target>> getRawFwdDeps(Iterable<Target> targets)
+ throws InterruptedException {
return makeTargetsMap(graph.getDirectDeps(makeTransitiveTraversalKeys(targets)));
}
- private Map<Target, Collection<Target>> getRawReverseDeps(Iterable<Target> targets) {
+ private Map<Target, Collection<Target>> getRawReverseDeps(Iterable<Target> targets)
+ throws InterruptedException {
return makeTargetsMap(graph.getReverseDeps(makeTransitiveTraversalKeys(targets)));
}
- private Set<Label> getAllowedDeps(Rule rule) {
+ private Set<Label> getAllowedDeps(Rule rule) throws InterruptedException {
Set<Label> allowedLabels = new HashSet<>(rule.getTransitions(dependencyFilter).values());
allowedLabels.addAll(rule.getVisibility().getDependencyLabels());
// We should add deps from aspects, otherwise they are going to be filtered out.
@@ -381,7 +383,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
return allowedLabels;
}
- private Collection<Target> filterFwdDeps(Target target, Collection<Target> rawFwdDeps) {
+ private Collection<Target> filterFwdDeps(Target target, Collection<Target> rawFwdDeps)
+ throws InterruptedException {
if (!(target instanceof Rule)) {
return rawFwdDeps;
}
@@ -405,7 +408,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
@Override
- public Collection<Target> getFwdDeps(Iterable<Target> targets) {
+ public Collection<Target> getFwdDeps(Iterable<Target> targets) throws InterruptedException {
Set<Target> result = new HashSet<>();
Map<Target, Collection<Target>> rawFwdDeps = getRawFwdDeps(targets);
warnIfMissingTargets(targets, rawFwdDeps.keySet());
@@ -416,14 +419,15 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
@Override
- public Collection<Target> getReverseDeps(Iterable<Target> targets) {
+ public Collection<Target> getReverseDeps(Iterable<Target> targets) throws InterruptedException {
Map<Target, Collection<Target>> rawReverseDeps = getRawReverseDeps(targets);
warnIfMissingTargets(targets, rawReverseDeps.keySet());
return processRawReverseDeps(rawReverseDeps);
}
- private Collection<Target> processRawReverseDeps(Map<Target, Collection<Target>> rawReverseDeps) {
+ private Collection<Target> processRawReverseDeps(Map<Target, Collection<Target>> rawReverseDeps)
+ throws InterruptedException {
Set<Target> result = CompactHashSet.create();
CompactHashSet<Target> visited =
CompactHashSet.createWithExpectedSize(totalSizeOfCollections(rawReverseDeps.values()));
@@ -457,7 +461,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
@Override
- public Set<Target> getTransitiveClosure(Set<Target> targets) {
+ public Set<Target> getTransitiveClosure(Set<Target> targets) throws InterruptedException {
Set<Target> visited = new HashSet<>();
Collection<Target> current = targets;
while (!current.isEmpty()) {
@@ -471,7 +475,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
// Implemented with a breadth-first search.
@Override
- public Set<Target> getNodesOnPath(Target from, Target to) {
+ public Set<Target> getNodesOnPath(Target from, Target to) throws InterruptedException {
// Tree of nodes visited so far.
Map<Target, Target> nodeToParent = new HashMap<>();
// Contains all nodes left to visit in a (LIFO) stack.
@@ -595,7 +599,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
@Override
- public Target getTarget(Label label) throws TargetNotFoundException, QueryException {
+ public Target getTarget(Label label)
+ throws TargetNotFoundException, QueryException, InterruptedException {
SkyKey packageKey = PackageValue.key(label.getPackageIdentifier());
if (!graph.exists(packageKey)) {
throw new QueryException(packageKey + " does not exist in graph");
@@ -617,7 +622,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
}
- public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) {
+ public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds)
+ throws InterruptedException {
Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));
ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
@@ -631,7 +637,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
@Override
public void buildTransitiveClosure(QueryExpression caller, Set<Target> targets, int maxDepth)
- throws QueryException {
+ throws QueryException, InterruptedException {
// Everything has already been loaded, so here we just check for errors so that we can
// pre-emptively throw/report if needed.
Iterable<SkyKey> transitiveTraversalKeys = makeTransitiveTraversalKeys(targets);
@@ -694,7 +700,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
};
- private Map<SkyKey, Target> makeTargetsFromSkyKeys(Iterable<SkyKey> keys) {
+ private Map<SkyKey, Target> makeTargetsFromSkyKeys(Iterable<SkyKey> keys)
+ throws InterruptedException {
Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = ArrayListMultimap.create();
for (SkyKey key : keys) {
Label label = SKYKEY_TO_LABEL.apply(key);
@@ -776,7 +783,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
*
* <p>Note that there may not be nodes in the graph corresponding to the returned SkyKeys.
*/
- private Collection<SkyKey> getSkyKeysForFileFragments(Iterable<PathFragment> pathFragments) {
+ private Collection<SkyKey> getSkyKeysForFileFragments(Iterable<PathFragment> pathFragments)
+ throws InterruptedException {
Set<SkyKey> result = new HashSet<>();
Multimap<PathFragment, PathFragment> currentToOriginal = ArrayListMultimap.create();
for (PathFragment pathFragment : pathFragments) {
@@ -898,7 +906,8 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
.build();
}
- private static class BlacklistSupplier implements Supplier<ImmutableSet<PathFragment>> {
+ private static class BlacklistSupplier
+ implements InterruptibleSupplier<ImmutableSet<PathFragment>> {
private final WalkableGraph graph;
BlacklistSupplier(WalkableGraph graph) {
@@ -906,7 +915,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
@Override
- public ImmutableSet<PathFragment> get() {
+ public ImmutableSet<PathFragment> get() throws InterruptedException {
return ((BlacklistedPackagePrefixesValue)
graph.getValue(BlacklistedPackagePrefixesValue.key()))
.getPatterns();
diff --git a/src/main/java/com/google/devtools/build/lib/query2/TargetEdgeErrorObserver.java b/src/main/java/com/google/devtools/build/lib/query2/TargetEdgeErrorObserver.java
index 3e81571067..06c60ce5d2 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/TargetEdgeErrorObserver.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/TargetEdgeErrorObserver.java
@@ -43,15 +43,16 @@ class TargetEdgeErrorObserver implements TargetEdgeObserver {
private volatile boolean hasErrors = false;
/**
- * Reports an unresolved label error and records the fact that an error was
- * encountered.
+ * Reports an unresolved label error and records the fact that an error was encountered.
+ *
* @param target the target that referenced the unresolved label
* @param label the label that could not be resolved
* @param e the exception that was thrown when the label could not be resolved
*/
@ThreadSafety.ThreadSafe
@Override
- public void missingEdge(Target target, Label label, NoSuchThingException e) {
+ public void missingEdge(Target target, Label label, NoSuchThingException e)
+ throws InterruptedException {
hasErrors = true;
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java
index 88a2ea99f1..9653841b1b 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java
@@ -14,11 +14,9 @@
package com.google.devtools.build.lib.query2.engine;
import com.google.common.collect.ImmutableList;
-
import java.util.Collection;
import java.util.List;
import java.util.Set;
-
import javax.annotation.Nonnull;
/**
@@ -143,7 +141,7 @@ public interface QueryEnvironment<T> {
* pattern, in 'blaze build' syntax.
*/
void getTargetsMatchingPattern(QueryExpression owner, String pattern, Callback<T> callback)
- throws QueryException;
+ throws QueryException, InterruptedException;
/** Ensures the specified target exists. */
// NOTE(bazel-team): this method is left here as scaffolding from a previous refactoring. It may
@@ -151,17 +149,16 @@ public interface QueryEnvironment<T> {
T getOrCreate(T target);
/** Returns the direct forward dependencies of the specified targets. */
- Collection<T> getFwdDeps(Iterable<T> targets);
+ Collection<T> getFwdDeps(Iterable<T> targets) throws InterruptedException;
/** Returns the direct reverse dependencies of the specified targets. */
- Collection<T> getReverseDeps(Iterable<T> targets);
+ Collection<T> getReverseDeps(Iterable<T> targets) throws InterruptedException;
/**
- * Returns the forward transitive closure of all of the targets in
- * "targets". Callers must ensure that {@link #buildTransitiveClosure}
- * has been called for the relevant subgraph.
+ * Returns the forward transitive closure of all of the targets in "targets". Callers must ensure
+ * that {@link #buildTransitiveClosure} has been called for the relevant subgraph.
*/
- Set<T> getTransitiveClosure(Set<T> targets);
+ Set<T> getTransitiveClosure(Set<T> targets) throws InterruptedException;
/**
* Construct the dependency graph for a depth-bounded forward transitive closure
@@ -176,10 +173,8 @@ public interface QueryEnvironment<T> {
Set<T> targetNodes,
int maxDepth) throws QueryException, InterruptedException;
- /**
- * Returns the set of nodes on some path from "from" to "to".
- */
- Set<T> getNodesOnPath(T from, T to);
+ /** Returns the set of nodes on some path from "from" to "to". */
+ Set<T> getNodesOnPath(T from, T to) throws InterruptedException;
/**
* Eval an expression {@code expr} and pass the results to the {@code callback}.
@@ -201,12 +196,12 @@ public interface QueryEnvironment<T> {
void reportBuildFileError(QueryExpression expression, String msg) throws QueryException;
/**
- * Returns the set of BUILD, and optionally sub-included and Skylark files that define the given set of
- * targets. Each such file is itself represented as a target in the result.
+ * Returns the set of BUILD, and optionally sub-included and Skylark files that define the given
+ * set of targets. Each such file is itself represented as a target in the result.
*/
Set<T> getBuildFiles(
QueryExpression caller, Set<T> nodes, boolean buildFiles, boolean subincludes, boolean loads)
- throws QueryException;
+ throws QueryException, InterruptedException;
/**
* Returns an object that can be used to query information about targets. Implementations should
@@ -307,8 +302,9 @@ public interface QueryEnvironment<T> {
*
* @throws IllegalArgumentException if target is not a rule (according to {@link #isRule})
*/
- List<T> getLabelListAttr(QueryExpression caller, T target, String attrName,
- String errorMsgPrefix) throws QueryException;
+ List<T> getLabelListAttr(
+ QueryExpression caller, T target, String attrName, String errorMsgPrefix)
+ throws QueryException, InterruptedException;
/**
* If the attribute of the given name on the given target is a string list, then this method
@@ -347,7 +343,7 @@ public interface QueryEnvironment<T> {
* Returns the set of package specifications the given target is visible from, represented as
* {@link QueryVisibility}s.
*/
- Set<QueryVisibility<T>> getVisibility(T from) throws QueryException;
+ Set<QueryVisibility<T>> getVisibility(T from) throws QueryException, InterruptedException;
}
/** List of the default query functions. */
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java
index 02ce8cc405..77dc6b4899 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java
@@ -19,7 +19,6 @@ import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.ArgumentType;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -161,12 +160,12 @@ class TestsFunction implements QueryFunction {
}
/**
- * Computes and returns the set of test rules in a particular suite. Uses
- * dynamic programming---a memoized version of {@link #computeTestsInSuite}.
+ * Computes and returns the set of test rules in a particular suite. Uses dynamic
+ * programming---a memoized version of {@link #computeTestsInSuite}.
*
* @precondition env.getAccessor().isTestSuite(testSuite)
*/
- private Set<T> getTestsInSuite(T testSuite) throws QueryException {
+ private Set<T> getTestsInSuite(T testSuite) throws QueryException, InterruptedException {
Set<T> tests = testsInSuite.get(testSuite);
if (tests == null) {
tests = Sets.newHashSet();
@@ -177,14 +176,15 @@ class TestsFunction implements QueryFunction {
}
/**
- * Populates 'result' with all the tests associated with the specified
- * 'testSuite'. Throws an exception if any target is missing.
+ * Populates 'result' with all the tests associated with the specified 'testSuite'. Throws an
+ * exception if any target is missing.
*
- * <p>CAUTION! Keep this logic consistent with {@code TestsSuiteConfiguredTarget}!
+ * <p>CAUTION! Keep this logic consistent with {@code TestsSuiteConfiguredTarget}!
*
* @precondition env.getAccessor().isTestSuite(testSuite)
*/
- private void computeTestsInSuite(T testSuite, Set<T> result) throws QueryException {
+ private void computeTestsInSuite(T testSuite, Set<T> result)
+ throws QueryException, InterruptedException {
List<T> testsAndSuites = new ArrayList<>();
// Note that testsAndSuites can contain input file targets; the test_suite rule does not
// restrict the set of targets that can appear in tests or suites.
@@ -231,7 +231,8 @@ class TestsFunction implements QueryFunction {
*
* @precondition env.getAccessor().isTestSuite(testSuite)
*/
- private List<T> getPrerequisites(T testSuite, String attrName) throws QueryException {
+ private List<T> getPrerequisites(T testSuite, String attrName)
+ throws QueryException, InterruptedException {
return env.getAccessor().getLabelListAttr(expression, testSuite, attrName,
"couldn't expand '" + attrName
+ "' attribute of test_suite " + env.getAccessor().getLabel(testSuite) + ": ");
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java
index 03a2ccf2bb..f69f134bc1 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java
@@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.ArgumentType;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction;
-
import java.util.List;
import java.util.Set;
@@ -71,11 +70,9 @@ public class VisibleFunction implements QueryFunction {
});
}
- /**
- * Returns true if {@code target} is visible to all targets in {@code toSet}.
- */
- private static <T> boolean visibleToAll(
- QueryEnvironment<T> env, Set<T> toSet, T target) throws QueryException {
+ /** Returns true if {@code target} is visible to all targets in {@code toSet}. */
+ private static <T> boolean visibleToAll(QueryEnvironment<T> env, Set<T> toSet, T target)
+ throws QueryException, InterruptedException {
for (T to : toSet) {
if (!visible(env, to, target)) {
return false;
@@ -84,10 +81,9 @@ public class VisibleFunction implements QueryFunction {
return true;
}
- /**
- * Returns true if the target {@code from} is visible to the target {@code to}.
- */
- public static <T> boolean visible(QueryEnvironment<T> env, T to, T from) throws QueryException {
+ /** Returns true if the target {@code from} is visible to the target {@code to}. */
+ public static <T> boolean visible(QueryEnvironment<T> env, T to, T from)
+ throws QueryException, InterruptedException {
Set<QueryVisibility<T>> visiblePackages = env.getAccessor().getVisibility(from);
for (QueryVisibility<T> spec : visiblePackages) {
if (spec.contains(to)) {