Search in sources :

Example 1 with ProcessExecutor

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

the class CodeSigning method hasValidSignature.

/**
   * Checks whether a binary or bundle already has a valid code signature.
   *
   * @param path Resolved path to the binary or bundle.
   * @return Whether the binary or bundle has a valid code signature.
   */
public static boolean hasValidSignature(ProcessExecutor processExecutor, Path path) throws InterruptedException, IOException {
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("codesign", "--verify", "-v", path.toString())).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.Option.IS_SILENT);
    ProcessExecutor.Result result = processExecutor.launchAndExecute(processExecutorParams, options, /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    return result.getExitCode() == 0 && result.getStderr().isPresent() && result.getStderr().get().contains(": satisfies its Designated Requirement");
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 2 with ProcessExecutor

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

the class RageCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    ProjectFilesystem filesystem = params.getCell().getFilesystem();
    BuckConfig buckConfig = params.getBuckConfig();
    RageConfig rageConfig = RageConfig.of(buckConfig);
    ProcessExecutor processExecutor = new DefaultProcessExecutor(params.getConsole());
    VersionControlCmdLineInterfaceFactory vcsFactory = new DefaultVersionControlCmdLineInterfaceFactory(params.getCell().getFilesystem().getRootPath(), new PrintStreamProcessExecutorFactory(), new VersionControlBuckConfig(buckConfig), buckConfig.getEnvironment());
    Optional<VcsInfoCollector> vcsInfoCollector = VcsInfoCollector.create(vcsFactory.createCmdLineInterface());
    ExtraInfoCollector extraInfoCollector = new DefaultExtraInfoCollector(rageConfig, filesystem, processExecutor);
    Optional<WatchmanDiagReportCollector> watchmanDiagReportCollector = WatchmanDiagReportCollector.newInstanceIfWatchmanUsed(params.getCell(), filesystem, processExecutor, new ExecutableFinder(), params.getEnvironment());
    AbstractReport report;
    DefaultDefectReporter reporter = new DefaultDefectReporter(filesystem, params.getObjectMapper(), rageConfig, params.getBuckEventBus(), params.getClock());
    if (params.getConsole().getAnsi().isAnsiTerminal() && !nonInteractive) {
        report = new InteractiveReport(reporter, filesystem, params.getObjectMapper(), params.getConsole(), params.getStdIn(), params.getBuildEnvironmentDescription(), vcsInfoCollector, rageConfig, extraInfoCollector, watchmanDiagReportCollector);
    } else {
        report = new AutomatedReport(reporter, filesystem, params.getObjectMapper(), params.getConsole(), params.getBuildEnvironmentDescription(), gatherVcsInfo ? vcsInfoCollector : Optional.empty(), rageConfig, extraInfoCollector);
    }
    Optional<DefectSubmitResult> defectSubmitResult = report.collectAndSubmitResult();
    report.presentDefectSubmitResult(defectSubmitResult, showJson);
    return 0;
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) VcsInfoCollector(com.facebook.buck.rage.VcsInfoCollector) AutomatedReport(com.facebook.buck.rage.AutomatedReport) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) DefaultExtraInfoCollector(com.facebook.buck.rage.DefaultExtraInfoCollector) ExtraInfoCollector(com.facebook.buck.rage.ExtraInfoCollector) RageConfig(com.facebook.buck.rage.RageConfig) DefaultVersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.DefaultVersionControlCmdLineInterfaceFactory) VersionControlBuckConfig(com.facebook.buck.util.versioncontrol.VersionControlBuckConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) DefaultVersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.DefaultVersionControlCmdLineInterfaceFactory) VersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.VersionControlCmdLineInterfaceFactory) DefectSubmitResult(com.facebook.buck.rage.DefectSubmitResult) VersionControlBuckConfig(com.facebook.buck.util.versioncontrol.VersionControlBuckConfig) WatchmanDiagReportCollector(com.facebook.buck.rage.WatchmanDiagReportCollector) AbstractReport(com.facebook.buck.rage.AbstractReport) InteractiveReport(com.facebook.buck.rage.InteractiveReport) DefaultDefectReporter(com.facebook.buck.rage.DefaultDefectReporter) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) PrintStreamProcessExecutorFactory(com.facebook.buck.util.PrintStreamProcessExecutorFactory) DefaultExtraInfoCollector(com.facebook.buck.rage.DefaultExtraInfoCollector)

Example 3 with ProcessExecutor

use of com.facebook.buck.util.ProcessExecutor 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 4 with ProcessExecutor

use of com.facebook.buck.util.ProcessExecutor 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 5 with ProcessExecutor

use of com.facebook.buck.util.ProcessExecutor 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)

Aggregations

ProcessExecutor (com.facebook.buck.util.ProcessExecutor)38 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)20 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)18 TestConsole (com.facebook.buck.testutil.TestConsole)13 IOException (java.io.IOException)13 Path (java.nio.file.Path)12 Test (org.junit.Test)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4 Verbosity (com.facebook.buck.util.Verbosity)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)3 BuckConfig (com.facebook.buck.cli.BuckConfig)3 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStreamReader (java.io.InputStreamReader)3 PrintStream (java.io.PrintStream)3 NSDate (com.dd.plist.NSDate)2