use of com.facebook.buck.util.SimpleProcessListener in project buck by facebook.
the class SwiftStdlibStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
ListeningProcessExecutor executor = new ListeningProcessExecutor();
ProcessExecutorParams params = makeProcessExecutorParams();
SimpleProcessListener listener = new SimpleProcessListener();
// TODO(ryu2): parse output as needed
try {
LOG.debug("%s", command);
ListeningProcessExecutor.LaunchedProcess process = executor.launchProcess(params, listener);
int result = executor.waitForProcess(process);
if (result != 0) {
LOG.error("Error running %s: %s", getDescription(context), listener.getStderr());
return StepExecutionResult.of(result);
}
} catch (IOException e) {
LOG.error(e, "Could not execute command %s", command);
return StepExecutionResult.ERROR;
}
// Copy from temp to destinationDirectory if we wrote files.
if (Files.notExists(temp)) {
return StepExecutionResult.SUCCESS;
}
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(temp)) {
if (dirStream.iterator().hasNext()) {
Files.createDirectories(destinationDirectory);
MoreFiles.copyRecursively(temp, destinationDirectory);
}
} catch (IOException e) {
LOG.error(e, "Could not copy to %s", destinationDirectory);
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.util.SimpleProcessListener in project buck by facebook.
the class SwiftCompileStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
ListeningProcessExecutor executor = new ListeningProcessExecutor();
ProcessExecutorParams params = makeProcessExecutorParams();
SimpleProcessListener listener = new SimpleProcessListener();
// TODO(ryu2): parse the output, print build failure errors, etc.
try {
LOG.debug("%s", compilerCommand);
ListeningProcessExecutor.LaunchedProcess process = executor.launchProcess(params, listener);
int result = executor.waitForProcess(process);
if (result != 0) {
LOG.error("Error running %s: %s", getDescription(context), listener.getStderr());
}
return StepExecutionResult.of(result);
} catch (IOException e) {
LOG.error(e, "Could not execute command %s", compilerCommand);
return StepExecutionResult.ERROR;
}
}
use of com.facebook.buck.util.SimpleProcessListener in project buck by facebook.
the class MacNetworkConfiguration method runNetworkSetupCommand.
/**
* Naive `networksetup` invocation; returns non-empty string of stdout if all went well.
*/
private static String runNetworkSetupCommand(String subCommand, String argument) throws InterruptedException {
ListeningProcessExecutor executor = new ListeningProcessExecutor();
SimpleProcessListener listener = new SimpleProcessListener();
ProcessExecutorParams params = ProcessExecutorParams.builder().addCommand("networksetup").addCommand(String.format("-%s", subCommand)).addCommand(argument).build();
ListeningProcessExecutor.LaunchedProcess process = null;
try {
process = executor.launchProcess(params, listener);
if (executor.waitForProcess(process, COMMAND_TIMEOUT_MS, TimeUnit.MILLISECONDS) != 0) {
return "";
}
return listener.getStdout();
} catch (IOException e) {
LOG.debug(e, "Exception while running networksetup command");
return "";
} finally {
if (process != null) {
executor.destroyProcess(process, /* force */
true);
}
}
}
Aggregations