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