use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class ProjectCommand method runDeprecatedIntellijProjectGenerator.
private int runDeprecatedIntellijProjectGenerator(CommandRunnerParams params, TargetGraph projectGraph, TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet) throws IOException, InterruptedException {
// Create an ActionGraph that only contains targets that can be represented as IDE
// configuration files.
ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
try (ExecutionContext executionContext = createExecutionContext(params)) {
Project project = new Project(new SourcePathResolver(new SourcePathRuleFinder(result.getResolver())), FluentIterable.from(result.getActionGraph().getNodes()).filter(ProjectConfig.class).toSortedSet(Ordering.natural()), getBasePathToAliasMap(params.getBuckConfig()), getJavaPackageFinder(params.getBuckConfig()), executionContext, new FilesystemBackedBuildFileTree(params.getCell().getFilesystem(), params.getBuckConfig().getView(ParserConfig.class).getBuildFileName()), params.getCell().getFilesystem(), getPathToDefaultAndroidManifest(params.getBuckConfig()), new IntellijConfig(params.getBuckConfig()), getPathToPostProcessScript(params.getBuckConfig()), new PythonBuckConfig(params.getBuckConfig(), new ExecutableFinder()).getPythonInterpreter(), params.getObjectMapper(), isAndroidAutoGenerateDisabled(params.getBuckConfig()));
File tempDir = Files.createTempDir();
File tempFile = new File(tempDir, "project.json");
int exitCode;
try {
exitCode = project.createIntellijProject(tempFile, executionContext.getProcessExecutor(), !passedInTargetsSet.isEmpty(), params.getConsole().getStdOut(), params.getConsole().getStdErr());
if (exitCode != 0) {
return exitCode;
}
List<String> additionalInitialTargets = ImmutableList.of();
if (shouldProcessAnnotations()) {
additionalInitialTargets = getAnnotationProcessingTargets(projectGraph, passedInTargetsSet);
}
// Build initial targets.
if (hasInitialTargets(params.getBuckConfig()) || !additionalInitialTargets.isEmpty()) {
BuildCommand buildCommand = createBuildCommandOptionsWithInitialTargets(params.getBuckConfig(), additionalInitialTargets);
buildCommand.setArtifactCacheDisabled(true);
exitCode = buildCommand.runWithoutHelp(params);
if (exitCode != 0) {
return exitCode;
}
}
} finally {
// Either leave project.json around for debugging or delete it on exit.
if (params.getConsole().getVerbosity().shouldPrintOutput()) {
params.getConsole().getStdErr().printf("project.json was written to %s", tempFile.getAbsolutePath());
} else {
tempFile.delete();
tempDir.delete();
}
}
if (passedInTargetsSet.isEmpty()) {
String greenStar = params.getConsole().getAnsi().asHighlightedSuccessText(" * ");
params.getConsole().getStdErr().printf(params.getConsole().getAnsi().asHighlightedSuccessText("=== Did you know ===") + "\n" + greenStar + "You can run `buck project <target>` to generate a minimal project " + "just for that target.\n" + greenStar + "This will make your IDE faster when working on large projects.\n" + greenStar + "See buck project --help for more info.\n" + params.getConsole().getAnsi().asHighlightedSuccessText("--=* Knowing is half the battle!") + "\n");
}
return 0;
}
}
use of com.facebook.buck.io.ExecutableFinder 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.io.ExecutableFinder in project buck by facebook.
the class WorkspaceAndProjectGeneratorTest method buildWithBuck.
@Test
public void buildWithBuck() throws IOException, InterruptedException {
Optional<Path> buck = new ExecutableFinder().getOptionalExecutable(Paths.get("buck"), ImmutableMap.of());
assumeThat(buck.isPresent(), is(true));
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
true, /* buildWithBuck */
ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
assertThat(fooProjectGenerator, is(notNullValue()));
PBXTarget buildWithBuckTarget = null;
for (PBXTarget target : fooProjectGenerator.getGeneratedProject().getTargets()) {
if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
buildWithBuckTarget = target;
break;
}
}
assertThat(buildWithBuckTarget, is(notNullValue()));
assertThat(buildWithBuckTarget, is(instanceOf(PBXAggregateTarget.class)));
String gid = buildWithBuckTarget.getGlobalID();
Optional<XCScheme> scheme = Iterables.getOnlyElement(generator.getSchemeGenerators().values()).getOutputScheme();
assertThat(scheme.isPresent(), is(true));
XCScheme.BuildableReference buildWithBuckBuildableReference = null;
for (XCScheme.BuildActionEntry buildActionEntry : scheme.get().getBuildAction().get().getBuildActionEntries()) {
XCScheme.BuildableReference buildableReference = buildActionEntry.getBuildableReference();
if (buildableReference.getBlueprintIdentifier().equals(gid)) {
buildWithBuckBuildableReference = buildableReference;
}
}
assertThat(buildWithBuckBuildableReference, is(notNullValue()));
assertThat(buildWithBuckBuildableReference.getBuildableName(), equalTo("//foo:bin-Buck"));
}
use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class JUnitStep method getTimeoutHandler.
@Override
protected Optional<Consumer<Process>> getTimeoutHandler(final ExecutionContext context) {
return Optional.of(process -> {
Optional<Long> pid = Optional.empty();
Platform platform = context.getPlatform();
try {
switch(platform) {
case LINUX:
case FREEBSD:
case MACOS:
{
Field field = process.getClass().getDeclaredField("pid");
field.setAccessible(true);
try {
pid = Optional.of((long) field.getInt(process));
} catch (IllegalAccessException e) {
LOG.error(e, "Failed to access `pid`.");
}
break;
}
case WINDOWS:
{
Field field = process.getClass().getDeclaredField("handle");
field.setAccessible(true);
try {
pid = Optional.of(field.getLong(process));
} catch (IllegalAccessException e) {
LOG.error(e, "Failed to access `handle`.");
}
break;
}
case UNKNOWN:
LOG.info("Unknown platform; unable to obtain the process id!");
break;
}
} catch (NoSuchFieldException e) {
LOG.error(e);
}
Optional<Path> jstack = new ExecutableFinder(context.getPlatform()).getOptionalExecutable(Paths.get("jstack"), context.getEnvironment());
if (!pid.isPresent() || !jstack.isPresent()) {
LOG.info("Unable to print a stack trace for timed out test!");
return;
}
context.getStdErr().println("Test has timed out! Here is a trace of what it is currently doing:");
try {
context.getProcessExecutor().launchAndExecute(ProcessExecutorParams.builder().addCommand(jstack.get().toString(), "-l", pid.get().toString()).setEnvironment(context.getEnvironment()).build(), ImmutableSet.<ProcessExecutor.Option>builder().add(ProcessExecutor.Option.PRINT_STD_OUT).add(ProcessExecutor.Option.PRINT_STD_ERR).build(), Optional.empty(), Optional.of(TimeUnit.SECONDS.toMillis(30)), Optional.of(input -> {
context.getStdErr().print("Printing the stack took longer than 30 seconds. No longer trying.");
}));
} catch (Exception e) {
LOG.error(e);
}
});
}
use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class GroovyBuckConfig method getGroovyCompiler.
Supplier<Tool> getGroovyCompiler() {
Optional<Path> path = delegate.getPath("groovy", "groovy_home");
final Path groovyHomePath;
if (path.isPresent()) {
groovyHomePath = path.get();
} else {
String defaultGroovyHome = delegate.getEnvironment().get("GROOVY_HOME");
if (defaultGroovyHome == null) {
throw new HumanReadableException("Unable to locate groovy compiler:" + " GROOVY_HOME is not set, and groovy.groovy_home was not provided");
} else {
groovyHomePath = Paths.get(defaultGroovyHome);
}
}
Path compiler = new ExecutableFinder().getExecutable(groovyHomePath.resolve("bin/groovyc"), delegate.getEnvironment());
return Suppliers.ofInstance(new HashedFileTool(compiler));
}
Aggregations