Search in sources :

Example 31 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class ExternalJavacTest method externalJavacWillHashTheExternalIfNoVersionInformationIsReturned.

@Test
public void externalJavacWillHashTheExternalIfNoVersionInformationIsReturned() throws IOException {
    Path javac = Files.createTempFile("fake", "javac");
    javac.toFile().deleteOnExit();
    ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
    FakeProcess javacProc = new FakeProcess(0, "", "");
    final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
    ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {

        @Override
        ProcessExecutor createProcessExecutor() {
            return executor;
        }
    };
    RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
    expect(sink.setReflectively("javac", javac.toString())).andReturn(sink);
    replay(sink);
    compiler.appendToRuleKey(sink);
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Test(org.junit.Test)

Example 32 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class ExternalJavacTest method externalJavacWillHashTheJavacVersionIfPresent.

@Test
public void externalJavacWillHashTheJavacVersionIfPresent() throws IOException {
    Path javac = Files.createTempFile("fake", "javac");
    javac.toFile().deleteOnExit();
    String reportedJavacVersion = "mozzarella";
    JavacVersion javacVersion = JavacVersion.of(reportedJavacVersion);
    ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
    FakeProcess javacProc = new FakeProcess(0, "", reportedJavacVersion);
    final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
    ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {

        @Override
        ProcessExecutor createProcessExecutor() {
            return executor;
        }
    };
    RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
    expect(sink.setReflectively("javac.version", javacVersion.toString())).andReturn(sink);
    replay(sink);
    compiler.appendToRuleKey(sink);
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Test(org.junit.Test)

Example 33 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class KnownBuildRuleTypesTest method addXcodeSelectProcess.

private static void addXcodeSelectProcess(Map<ProcessExecutorParams, FakeProcess> processMap, String xcodeSelectPath) {
    FakeProcess xcodeSelectOutputProcess = new FakeProcess(0, xcodeSelectPath, "");
    ProcessExecutorParams xcodeSelectParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("xcode-select", "--print-path")).build();
    processMap.put(xcodeSelectParams, xcodeSelectOutputProcess);
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcess(com.facebook.buck.util.FakeProcess)

Example 34 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class ShellStepTest method testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr.

@Test
public void testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr() throws Exception {
    ShellStep command = createCommand(/*shouldPrintStdErr*/
    false, /*shouldPrintStdOut*/
    false);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.STANDARD_INFORMATION);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 35 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class WorkerShellStepTest method testMultipleWorkerProcesses.

@Test
public void testMultipleWorkerProcesses() throws IOException, InterruptedException {
    String jobArgsA = "jobArgsA";
    String jobArgsB = "jobArgsB";
    final ImmutableMap<String, WorkerJobResult> jobResults = ImmutableMap.of(jobArgsA, WorkerJobResult.of(0, Optional.of("stdout A"), Optional.of("stderr A")), jobArgsB, WorkerJobResult.of(0, Optional.of("stdout B"), Optional.of("stderr B")));
    class WorkerShellStepWithFakeProcesses extends WorkerShellStep {

        WorkerShellStepWithFakeProcesses(WorkerJobParams jobParams) {
            super(Optional.ofNullable(jobParams), Optional.empty(), Optional.empty(), new WorkerProcessPoolFactory(new FakeProjectFilesystem()) {

                @Override
                WorkerProcess createWorkerProcess(ProcessExecutorParams processParams, ExecutionContext context, Path tmpDir) throws IOException {
                    try {
                        sleep(5);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    return new FakeWorkerProcess(jobResults);
                }
            });
        }
    }
    ExecutionContext context = TestExecutionContext.newBuilder().setPlatform(Platform.LINUX).setConsole(new TestConsole(Verbosity.ALL)).setBuckEventBus(BuckEventBusFactory.newInstance()).build();
    WorkerJobParams jobParamsA = createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), jobArgsA, 2);
    WorkerShellStep stepA = new WorkerShellStepWithFakeProcesses(jobParamsA);
    WorkerShellStep stepB = new WorkerShellStepWithFakeProcesses(jobParamsA.withJobArgs(jobArgsB));
    Thread[] threads = { new ConcurrentExecution(stepA, context), new ConcurrentExecution(stepB, context) };
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    Collection<WorkerProcessPool> pools = context.getWorkerProcessPools().values();
    assertThat(pools.size(), Matchers.equalTo(1));
    WorkerProcessPool pool = pools.iterator().next();
    assertThat(pool.getCapacity(), Matchers.equalTo(2));
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestConsole(com.facebook.buck.testutil.TestConsole) 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