Skip to content

Commit

Permalink
CPP-22975: workaround for WSL1 issue "Output from WSL command pipelin…
Browse files Browse the repository at this point in the history
…e is randomly truncated"

microsoft/WSL#4082

GitOrigin-RevId: 1a69a2430f9bc9aa05ca6f493226ed7f9422d2ef
  • Loading branch information
Vasily Romanikhin authored and intellij-monorepo-bot committed May 6, 2021
1 parent 3729acd commit 1ab8f9e
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ public ProcessOutput copyFromWsl(@NotNull String wslPath,
public @NotNull <T extends GeneralCommandLine> T patchCommandLine(@NotNull T commandLine,
@Nullable Project project,
@NotNull WSLCommandLineOptions options) throws ExecutionException {
return patchCommandLine(commandLine, project, options, 0);
}

/**
* Works like {@link #patchCommandLine(GeneralCommandLine, Project, WSLCommandLineOptions)},
* but in addition it allows to workaround WSL1 problem
* <a href="https://github.com/microsoft/WSL/issues/4082">Output from WSL command pipeline is randomly truncated</a>
*/
public @NotNull <T extends GeneralCommandLine> T patchCommandLine(@NotNull T commandLine,
@Nullable Project project,
@NotNull WSLCommandLineOptions options,
double sleepTimeoutSec) throws ExecutionException {
logCommandLineBefore(commandLine, options);
Path executable = getExecutablePath();
boolean launchWithWslExe = options.isLaunchWithWslExe() || executable == null;
Expand Down Expand Up @@ -282,6 +294,9 @@ public void startNotified(@NotNull ProcessEvent event) {

commandLine.getParametersList().clearAll();
String linuxCommandStr = StringUtil.join(linuxCommand, " ");
if (sleepTimeoutSec > 0) {
linuxCommandStr += " && sleep " + sleepTimeoutSec;
}
if (wslExe != null) {
commandLine.setExePath(wslExe.toString());
commandLine.addParameters("--distribution", getMsId());
Expand Down Expand Up @@ -338,7 +353,7 @@ private void logCommandLineAfter(@NotNull GeneralCommandLine commandLine) {
return file != null ? file.toPath() : null;
}

public static @NotNull List<String> buildLinuxCommand(@NotNull GeneralCommandLine commandLine, boolean executeCommandInShell) {
private static @NotNull List<String> buildLinuxCommand(@NotNull GeneralCommandLine commandLine, boolean executeCommandInShell) {
List<String> command = ContainerUtil.concat(List.of(commandLine.getExePath()), commandLine.getParametersList().getList());
return new ArrayList<>(ContainerUtil.map(command, executeCommandInShell ? CommandLineUtil::posixQuote : Functions.identity()));
}
Expand Down

0 comments on commit 1ab8f9e

Please sign in to comment.