use of com.facebook.buck.rules.ActionGraphAndResolver 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.rules.ActionGraphAndResolver in project buck by facebook.
the class ProjectCommand method writeProjectAndGetRequiredBuildTargets.
private ImmutableSet<BuildTarget> writeProjectAndGetRequiredBuildTargets(CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets) throws IOException {
ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
BuckConfig buckConfig = params.getBuckConfig();
BuildRuleResolver ruleResolver = result.getResolver();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
JavacOptions javacOptions = buckConfig.getView(JavaBuckConfig.class).getDefaultJavacOptions();
IjProject project = new IjProject(targetGraphAndTargets, getJavaPackageFinder(buckConfig), JavaFileParser.createJavaFileParser(javacOptions), ruleResolver, sourcePathResolver, ruleFinder, params.getCell().getFilesystem(), getIntellijAggregationMode(buckConfig), buckConfig);
return project.write(runIjCleaner, getRemoveUnusedLibraries(buckConfig), excludeArtifacts || getExcludeArtifactsFromConfig(buckConfig));
}
use of com.facebook.buck.rules.ActionGraphAndResolver in project buck by facebook.
the class FetchCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
if (getArguments().isEmpty()) {
params.getBuckEventBus().post(ConsoleEvent.severe("Must specify at least one build target to fetch."));
return 1;
}
// Post the build started event, setting it to the Parser recorded start time if appropriate.
BuildEvent.Started started = BuildEvent.started(getArguments());
if (params.getParser().getParseStartTime().isPresent()) {
params.getBuckEventBus().post(started, params.getParser().getParseStartTime().get());
} else {
params.getBuckEventBus().post(started);
}
FetchTargetNodeToBuildRuleTransformer ruleGenerator = createFetchTransformer(params);
int exitCode;
try (CommandThreadManager pool = new CommandThreadManager("Fetch", getConcurrencyLimit(params.getBuckConfig()))) {
ActionGraphAndResolver actionGraphAndResolver;
ImmutableSet<BuildTarget> buildTargets;
try {
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
TargetGraphAndBuildTargets result = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), /* ignoreBuckAutodepsFiles */
false, parserConfig.getDefaultFlavorsMode());
if (params.getBuckConfig().getBuildVersions()) {
result = toVersionedTargetGraph(params, result);
}
actionGraphAndResolver = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), ruleGenerator, result.getTargetGraph()));
buildTargets = ruleGenerator.getDownloadableTargets();
} catch (BuildTargetException | BuildFileParseException | VersionException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return 1;
}
CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
LocalCachingBuildEngineDelegate localCachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
try (RuleKeyCacheScope<RuleKey> ruleKeyCacheScope = getDefaultRuleKeyCacheScope(params, new RuleKeyCacheRecycler.SettingsAffectingCache(params.getBuckConfig().getKeySeed(), actionGraphAndResolver.getActionGraph()));
Build build = createBuild(params.getBuckConfig(), actionGraphAndResolver.getActionGraph(), actionGraphAndResolver.getResolver(), params.getCell(), params.getAndroidPlatformTargetSupplier(), new CachingBuildEngine(localCachingBuildEngineDelegate, pool.getExecutor(), pool.getExecutor(), new DefaultStepRunner(), getBuildEngineMode().orElse(cachingBuildEngineBuckConfig.getBuildEngineMode()), cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> localCachingBuildEngineDelegate.getFileHashCache(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), ruleKeyCacheScope.getCache())), params.getArtifactCacheFactory().newInstance(), params.getConsole(), params.getBuckEventBus(), Optional.empty(), params.getPersistentWorkerPools(), params.getPlatform(), params.getEnvironment(), params.getObjectMapper(), params.getClock(), Optional.empty(), Optional.empty(), params.getExecutors())) {
exitCode = build.executeAndPrintFailuresToEventBus(buildTargets, isKeepGoing(), params.getBuckEventBus(), params.getConsole(), getPathToBuildReport(params.getBuckConfig()));
}
}
params.getBuckEventBus().post(BuildEvent.finished(started, exitCode));
return exitCode;
}
use of com.facebook.buck.rules.ActionGraphAndResolver in project buck by facebook.
the class BuildCommand method createGraphs.
private ActionAndTargetGraphs createGraphs(CommandRunnerParams params, WeightedListeningExecutorService executorService) throws ActionGraphCreationException, IOException, InterruptedException {
TargetGraphAndBuildTargets unversionedTargetGraph = createUnversionedTargetGraph(params, executorService);
Optional<TargetGraphAndBuildTargets> versionedTargetGraph = Optional.empty();
try {
if (params.getBuckConfig().getBuildVersions()) {
versionedTargetGraph = Optional.of(toVersionedTargetGraph(params, unversionedTargetGraph));
}
} catch (VersionException e) {
throw new ActionGraphCreationException(MoreExceptions.getHumanReadableOrLocalizedMessage(e));
}
TargetGraphAndBuildTargets targetGraphForLocalBuild = getTargetGraphForLocalBuild(unversionedTargetGraph, versionedTargetGraph);
checkSingleBuildTargetSpecifiedForOutBuildMode(targetGraphForLocalBuild);
ActionGraphAndResolver actionGraph = createActionGraphAndResolver(params, targetGraphForLocalBuild);
return new ActionAndTargetGraphs(unversionedTargetGraph, versionedTargetGraph, actionGraph);
}
use of com.facebook.buck.rules.ActionGraphAndResolver in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method createDistBuildFileHashes.
private DistBuildFileHashes createDistBuildFileHashes(TargetGraph targetGraph, Cell rootCell) throws IOException {
ActionGraphCache cache = new ActionGraphCache(new BroadcastEventListener());
ActionGraphAndResolver actionGraphAndResolver = cache.getActionGraph(BuckEventBusFactory.newInstance(), true, false, targetGraph, KEY_SEED);
BuildRuleResolver ruleResolver = actionGraphAndResolver.getResolver();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
DistBuildCellIndexer cellIndexer = new DistBuildCellIndexer(rootCell);
ImmutableList.Builder<ProjectFileHashCache> allCaches = ImmutableList.builder();
allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(rootCell.getFilesystem()));
for (Path cellPath : rootCell.getKnownRoots()) {
Cell cell = rootCell.getCell(cellPath);
allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(cell.getFilesystem()));
}
allCaches.addAll(DefaultFileHashCache.createOsRootDirectoriesCaches());
StackedFileHashCache stackedCache = new StackedFileHashCache(allCaches.build());
return new DistBuildFileHashes(actionGraphAndResolver.getActionGraph(), sourcePathResolver, ruleFinder, stackedCache, cellIndexer, MoreExecutors.newDirectExecutorService(), /* keySeed */
KEY_SEED, rootCell);
}
Aggregations