use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.
the class DoctorCommand method generateRageReport.
private Optional<DefectSubmitResult> generateRageReport(CommandRunnerParams params, UserInput userInput, BuildLogEntry entry) throws IOException, InterruptedException {
RageConfig rageConfig = RageConfig.of(params.getBuckConfig());
VersionControlCmdLineInterfaceFactory vcsFactory = new DefaultVersionControlCmdLineInterfaceFactory(params.getCell().getFilesystem().getRootPath(), new PrintStreamProcessExecutorFactory(), new VersionControlBuckConfig(params.getBuckConfig()), params.getBuckConfig().getEnvironment());
Optional<WatchmanDiagReportCollector> watchmanDiagReportCollector = WatchmanDiagReportCollector.newInstanceIfWatchmanUsed(params.getCell(), params.getCell().getFilesystem(), new DefaultProcessExecutor(params.getConsole()), new ExecutableFinder(), params.getEnvironment());
DoctorInteractiveReport report = new DoctorInteractiveReport(new DefaultDefectReporter(params.getCell().getFilesystem(), params.getObjectMapper(), rageConfig, params.getBuckEventBus(), params.getClock()), params.getCell().getFilesystem(), params.getConsole(), userInput, params.getBuildEnvironmentDescription(), VcsInfoCollector.create(vcsFactory.createCmdLineInterface()), rageConfig, new DefaultExtraInfoCollector(rageConfig, params.getCell().getFilesystem(), new DefaultProcessExecutor(params.getConsole())), ImmutableSet.of(entry), watchmanDiagReportCollector);
return report.collectAndSubmitResult();
}
use of com.facebook.buck.util.DefaultProcessExecutor 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.DefaultProcessExecutor 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.DefaultProcessExecutor in project buck by facebook.
the class GoAssumptions method assumeGoCompilerAvailable.
public static void assumeGoCompilerAvailable() throws InterruptedException, IOException {
Throwable exception = null;
try {
ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
FakeBuckConfig.Builder baseConfig = FakeBuckConfig.builder();
String goRoot = System.getenv("GOROOT");
if (goRoot != null) {
baseConfig.setSections("[go]", " root = " + goRoot);
// This should really act like some kind of readonly bind-mount onto the real filesystem.
// But this is currently enough to check whether Go seems to be installed, so we'll live...
FakeProjectFilesystem fs = new FakeProjectFilesystem();
fs.mkdirs(fs.getPath(goRoot));
baseConfig.setFilesystem(fs);
}
new GoBuckConfig(baseConfig.build(), executor, FlavorDomain.from("Cxx", ImmutableSet.of())).getCompiler();
} catch (HumanReadableException e) {
exception = e;
}
assumeNoException(exception);
}
use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.
the class ObjectPathsAbsolutifierIntegrationTest method checkCodeSignatureMatchesBetweenFiles.
private boolean checkCodeSignatureMatchesBetweenFiles(Path file1, Path file2) throws IOException, InterruptedException {
if (!Files.exists(file1)) {
throw new NoSuchFileException(file1.toString());
}
if (!Files.exists(file2)) {
throw new NoSuchFileException(file2.toString());
}
ProcessExecutor processExecutor = new DefaultProcessExecutor(new TestConsole());
ProcessExecutor.Result result1 = processExecutor.launchAndExecute(ProcessExecutorParams.builder().setCommand(ImmutableList.of("codesign", "-vvvv", "-d", file1.toString())).build(), EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT, ProcessExecutor.Option.IS_SILENT), /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
ProcessExecutor.Result result2 = processExecutor.launchAndExecute(ProcessExecutorParams.builder().setCommand(ImmutableList.of("codesign", "-vvvv", "-d", file1.toString())).build(), EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT, ProcessExecutor.Option.IS_SILENT), /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
String stderr1 = result1.getStderr().orElse("");
String stderr2 = result2.getStderr().orElse("");
// skip first line as it has a path to the binary
Assert.assertThat(stderr1, startsWith("Executable="));
Assert.assertThat(stderr2, startsWith("Executable="));
stderr1 = stderr1.substring(stderr1.indexOf("\n"));
stderr2 = stderr2.substring(stderr2.indexOf("\n"));
return stderr1.equals(stderr2);
}
Aggregations