use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class AppleSimulatorDiscovery method discoverAppleSimulators.
/**
* Discovers information about Apple simulators installed on the system.
*/
public static ImmutableSet<AppleSimulator> discoverAppleSimulators(ProcessExecutor processExecutor, Path simctlPath) throws InterruptedException, IOException {
LOG.debug("Running xcrun simctl list to get list of simulators");
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of(simctlPath.toString(), "list")).build();
ProcessExecutor.LaunchedProcess simctlListProcess = processExecutor.launchProcess(processExecutorParams);
ImmutableSet.Builder<AppleSimulator> simulatorsBuilder = ImmutableSet.builder();
try (InputStreamReader stdoutReader = new InputStreamReader(simctlListProcess.getInputStream(), StandardCharsets.UTF_8)) {
LOG.debug("Parsing output of xcrun simctl list...");
SimctlListOutputParsing.parseOutputFromReader(stdoutReader, simulatorsBuilder);
}
ProcessExecutor.Result result = processExecutor.waitForLaunchedProcess(simctlListProcess);
if (result.getExitCode() != 0) {
throw new IOException(result.getMessageForUnexpectedResult("simctl list"));
}
ImmutableSet<AppleSimulator> simulators = simulatorsBuilder.build();
LOG.debug("Discovered simulators: %s", simulators);
return simulators;
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class AbstractTestStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
// Build the process, redirecting output to the provided output file. In general,
// it's undesirable that both stdout and stderr are being redirected to the same
// input stream. However, due to the nature of OS pipe buffering, we can't really
// maintain the natural interleaving of multiple output streams in a way that we
// can correctly associate both stdout/stderr streams to the one correct test out
// of the many that ran. So, our best bet is to just combine them all into stdout,
// so they get properly interleaved with the test start and end messages that we
// use when we parse the test output.
Map<String, String> environment = new HashMap<>(System.getenv());
if (env.isPresent()) {
environment.putAll(env.get());
}
ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(command).setDirectory(workingDirectory.map(filesystem::resolve)).setEnvironment(ImmutableMap.copyOf(environment)).setRedirectOutput(ProcessBuilder.Redirect.to(filesystem.resolve(output).toFile())).setRedirectErrorStream(true).build();
ProcessExecutor.Result result;
try {
// Run the test process, saving the exit code.
ProcessExecutor executor = context.getProcessExecutor();
ImmutableSet<ProcessExecutor.Option> options = ImmutableSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
result = executor.launchAndExecute(params, options, /* stdin */
Optional.empty(), testRuleTimeoutMs, /* timeOutHandler */
Optional.empty());
} catch (IOException e) {
context.logError(e, "Error starting command %s", command);
return StepExecutionResult.ERROR;
}
if (result.isTimedOut()) {
throw new HumanReadableException("Timed out after %d ms running test command %s", testRuleTimeoutMs.orElse(-1L), command);
}
// to a file rather than signalling a step failure.
try (FileOutputStream fileOut = new FileOutputStream(filesystem.resolve(exitCode).toFile());
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut)) {
objectOut.writeInt(result.getExitCode());
} catch (IOException e) {
context.logError(e, "Error saving exit code to %s", exitCode);
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class ShellStep method launchAndInteractWithProcess.
@VisibleForTesting
int launchAndInteractWithProcess(ExecutionContext context, ProcessExecutorParams params) throws InterruptedException, IOException {
ImmutableSet.Builder<Option> options = ImmutableSet.builder();
addOptions(context, options);
ProcessExecutor executor = context.getProcessExecutor();
ProcessExecutor.Result result = executor.launchAndExecute(params, options.build(), getStdin(context), getTimeout(), getTimeoutHandler(context));
stdout = result.getStdout();
stderr = result.getStderr();
Verbosity verbosity = context.getVerbosity();
if (stdout.isPresent() && !stdout.get().isEmpty() && (result.getExitCode() != 0 || shouldPrintStdout(verbosity))) {
context.postEvent(ConsoleEvent.info("%s", stdout.get()));
}
if (stderr.isPresent() && !stderr.get().isEmpty() && (result.getExitCode() != 0 || shouldPrintStderr(verbosity))) {
context.postEvent(ConsoleEvent.warning("%s", stderr.get()));
}
return getExitCodeFromResult(context, result);
}
Aggregations