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 19ca306
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@
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;
import java.util.concurrent.Future;
import javax.annotation.Nullable;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.ide.PooledThreadExecutor;

/**
Expand Down Expand Up @@ -185,10 +191,11 @@ private static ImmutableList<TargetInfo> runRecursiveRdepsQuery(
@Nullable
private static ImmutableList<TargetInfo> getTargetInfoList(
Project project, BlazeContext context, ContextType type, String rdepsQuery)
throws BlazeQuerySourceToTargetException {
throws BlazeQuerySourceToTargetException {
Path queryFile = prepareQueryFile(project, rdepsQuery);
BlazeCommand.Builder command =
getBlazeCommandBuilder(
project, type, rdepsQuery, ImmutableList.of("--output=label_kind"), context);
project, type, "--query_file=" + queryFile.toAbsolutePath(), ImmutableList.of("--output=label_kind"), context);
try (InputStream queryResultStream = runQuery(project, command, context)) {
BlazeQueryLabelKindParser blazeQueryLabelKindParser =
new BlazeQueryLabelKindParser(t -> true);
Expand All @@ -201,7 +208,24 @@ private static ImmutableList<TargetInfo> getTargetInfoList(
return blazeQueryLabelKindParser.getTargets();
} catch (IOException e) {
throw new BlazeQuerySourceToTargetException("Failed to get target info list", e);
} finally {
queryFile.toFile().delete();
}
}

private static @NotNull Path prepareQueryFile(Project project, String rdepsQuery) throws BlazeQuerySourceToTargetException {
Path queryFile = null;
try {
queryFile = Files.createTempFile(Paths.get(project.getBasePath()), "query-", "");
Files.writeString(queryFile, rdepsQuery, StandardOpenOption.WRITE);

} catch (IOException e) {
if (queryFile != null) {
queryFile.toFile().delete();
}
throw new BlazeQuerySourceToTargetException("Couldn't create query file", e);
}
return queryFile;
}

@Nullable
Expand Down

0 comments on commit 19ca306

Please sign in to comment.