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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations