Skip to content

Commit

Permalink
Rollback of commit 8e7da87.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

--
MOS_MIGRATED_REVID=109005097
  • Loading branch information
aragos authored and kchodorow committed Dec 1, 2015
1 parent 7be8186 commit 016b4b6
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 460 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
import com.google.devtools.build.lib.query2.AbstractBlazeQueryEnvironment;
import com.google.devtools.build.lib.query2.engine.Callback;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting;
import com.google.devtools.build.lib.query2.engine.QueryException;
import com.google.devtools.build.lib.query2.engine.QueryExpression;
Expand Down Expand Up @@ -122,13 +121,7 @@ public ExitCode exec(CommandEnvironment env, OptionsProvider options) {

// 2. Evaluate expression:
try {
queryEnv.evaluateQuery(expr, new Callback<Target>() {
@Override
public void process(Iterable<Target> partialResult)
throws QueryException, InterruptedException {
// Throw away the result.
}
});
queryEnv.evaluateQuery(expr);
} catch (QueryException | InterruptedException e) {
// Keep consistent with reportBuildFileError()
env.getReporter().handle(Event.error(e.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
Expand All @@ -32,11 +31,11 @@
import com.google.devtools.build.lib.pkgcache.TargetPatternEvaluator;
import com.google.devtools.build.lib.pkgcache.TransitivePackageLoader;
import com.google.devtools.build.lib.profiler.AutoProfiler;
import com.google.devtools.build.lib.query2.engine.Callback;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment;
import com.google.devtools.build.lib.query2.engine.QueryEvalResult;
import com.google.devtools.build.lib.query2.engine.QueryException;
import com.google.devtools.build.lib.query2.engine.QueryExpression;
import com.google.devtools.build.lib.query2.engine.QueryUtil;
import com.google.devtools.build.lib.util.BinaryPredicate;
import com.google.devtools.build.skyframe.WalkableGraph.WalkableGraphFactory;

Expand All @@ -46,7 +45,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -138,11 +136,10 @@ public static AbstractBlazeQueryEnvironment<Target> newQueryEnvironment(
* @throws QueryException if the evaluation failed and {@code --nokeep_going} was in
* effect
*/
public QueryEvalResult evaluateQuery(QueryExpression expr, final Callback<T> callback)
public QueryEvalResult<T> evaluateQuery(QueryExpression expr)
throws QueryException, InterruptedException {

final AtomicBoolean empty = new AtomicBoolean(true);
try (final AutoProfiler p = AutoProfiler.logged("evaluating query", LOG)) {
Set<T> resultNodes;
try (AutoProfiler p = AutoProfiler.logged("evaluating query", LOG)) {
resolvedTargetPatterns.clear();

// In the --nokeep_going case, errors are reported in the order in which the patterns are
Expand All @@ -155,15 +152,9 @@ public QueryEvalResult evaluateQuery(QueryExpression expr, final Callback<T> cal
// Unfortunately, by evaluating the patterns in parallel, we lose some location information.
throw new QueryException(expr, e.getMessage());
}

try {
this.eval(expr, new Callback<T>() {
@Override
public void process(Iterable<T> partialResult)
throws QueryException, InterruptedException {
empty.compareAndSet(true, Iterables.isEmpty(partialResult));
callback.process(partialResult);
}
});
resultNodes = QueryUtil.evalAll(this, expr);
} catch (QueryException e) {
throw new QueryException(e, expr);
}
Expand All @@ -181,12 +172,12 @@ public void process(Iterable<T> partialResult)
}
}

return new QueryEvalResult(!eventHandler.hasErrors(), empty.get());
return new QueryEvalResult<>(!eventHandler.hasErrors(), resultNodes);
}

public QueryEvalResult evaluateQuery(String query, Callback<T> callback)
public QueryEvalResult<T> evaluateQuery(String query)
throws QueryException, InterruptedException {
return evaluateQuery(QueryExpression.parse(query, this), callback);
return evaluateQuery(QueryExpression.parse(query, this));
}

@Override
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/query2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ java_library(
srcs = glob(["engine/*.java"]),
deps = [
"//src/main/java/com/google/devtools/build/lib:common",
"//src/main/java/com/google/devtools/build/lib:concurrent",
"//src/main/java/com/google/devtools/build/lib:graph",
"//src/main/java/com/google/devtools/build/lib:util",
"//third_party:jsr305",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import com.google.devtools.build.lib.pkgcache.TargetPatternEvaluator;
import com.google.devtools.build.lib.pkgcache.TargetProvider;
import com.google.devtools.build.lib.pkgcache.TransitivePackageLoader;
import com.google.devtools.build.lib.query2.engine.BlazeQueryEvalResult;
import com.google.devtools.build.lib.query2.engine.Callback;
import com.google.devtools.build.lib.query2.engine.DigraphQueryEvalResult;
import com.google.devtools.build.lib.query2.engine.QueryEvalResult;
import com.google.devtools.build.lib.query2.engine.QueryException;
import com.google.devtools.build.lib.query2.engine.QueryExpression;
Expand All @@ -54,7 +54,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* The environment of a Blaze query. Not thread-safe.
Expand Down Expand Up @@ -103,22 +102,15 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}

@Override
public DigraphQueryEvalResult<Target> evaluateQuery(QueryExpression expr,
final Callback<Target> callback) throws QueryException, InterruptedException {
public BlazeQueryEvalResult<Target> evaluateQuery(QueryExpression expr)
throws QueryException, InterruptedException {
// 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();
final AtomicBoolean empty = new AtomicBoolean(true);
QueryEvalResult queryEvalResult = super.evaluateQuery(expr, new Callback<Target>() {
@Override
public void process(Iterable<Target> partialResult)
throws QueryException, InterruptedException {
empty.compareAndSet(true, Iterables.isEmpty(partialResult));
callback.process(partialResult);
}
});
return new DigraphQueryEvalResult<>(queryEvalResult.getSuccess(), empty.get(), graph);
QueryEvalResult<Target> queryEvalResult = super.evaluateQuery(expr);
return new BlazeQueryEvalResult<>(queryEvalResult.getSuccess(), queryEvalResult.getResultSet(),
graph);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ private void init() throws InterruptedException {
}

@Override
public QueryEvalResult evaluateQuery(QueryExpression expr, Callback<Target> callback)
public QueryEvalResult<Target> evaluateQuery(QueryExpression expr)
throws QueryException, InterruptedException {
// 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();
init();
return super.evaluateQuery(expr, callback);
return super.evaluateQuery(expr);
}

private Map<Target, Collection<Target>> makeTargetsMap(Map<SkyKey, Iterable<SkyKey>> input) {
Expand Down Expand Up @@ -376,7 +376,7 @@ private static void addIfUniqueLabel(Target node, Set<Label> labels, Set<Target>
}
}

private static Target getSubincludeTarget(Label label, Package pkg) {
private static Target getSubincludeTarget(final Label label, Package pkg) {
return new FakeSubincludeTarget(label, pkg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.graph.Digraph;

import java.util.Set;

/** {@link QueryEvalResult} along with a digraph giving the structure of the results. */
public class DigraphQueryEvalResult<T> extends QueryEvalResult {
public class BlazeQueryEvalResult<T> extends QueryEvalResult<T> {

private final Digraph<T> graph;

public DigraphQueryEvalResult(boolean success, boolean isEmpty, Digraph<T> graph) {
super(success, isEmpty);
public BlazeQueryEvalResult(boolean success, Set<T> resultSet, Digraph<T> graph) {
super(success, resultSet);
this.graph = Preconditions.checkNotNull(graph);
}

/** Returns the recorded graph */
public Digraph<T> getGraph() {
return graph;
/** Returns the result as a directed graph over elements. */
public Digraph<T> getResultGraph() {
return graph.extractSubgraph(resultSet);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@

package com.google.devtools.build.lib.query2.engine;

import com.google.common.base.Preconditions;

import java.util.Set;

/**
* Information about the query evaluation, like if it was successful and number of elements
* returned.
* The result of a query evaluation, containing a set of elements.
*
* @param <T> the node type of the elements.
*/
public class QueryEvalResult {
public class QueryEvalResult<T> {

private final boolean success;
private final boolean empty;
protected final boolean success;
protected final Set<T> resultSet;

public QueryEvalResult(boolean success, boolean empty) {
public QueryEvalResult(
boolean success, Set<T> resultSet) {
this.success = success;
this.empty = empty;
this.resultSet = Preconditions.checkNotNull(resultSet);
}

/**
Expand All @@ -36,13 +42,16 @@ public boolean getSuccess() {
return success;
}

/** True if the query did not return any result; */
public boolean isEmpty() {
return empty;
/**
* Returns the result as a set of targets.
*/
public Set<T> getResultSet() {
return resultSet;
}

@Override
public String toString() {
return (getSuccess() ? "Successful" : "Unsuccessful") + ", empty = " + empty;
return (getSuccess() ? "Successful" : "Unsuccessful") + ", result size = "
+ getResultSet().size() + ", " + getResultSet();
}
}
Loading

0 comments on commit 016b4b6

Please sign in to comment.