diff --git a/base/src/com/google/idea/blaze/base/dependencies/BlazeQuerySourceToTargetProvider.java b/base/src/com/google/idea/blaze/base/dependencies/BlazeQuerySourceToTargetProvider.java index c3193007e11..42a748a539b 100644 --- a/base/src/com/google/idea/blaze/base/dependencies/BlazeQuerySourceToTargetProvider.java +++ b/base/src/com/google/idea/blaze/base/dependencies/BlazeQuerySourceToTargetProvider.java @@ -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; /** @@ -185,10 +191,11 @@ private static ImmutableList runRecursiveRdepsQuery( @Nullable private static ImmutableList 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); @@ -201,7 +208,24 @@ private static ImmutableList 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