Search in sources :

Example 36 with Flavor

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);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 37 with Flavor

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());
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 38 with Flavor

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);
    }
}
Also used : Iterables(com.google.common.collect.Iterables) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) VersionPropagator(com.facebook.buck.versions.VersionPropagator) Flavored(com.facebook.buck.model.Flavored) HasTests(com.facebook.buck.model.HasTests) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Suppliers(com.google.common.base.Suppliers) ResourceValidator.validateResources(com.facebook.buck.jvm.common.ResourceValidator.validateResources) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) BuildRules(com.facebook.buck.rules.BuildRules) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) AetherUtil(com.facebook.buck.maven.AetherUtil) TargetGraph(com.facebook.buck.rules.TargetGraph) Collection(java.util.Collection) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Hint(com.facebook.buck.rules.Hint) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Description(com.facebook.buck.rules.Description) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Flavor(com.facebook.buck.model.Flavor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePath(com.facebook.buck.rules.SourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 39 with Flavor

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Either(com.facebook.buck.model.Either) Flavor(com.facebook.buck.model.Flavor) Pair(com.facebook.buck.model.Pair)

Example 40 with Flavor

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);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) WorkerTool(com.facebook.buck.shell.WorkerTool) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Flavor(com.facebook.buck.model.Flavor)

Aggregations

Flavor (com.facebook.buck.model.Flavor)60 InternalFlavor (com.facebook.buck.model.InternalFlavor)42 BuildTarget (com.facebook.buck.model.BuildTarget)33 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)17 Test (org.junit.Test)17 SourcePath (com.facebook.buck.rules.SourcePath)14 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 ImmutableMap (com.google.common.collect.ImmutableMap)14 BuildRule (com.facebook.buck.rules.BuildRule)13 ImmutableSet (com.google.common.collect.ImmutableSet)13 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)12 Path (java.nio.file.Path)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)11 Optional (java.util.Optional)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)9 Map (java.util.Map)9 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)7 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)6