use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class OcamlRuleBuilder method executeProcessAndGetStdout.
private static Optional<String> executeProcessAndGetStdout(Path baseDir, ImmutableList<String> cmd) throws IOException, InterruptedException {
ImmutableSet.Builder<ProcessExecutor.Option> options = ImmutableSet.builder();
options.add(ProcessExecutor.Option.EXPECTING_STD_OUT);
ProcessExecutor exe = new DefaultProcessExecutor(Console.createNullConsole());
ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(cmd).setDirectory(baseDir).build();
ProcessExecutor.Result result = exe.launchAndExecute(params, options.build(), /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
if (result.getExitCode() != 0) {
throw new HumanReadableException(result.getStderr().get());
}
return result.getStdout();
}
use of com.facebook.buck.util.ProcessExecutorParams 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.ProcessExecutorParams 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);
}
}
}
use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class CodeSignIdentityStoreTest method testInvalidIdentitiesAreIgnored.
@Test
public void testInvalidIdentitiesAreIgnored() throws Exception {
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addCommand("unused").build();
FakeProcess process = new FakeProcess(0, " 1) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " + "\"iPhone Developer: Foo Bar (ABCDE12345)\" (CSSMERR_TP_CERT_REVOKED)\n" + " 2) AAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBB " + "\"iPhone Developer: Foo Bar (12345ABCDE)\" (CSSMERR_TP_CERT_EXPIRED)\n" + " 3) BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB " + "\"iPhone Developer: Foo Bar (54321EDCBA)\"\n" + " 3 valid identities found\n", "");
FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(processExecutorParams, process));
CodeSignIdentityStore store = CodeSignIdentityStore.fromSystem(processExecutor, ImmutableList.of("unused"));
ImmutableList<CodeSignIdentity> expected = ImmutableList.of(CodeSignIdentity.builder().setFingerprint(CodeSignIdentity.toFingerprint("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")).setSubjectCommonName("iPhone Developer: Foo Bar (54321EDCBA)").build());
assertThat(store.getIdentities(), equalTo(expected));
}
use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class AppleConfigTest method getXcodeSelectDetectedAppleDeveloperDirectorySupplier.
@Test
public void getXcodeSelectDetectedAppleDeveloperDirectorySupplier() {
BuckConfig buckConfig = FakeBuckConfig.builder().build();
AppleConfig config = new AppleConfig(buckConfig);
ProcessExecutorParams xcodeSelectParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("xcode-select", "--print-path")).build();
FakeProcess fakeXcodeSelect = new FakeProcess(0, "/path/to/another/place", "");
FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xcodeSelectParams, fakeXcodeSelect));
Supplier<Optional<Path>> supplier = config.getAppleDeveloperDirectorySupplier(processExecutor);
assertNotNull(supplier);
assertEquals(Optional.of(Paths.get("/path/to/another/place")), supplier.get());
}
Aggregations