Search in sources :

Example 16 with ProcessExecutorParams

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();
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor)

Example 17 with ProcessExecutorParams

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;
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) SimpleProcessListener(com.facebook.buck.util.SimpleProcessListener) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) IOException(java.io.IOException)

Example 18 with ProcessExecutorParams

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);
        }
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) SimpleProcessListener(com.facebook.buck.util.SimpleProcessListener) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) IOException(java.io.IOException)

Example 19 with ProcessExecutorParams

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));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 20 with ProcessExecutorParams

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());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Optional(java.util.Optional) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Aggregations

ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)72 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)32 FakeProcess (com.facebook.buck.util.FakeProcess)30 Test (org.junit.Test)30 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)21 ExecutionContext (com.facebook.buck.step.ExecutionContext)19 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)19 IOException (java.io.IOException)18 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)12 TestConsole (com.facebook.buck.testutil.TestConsole)12 Path (java.nio.file.Path)11 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)8 ListeningProcessExecutor (com.facebook.buck.util.ListeningProcessExecutor)6 HumanReadableException (com.facebook.buck.util.HumanReadableException)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Matcher (java.util.regex.Matcher)4