Search in sources :

Example 11 with DefaultProcessExecutor

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();
}
Also used : VersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.VersionControlCmdLineInterfaceFactory) DefaultVersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.DefaultVersionControlCmdLineInterfaceFactory) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) WatchmanDiagReportCollector(com.facebook.buck.rage.WatchmanDiagReportCollector) RageConfig(com.facebook.buck.rage.RageConfig) DefaultVersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.DefaultVersionControlCmdLineInterfaceFactory) VersionControlBuckConfig(com.facebook.buck.util.versioncontrol.VersionControlBuckConfig) DefaultDefectReporter(com.facebook.buck.rage.DefaultDefectReporter) PrintStreamProcessExecutorFactory(com.facebook.buck.util.PrintStreamProcessExecutorFactory) DefaultExtraInfoCollector(com.facebook.buck.rage.DefaultExtraInfoCollector) DoctorInteractiveReport(com.facebook.buck.rage.DoctorInteractiveReport)

Example 12 with DefaultProcessExecutor

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);
}
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 13 with DefaultProcessExecutor

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();
}
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 14 with DefaultProcessExecutor

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);
}
Also used : DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig)

Example 15 with DefaultProcessExecutor

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);
}
Also used : DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) NoSuchFileException(java.nio.file.NoSuchFileException) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole)

Aggregations

DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)37 TestConsole (com.facebook.buck.testutil.TestConsole)27 Test (org.junit.Test)21 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)20 Path (java.nio.file.Path)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)7 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)5 NSDictionary (com.dd.plist.NSDictionary)3 NSString (com.dd.plist.NSString)3 SymbolGetter (com.facebook.buck.android.AndroidNdkHelper.SymbolGetter)3 BuckConfig (com.facebook.buck.cli.BuckConfig)3 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 HumanReadableException (com.facebook.buck.util.HumanReadableException)3