Skip to content

Commit

Permalink
Extend SkyQueryEnvironment to pass query Callback to `#beforeEvaluate…
Browse files Browse the repository at this point in the history
…Query()`.

Subclasses of SkyQueryEnvironment can inspect the
`ThreadSafeOutputFormatterCallback` to optimize how they initialize query
evaluation.

PiperOrigin-RevId: 545756099
Change-Id: I05dd0fba4aa70e98fb07147548ff99371bf5db43
  • Loading branch information
michaeledgar authored and copybara-github committed Jul 5, 2023
1 parent df82dcd commit f5d8a45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ protected EvaluationContext newEvaluationContext() {
.build();
}

protected void beforeEvaluateQuery(QueryExpression expr)
protected void beforeEvaluateQuery(
QueryExpression expr, ThreadSafeOutputFormatterCallback<Target> callback)
throws QueryException, InterruptedException {
UniverseSkyKey universeKey = universeScope.getUniverseKey(expr, parserPrefix);
ImmutableList<String> universeScopeListToUse = universeKey.getPatterns();
Expand Down Expand Up @@ -295,10 +296,11 @@ protected void beforeEvaluateQuery(QueryExpression expr)
/* workQueue= */ new BlockingStack<>(),
new ThreadFactoryBuilder().setNameFormat("QueryEnvironment %d").build()));
}
resolver = makeNewTargetPatternResolver();
resolver = makeNewTargetPatternResolver(expr, callback);
}

protected TargetPatternResolver<Target> makeNewTargetPatternResolver() {
protected TargetPatternResolver<Target> makeNewTargetPatternResolver(
QueryExpression expr, ThreadSafeOutputFormatterCallback<Target> callback) {
return new RecursivePackageProviderBackedTargetPatternResolver(
graphBackedRecursivePackageProvider,
eventHandler,
Expand Down Expand Up @@ -458,7 +460,7 @@ protected void handleInterruptedShutdown() {}
public QueryEvalResult evaluateQuery(
QueryExpression expr, ThreadSafeOutputFormatterCallback<Target> callback)
throws QueryException, InterruptedException, IOException {
beforeEvaluateQuery(expr);
beforeEvaluateQuery(expr, callback);

// SkyQueryEnvironment batches callback invocations using a BatchStreamedCallback, created here
// so that there's one per top-level evaluateQuery call. The batch size is large enough that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum Result {
* If {@code getResult().equals(NO_SUCH_PACKAGE_EXCEPTION)}, returns the error message from the
* {@link com.google.devtools.build.lib.packages.NoSuchPackageException} encountered.
*/
abstract String getNoSuchPackageExceptionMessage();
public abstract String getNoSuchPackageExceptionMessage();

static PackageErrorMessageValue ofPackageWithNoErrors() {
return NO_ERROR_VALUE;
Expand Down Expand Up @@ -109,7 +109,7 @@ public Result getResult() {
}

@Override
String getNoSuchPackageExceptionMessage() {
public String getNoSuchPackageExceptionMessage() {
throw new IllegalStateException();
}
};
Expand All @@ -123,7 +123,7 @@ public Result getResult() {
}

@Override
String getNoSuchPackageExceptionMessage() {
public String getNoSuchPackageExceptionMessage() {
throw new IllegalStateException();
}
};
Expand All @@ -141,7 +141,7 @@ public Result getResult() {
}

@Override
String getNoSuchPackageExceptionMessage() {
public String getNoSuchPackageExceptionMessage() {
return errorMessage;
}

Expand Down

0 comments on commit f5d8a45

Please sign in to comment.