Skip to content

Commit

Permalink
fix: Resolve query failure when there is a large number of files in t…
Browse files Browse the repository at this point in the history
…he Working Set

closes bazelbuild#6478
  • Loading branch information
Tomasz Pasternak committed Jun 28, 2024
1 parent 5cd93dc commit 6f42b3e
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -246,18 +250,30 @@ private static BlazeCommand.Builder getBlazeCommandBuilder(
List<String> additionalBlazeFlags,
BlazeContext context) {
// never use a custom output base for queries during sync
String outputBaseFlag =
type == ContextType.Sync
? null
: BlazeQueryOutputBaseProvider.getInstance(project).getOutputBaseFlag();
BuildInvoker buildInvoker =
Blaze.getBuildSystemProvider(project).getBuildSystem().getDefaultInvoker(project, context);
return BlazeCommand.builder(buildInvoker, BlazeCommandName.QUERY)
.addBlazeFlags(additionalBlazeFlags)
.addBlazeFlags("--keep_going")
.addBlazeFlags(query)
.addBlazeStartupFlags(
outputBaseFlag == null ? ImmutableList.of() : ImmutableList.of(outputBaseFlag));
Path queryFile = null;
try {
queryFile = Files.createTempFile(Paths.get(project.getBasePath()), "query-", "");
queryFile.toFile().deleteOnExit();
Files.writeString(queryFile, query, StandardOpenOption.WRITE);
String outputBaseFlag =
type == ContextType.Sync
? null
: BlazeQueryOutputBaseProvider.getInstance(project).getOutputBaseFlag();
BuildInvoker buildInvoker =
Blaze.getBuildSystemProvider(project).getBuildSystem().getDefaultInvoker(project, context);
return BlazeCommand.builder(buildInvoker, BlazeCommandName.QUERY)
.addBlazeFlags(additionalBlazeFlags)
.addBlazeFlags("--keep_going")
.addBlazeFlags("--query_file=" + queryFile.toAbsolutePath())
.addBlazeStartupFlags(
outputBaseFlag == null ? ImmutableList.of() : ImmutableList.of(outputBaseFlag));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (queryFile != null) {
queryFile.toFile().delete();
}
}
}

/**
Expand Down

0 comments on commit 6f42b3e

Please sign in to comment.