use of com.facebook.buck.model.Flavor in project buck by facebook.
the class CxxLibraryDescription method getUntypedParams.
static BuildRuleParams getUntypedParams(BuildRuleParams params) {
Optional<Map.Entry<Flavor, Type>> type = getLibType(params.getBuildTarget());
if (!type.isPresent()) {
return params;
}
Set<Flavor> flavors = Sets.newHashSet(params.getBuildTarget().getFlavors());
flavors.remove(type.get().getKey());
BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget()).addAllFlavors(flavors).build();
return params.withBuildTarget(target);
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class CxxLibraryDescription method getTransitiveCxxPreprocessorInput.
public static ImmutableCollection<CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(BuildRuleParams params, BuildRuleResolver ruleResolver, CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
// Check if there is a target node representative for the library in the action graph and,
// if so, grab the cached transitive C/C++ preprocessor input from that.
BuildTarget rawTarget = params.getBuildTarget().withoutFlavors(ImmutableSet.<Flavor>builder().addAll(LIBRARY_TYPE.getFlavors()).add(cxxPlatform.getFlavor()).build());
Optional<BuildRule> rawRule = ruleResolver.getRuleOptional(rawTarget);
if (rawRule.isPresent()) {
CxxLibrary rule = (CxxLibrary) rawRule.get();
return rule.getTransitiveCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC).values();
}
Map<BuildTarget, CxxPreprocessorInput> input = Maps.newLinkedHashMap();
input.put(params.getBuildTarget(), ruleResolver.requireMetadata(params.getBuildTarget().withAppendedFlavors(MetadataType.CXX_PREPROCESSOR_INPUT.getFlavor(), cxxPlatform.getFlavor(), HeaderVisibility.PUBLIC.getFlavor()), CxxPreprocessorInput.class).orElseThrow(IllegalStateException::new));
for (BuildRule rule : params.getDeps()) {
if (rule instanceof CxxPreprocessorDep) {
input.putAll(((CxxPreprocessorDep) rule).getTransitiveCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC));
}
}
return ImmutableList.copyOf(input.values());
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class JavaLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
BuildTarget target = params.getBuildTarget();
// We know that the flavour we're being asked to create is valid, since the check is done when
// creating the action graph from the target graph.
ImmutableSortedSet<Flavor> flavors = target.getFlavors();
if (flavors.contains(Javadoc.DOC_JAR)) {
BuildTarget unflavored = BuildTarget.of(target.getUnflavoredBuildTarget());
BuildRule baseLibrary = resolver.requireRule(unflavored);
JarShape shape = params.getBuildTarget().getFlavors().contains(JavaLibrary.MAVEN_JAR) ? JarShape.MAVEN : JarShape.SINGLE;
JarShape.Summary summary = shape.gatherDeps(baseLibrary);
ImmutableSet<SourcePath> sources = summary.getPackagedRules().stream().filter(HasSources.class::isInstance).map(rule -> ((HasSources) rule).getSources()).flatMap(Collection::stream).collect(MoreCollectors.toImmutableSet());
// In theory, the only deps we need are the ones that contribute to the sourcepaths. However,
// javadoc wants to have classes being documented have all their deps be available somewhere.
// Ideally, we'd not build everything, but then we're not able to document any classes that
// rely on auto-generated classes, such as those created by the Immutables library. Oh well.
// Might as well add them as deps. *sigh*
ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
// Sourcepath deps
deps.addAll(ruleFinder.filterBuildRuleInputs(sources));
// Classpath deps
deps.add(baseLibrary);
deps.addAll(summary.getClasspath().stream().filter(rule -> HasClasspathEntries.class.isAssignableFrom(rule.getClass())).flatMap(rule -> rule.getTransitiveClasspathDeps().stream()).iterator());
BuildRuleParams emptyParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(deps.build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
return new Javadoc(emptyParams, args.mavenCoords, args.mavenPomTemplate, summary.getMavenDeps(), sources);
}
if (CalculateAbi.isAbiTarget(target)) {
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(target);
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
BuildRuleParams paramsWithMavenFlavor = null;
if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
paramsWithMavenFlavor = params;
// Maven rules will depend upon their vanilla versions, so the latter have to be constructed
// without the maven flavor to prevent output-path conflict
params = params.withoutFlavor(JavaLibrary.MAVEN_JAR);
}
if (flavors.contains(JavaLibrary.SRC_JAR)) {
args.mavenCoords = args.mavenCoords.map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return new JavaSourceJar(params, args.srcs, args.mavenCoords);
} else {
return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), args.srcs, args.mavenCoords, args.mavenPomTemplate);
}
}
JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig, args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, javacOptions.getClassesToRemoveFromJar());
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return defaultJavaLibrary;
} else {
resolver.addToIndex(defaultJavaLibrary);
return MavenUberJar.create(defaultJavaLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
}
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class JsLibraryDescription method mapSourcesToFlavors.
private static ImmutableBiMap<Either<SourcePath, Pair<SourcePath, String>>, Flavor> mapSourcesToFlavors(SourcePathResolver sourcePathResolver, ImmutableSet<Either<SourcePath, Pair<SourcePath, String>>> sources) {
final ImmutableBiMap.Builder<Either<SourcePath, Pair<SourcePath, String>>, Flavor> builder = ImmutableBiMap.builder();
for (Either<SourcePath, Pair<SourcePath, String>> source : sources) {
final Path relativePath = source.isLeft() ? sourcePathResolver.getRelativePath(source.getLeft()) : Paths.get(source.getRight().getSecond());
builder.put(source, JsFlavors.fileFlavorForSourcePath(relativePath));
}
return builder.build();
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class JsLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
params.getBuildTarget().getBasePath();
// this params object is used as base for the JsLibrary build rule, but also for all dynamically
// created JsFile rules.
// For the JsLibrary case, we want to propagate flavors to library dependencies
// For the JsFile case, we only want to depend on the worker, not on any libraries
params = JsUtil.withWorkerDependencyOnly(params, resolver, args.worker);
final WorkerTool worker = resolver.getRuleWithType(args.worker, WorkerTool.class);
final SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
final SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
final ImmutableBiMap<Either<SourcePath, Pair<SourcePath, String>>, Flavor> sourcesToFlavors = mapSourcesToFlavors(sourcePathResolver, args.srcs);
final Optional<Either<SourcePath, Pair<SourcePath, String>>> file = JsFlavors.extractSourcePath(sourcesToFlavors.inverse(), params.getBuildTarget().getFlavors().stream());
if (file.isPresent()) {
return params.getBuildTarget().getFlavors().contains(JsFlavors.RELEASE) ? createReleaseFileRule(params, resolver, args, worker) : createDevFileRule(params, ruleFinder, sourcePathResolver, args, file.get(), worker);
} else {
return new LibraryBuilder(targetGraph, resolver, params, sourcesToFlavors).setSources(args.srcs).setLibraryDependencies(args.libs).build(worker);
}
}
Aggregations