use of com.facebook.buck.util.LineProcessorRunnable in project buck by facebook.
the class CxxPreprocessAndCompileStep method executeCompilation.
private int executeCompilation(ExecutionContext context) throws Exception {
ProcessExecutorParams.Builder builder = makeSubprocessBuilder(context, ImmutableMap.of());
if (useArgfile) {
filesystem.writeLinesToPath(Iterables.transform(getArguments(context.getAnsi().isAnsiTerminal()), Escaper.ARGFILE_ESCAPER), getArgfile());
builder.setCommand(ImmutableList.<String>builder().addAll(getCommandPrefix()).add("@" + getArgfile()).build());
} else {
builder.setCommand(ImmutableList.<String>builder().addAll(getCommandPrefix()).addAll(getArguments(context.getAnsi().isAnsiTerminal())).build());
}
ProcessExecutorParams params = builder.build();
LOG.debug("Running command (pwd=%s): %s", params.getDirectory(), getDescription(context));
// Start the process.
ProcessExecutor executor = new DefaultProcessExecutor(Console.createNullConsole());
ProcessExecutor.LaunchedProcess process = executor.launchProcess(params);
// We buffer error messages in memory, as these are typically small.
ByteArrayOutputStream error = new ByteArrayOutputStream();
// Fire up managed threads to process the stdout and stderr lines.
int exitCode;
try {
try (LineProcessorRunnable errorProcessor = createErrorTransformerFactory(context).createTransformerThread(context, compiler.getErrorStream(process), error)) {
errorProcessor.start();
errorProcessor.waitFor();
} catch (Throwable thrown) {
executor.destroyLaunchedProcess(process);
throw thrown;
}
exitCode = executor.waitForLaunchedProcess(process).getExitCode();
} finally {
executor.destroyLaunchedProcess(process);
executor.waitForLaunchedProcess(process);
}
// If we generated any error output, print that to the console.
String err = new String(error.toByteArray());
if (!err.isEmpty()) {
context.getBuckEventBus().post(createConsoleEvent(context, preprocessorCommand.map(Optional::of).orElse(compilerCommand).get().supportsColorsInDiagnostics(), exitCode == 0 ? Level.WARNING : Level.SEVERE, err));
}
return exitCode;
}
Aggregations