use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class AppleLibraryDescription method createMetadataForLibrary.
<U> Optional<U> createMetadataForLibrary(BuildTarget buildTarget, BuildRuleResolver resolver, Optional<ImmutableMap<BuildTarget, Version>> selectedVersions, AppleNativeTargetDescriptionArg args, Class<U> metadataClass) throws NoSuchBuildTargetException {
// Forward to C/C++ library description.
if (CxxLibraryDescription.METADATA_TYPE.containsAnyOf(buildTarget.getFlavors())) {
CxxLibraryDescription.Arg delegateArg = delegate.createUnpopulatedConstructorArg();
AppleDescriptions.populateCxxLibraryDescriptionArg(new SourcePathResolver(new SourcePathRuleFinder(resolver)), delegateArg, args, buildTarget);
return delegate.createMetadata(buildTarget, resolver, delegateArg, selectedVersions, metadataClass);
}
if (metadataClass.isAssignableFrom(FrameworkDependencies.class) && buildTarget.getFlavors().contains(AppleDescriptions.FRAMEWORK_FLAVOR)) {
Optional<Flavor> cxxPlatformFlavor = delegate.getCxxPlatforms().getFlavor(buildTarget);
Preconditions.checkState(cxxPlatformFlavor.isPresent(), "Could not find cxx platform in:\n%s", Joiner.on(", ").join(buildTarget.getFlavors()));
ImmutableSet.Builder<SourcePath> sourcePaths = ImmutableSet.builder();
for (BuildTarget dep : args.deps) {
Optional<FrameworkDependencies> frameworks = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(AppleDescriptions.FRAMEWORK_FLAVOR).addFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR).addFlavors(cxxPlatformFlavor.get()).build(), FrameworkDependencies.class);
if (frameworks.isPresent()) {
sourcePaths.addAll(frameworks.get().getSourcePaths());
}
}
// Not all parts of Buck use require yet, so require the rule here so it's available in the
// resolver for the parts that don't.
BuildRule buildRule = resolver.requireRule(buildTarget);
sourcePaths.add(buildRule.getSourcePathToOutput());
return Optional.of(metadataClass.cast(FrameworkDependencies.of(sourcePaths.build())));
}
return Optional.empty();
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class RobolectricTestDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
JavacOptions javacOptions = JavacOptionsFactory.create(templateOptions, params, resolver, ruleFinder, args);
AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(params.getBuildTarget(), params.copyReplacingExtraDeps(Suppliers.ofInstance(resolver.getAllRules(args.exportedDeps))), javacOptions, DependencyMode.TRANSITIVE, /* forceFinalResourceIds */
true, /* resourceUnionPackage */
Optional.empty(), /* rName */
Optional.empty(), args.useOldStyleableFormat);
if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
if (params.getBuildTarget().getFlavors().contains(AndroidLibraryGraphEnhancer.DUMMY_R_DOT_JAVA_FLAVOR)) {
return graphEnhancer.getBuildableForAndroidResourcesAbi(resolver, ruleFinder);
}
BuildTarget testTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule testRule = resolver.requireRule(testTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
}
ImmutableList<String> vmArgs = args.vmArgs;
Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(resolver, /* createBuildableIfEmpty */
true);
ImmutableSet<Either<SourcePath, Path>> additionalClasspathEntries = ImmutableSet.of();
if (dummyRDotJava.isPresent()) {
additionalClasspathEntries = ImmutableSet.of(Either.ofLeft(dummyRDotJava.get().getSourcePathToOutput()));
ImmutableSortedSet<BuildRule> newExtraDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).add(dummyRDotJava.get()).build();
params = params.copyReplacingExtraDeps(Suppliers.ofInstance(newExtraDeps));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, ruleFinder, cxxPlatform);
params = cxxLibraryEnhancement.updatedParams;
// Rewrite dependencies on tests to actually depend on the code which backs the test.
BuildRuleParams testsLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps)))).build()), Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).build())).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig, /* postprocessClassesCommands */
ImmutableList.of(), /* exportDeps */
ImmutableSortedSet.of(), /* providedDeps */
resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), javacOptions.trackClassUsage(), additionalClasspathEntries, new JavacToJarStepFactory(javacOptions, new BootClasspathAppender()), args.resourcesRoot, args.manifestFile, args.mavenCoords, /* tests */
ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of()));
return new RobolectricTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), ruleFinder, testsLibrary, additionalClasspathEntries, args.labels, args.contacts, TestType.JUNIT, javaOptions, vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment, dummyRDotJava, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel, args.stdErrLogLevel, args.robolectricRuntimeDependency, args.robolectricManifest);
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class JavaBuildGraphProcessor method run.
/**
* Creates the appropriate target graph and other resources needed for the {@link Processor} and
* runs it. This method will take responsibility for cleaning up the executor service after it
* runs.
*/
static void run(final CommandRunnerParams params, final AbstractCommand command, final Processor processor) throws ExitCodeException, InterruptedException, IOException {
final ConcurrencyLimit concurrencyLimit = command.getConcurrencyLimit(params.getBuckConfig());
try (CommandThreadManager pool = new CommandThreadManager(command.getClass().getName(), concurrencyLimit)) {
Cell cell = params.getCell();
WeightedListeningExecutorService executorService = pool.getExecutor();
// Ideally, we should be able to construct the TargetGraph quickly assuming most of it is
// already in memory courtesy of buckd. Though we could make a performance optimization where
// we pass an option to buck.py that tells it to ignore reading the BUCK.autodeps files when
// parsing the BUCK files because we never need to consider the existing auto-generated deps
// when creating the new auto-generated deps. If we did so, we would have to make sure to keep
// the nodes for that version of the graph separate from the ones that are actually used for
// building.
TargetGraph graph;
try {
graph = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), cell, command.getEnableParserProfiling(), executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), cell.getRoot()))), /* ignoreBuckAutodepsFiles */
true).getTargetGraph();
} catch (BuildTargetException | BuildFileParseException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
throw new ExitCodeException(1);
}
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
LocalCachingBuildEngineDelegate cachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
BuildEngine buildEngine = new CachingBuildEngine(cachingBuildEngineDelegate, executorService, executorService, new DefaultStepRunner(), CachingBuildEngine.BuildMode.SHALLOW, cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), buildRuleResolver, cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> cachingBuildEngineDelegate.getFileHashCache(), buildRuleResolver, cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), new DefaultRuleKeyCache<>()));
// Create a BuildEngine because we store symbol information as build artifacts.
BuckEventBus eventBus = params.getBuckEventBus();
ExecutionContext executionContext = ExecutionContext.builder().setConsole(params.getConsole()).setConcurrencyLimit(concurrencyLimit).setBuckEventBus(eventBus).setEnvironment(/* environment */
ImmutableMap.of()).setExecutors(ImmutableMap.<ExecutorPool, ListeningExecutorService>of(ExecutorPool.CPU, executorService)).setJavaPackageFinder(params.getJavaPackageFinder()).setObjectMapper(params.getObjectMapper()).setPlatform(params.getPlatform()).setCellPathResolver(params.getCell().getCellPathResolver()).build();
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
BuildEngineBuildContext buildContext = BuildEngineBuildContext.builder().setBuildContext(BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(executionContext.getJavaPackageFinder()).setEventBus(eventBus).build()).setClock(params.getClock()).setArtifactCache(params.getArtifactCacheFactory().newInstance()).setBuildId(eventBus.getBuildId()).setObjectMapper(params.getObjectMapper()).setEnvironment(executionContext.getEnvironment()).setKeepGoing(false).build();
// Traverse the TargetGraph to find all of the auto-generated dependencies.
JavaDepsFinder javaDepsFinder = JavaDepsFinder.createJavaDepsFinder(params.getBuckConfig(), params.getCell().getCellPathResolver(), params.getObjectMapper(), buildContext, executionContext, buildEngine);
processor.process(graph, javaDepsFinder, executorService);
}
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class BuildCommand method showOutputs.
private void showOutputs(CommandRunnerParams params, ActionGraphAndResolver actionGraphAndResolver) {
Optional<DefaultRuleKeyFactory> ruleKeyFactory = Optional.empty();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(actionGraphAndResolver.getResolver());
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
if (showRuleKey) {
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(params.getBuckConfig().getKeySeed());
ruleKeyFactory = Optional.of(new DefaultRuleKeyFactory(fieldLoader, params.getFileHashCache(), pathResolver, ruleFinder));
}
params.getConsole().getStdOut().println("The outputs are:");
for (BuildTarget buildTarget : buildTargets) {
try {
BuildRule rule = actionGraphAndResolver.getResolver().requireRule(buildTarget);
Optional<Path> outputPath = TargetsCommand.getUserFacingOutputPath(pathResolver, rule, showFullOutput, params.getBuckConfig().getBuckOutCompatLink());
params.getConsole().getStdOut().printf("%s%s%s\n", rule.getFullyQualifiedName(), showRuleKey ? " " + ruleKeyFactory.get().build(rule).toString() : "", showOutput || showFullOutput ? " " + outputPath.map(Object::toString).orElse("") : "");
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(MoreExceptions.getHumanReadableOrLocalizedMessage(e));
}
}
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class BuildCommand method processSuccessfulBuild.
private int processSuccessfulBuild(CommandRunnerParams params, ActionAndTargetGraphs graphs) throws IOException {
if (showOutput || showFullOutput || showRuleKey) {
showOutputs(params, graphs.actionGraph);
}
if (outputPathForSingleBuildTarget != null) {
BuildTarget loneTarget = Iterables.getOnlyElement(graphs.getTargetGraphForLocalBuild().getBuildTargets());
BuildRule rule = graphs.actionGraph.getResolver().getRule(loneTarget);
if (!rule.outputFileCanBeCopied()) {
params.getConsole().printErrorText(String.format("%s does not have an output that is compatible with `buck build --out`", loneTarget));
return 1;
} else {
SourcePath output = Preconditions.checkNotNull(rule.getSourcePathToOutput(), "%s specified a build target that does not have an output file: %s", OUT_LONG_ARG, loneTarget);
ProjectFilesystem projectFilesystem = rule.getProjectFilesystem();
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(graphs.actionGraph.getResolver()));
projectFilesystem.copyFile(pathResolver.getAbsolutePath(output), outputPathForSingleBuildTarget);
}
}
return 0;
}
Aggregations