Search in sources :

Example 11 with ProcessExecutorParams

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

the class GroovycStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
    try {
        ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(createCommand()).setEnvironment(context.getEnvironment()).setDirectory(filesystem.getRootPath().toAbsolutePath()).build();
        writePathToSourcesList(sourceFilePaths);
        ProcessExecutor processExecutor = context.getProcessExecutor();
        return StepExecutionResult.of(processExecutor.launchAndExecute(params));
    } catch (IOException e) {
        e.printStackTrace(context.getStdErr());
        return StepExecutionResult.of(-1);
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 12 with ProcessExecutorParams

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

the class WorkerProcessPoolFactory method createWorkerProcessPool.

private WorkerProcessPool createWorkerProcessPool(final ExecutionContext context, final WorkerJobParams paramsToUse, ConcurrentMap<String, WorkerProcessPool> processPoolMap, String key, final HashCode workerHash) {
    final ProcessExecutorParams processParams = ProcessExecutorParams.builder().setCommand(getCommand(context.getPlatform(), paramsToUse)).setEnvironment(getEnvironmentForProcess(context, paramsToUse)).setDirectory(filesystem.getRootPath()).build();
    final Path workerTmpDir = paramsToUse.getTempDir();
    final AtomicInteger workerNumber = new AtomicInteger(0);
    WorkerProcessPool newPool = new WorkerProcessPool(paramsToUse.getMaxWorkers(), workerHash) {

        @Override
        protected WorkerProcess startWorkerProcess() throws IOException {
            Path tmpDir = workerTmpDir.resolve(Integer.toString(workerNumber.getAndIncrement()));
            filesystem.mkdirs(tmpDir);
            WorkerProcess process = createWorkerProcess(processParams, context, tmpDir);
            process.ensureLaunchAndHandshake();
            return process;
        }
    };
    WorkerProcessPool previousPool = processPoolMap.putIfAbsent(key, newPool);
    // should ignore newPool and return the existing one.
    return previousPool == null ? newPool : previousPool;
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 13 with ProcessExecutorParams

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

the class AppleConfig method getXcodeBuildVersionSupplier.

/**
   * For some inscrutable reason, the Xcode build number isn't in the toolchain's plist
   * (or in any .plist under Developer/)
   *
   * We have to run `Developer/usr/bin/xcodebuild -version` to get it.
   */
public Supplier<Optional<String>> getXcodeBuildVersionSupplier(final Path developerPath, final ProcessExecutor processExecutor) {
    Supplier<Optional<String>> supplier = xcodeVersionCache.get(developerPath);
    if (supplier != null) {
        return supplier;
    }
    supplier = Suppliers.memoize(new Supplier<Optional<String>>() {

        @Override
        public Optional<String> get() {
            ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of(developerPath.resolve("usr/bin/xcodebuild").toString(), "-version")).build();
            // Specify that stdout is expected, or else output may be wrapped in Ansi escape chars.
            Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
            ProcessExecutor.Result result;
            try {
                result = processExecutor.launchAndExecute(processExecutorParams, options, /* stdin */
                Optional.empty(), /* timeOutMs */
                Optional.empty(), /* timeOutHandler */
                Optional.empty());
            } catch (InterruptedException | IOException e) {
                LOG.warn("Could not execute xcodebuild to find Xcode build number.");
                return Optional.empty();
            }
            if (result.getExitCode() != 0) {
                throw new RuntimeException(result.getMessageForUnexpectedResult("xcodebuild -version"));
            }
            Matcher matcher = XCODE_BUILD_NUMBER_PATTERN.matcher(result.getStdout().get());
            if (matcher.find()) {
                String xcodeBuildNumber = matcher.group(1);
                return Optional.of(xcodeBuildNumber);
            } else {
                LOG.warn("Xcode build number not found.");
                return Optional.empty();
            }
        }
    });
    xcodeVersionCache.put(developerPath, supplier);
    return supplier;
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) Optional(java.util.Optional) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Supplier(com.google.common.base.Supplier)

Example 14 with ProcessExecutorParams

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

the class CxxToolProvider method getTypeFromPath.

private static Type getTypeFromPath(Path path) {
    ProcessExecutorParams params = ProcessExecutorParams.builder().addCommand(path.toString()).addCommand("--version").build();
    ProcessExecutor.Result result;
    try {
        ProcessExecutor processExecutor = new DefaultProcessExecutor(Console.createNullConsole());
        result = processExecutor.launchAndExecute(params, EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT), Optional.empty(), Optional.empty(), Optional.empty());
    } catch (InterruptedException | IOException e) {
        throw new RuntimeException(e);
    }
    if (result.getExitCode() != 0) {
        String commandString = params.getCommand().toString();
        String message = result.getMessageForUnexpectedResult(commandString);
        LOG.error(message);
        throw new RuntimeException(message);
    }
    String stdout = result.getStdout().orElse("");
    Iterable<String> lines = Splitter.on(CharMatcher.anyOf("\r\n")).split(stdout);
    LOG.debug("Output of %s: %s", params.getCommand(), lines);
    return getTypeFromVersionOutput(lines);
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor)

Example 15 with ProcessExecutorParams

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

the class PythonRunTestsStep method doExecute.

private StepExecutionResult doExecute(ExecutionContext context) throws IOException, InterruptedException {
    if (testSelectorList.isEmpty()) {
        return getShellStepWithArgs("-o", resultsOutputPath.toString()).execute(context);
    }
    ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(ImmutableList.<String>builder().addAll(commandPrefix).add("-l", "-L", "buck").build()).setDirectory(workingDirectory).setEnvironment(environment).build();
    ProcessExecutor.Result result = context.getProcessExecutor().launchAndExecute(params, EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT), Optional.empty(), testRuleTimeoutMs, Optional.of(timeoutHandler));
    if (timedOut) {
        return StepExecutionResult.ERROR;
    } else if (result.getExitCode() != 0) {
        return StepExecutionResult.of(result);
    }
    Preconditions.checkState(result.getStdout().isPresent());
    String testsToRunRegex = getTestsToRunRegexFromListOutput(result.getStdout().get());
    return getShellStepWithArgs("--hide-output", "-o", resultsOutputPath.toString(), "-r", testsToRunRegex).execute(context);
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

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