Search in sources :

Example 1 with AbstractGenruleDescription

use of com.facebook.buck.shell.AbstractGenruleDescription in project buck by facebook.

the class AppleDescriptions method getFlavoredBinaryRule.

private static BuildRule getFlavoredBinaryRule(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, TargetGraph targetGraph, ImmutableSet<Flavor> flavors, BuildRuleResolver resolver, BuildTarget binary) throws NoSuchBuildTargetException {
    // Don't flavor genrule deps.
    if (targetGraph.get(binary).getDescription() instanceof AbstractGenruleDescription) {
        return resolver.requireRule(binary);
    }
    // Cxx targets must have one Platform Flavor set otherwise nothing gets compiled.
    if (flavors.contains(AppleDescriptions.FRAMEWORK_FLAVOR)) {
        flavors = ImmutableSet.<Flavor>builder().addAll(flavors).add(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    }
    flavors = ImmutableSet.copyOf(Sets.difference(flavors, ImmutableSet.of(AppleDescriptions.FRAMEWORK_FLAVOR, AppleBinaryDescription.APP_FLAVOR)));
    if (!cxxPlatformFlavorDomain.containsAnyOf(flavors)) {
        flavors = new ImmutableSet.Builder<Flavor>().addAll(flavors).add(defaultCxxPlatform.getFlavor()).build();
    }
    BuildTarget.Builder buildTargetBuilder = BuildTarget.builder(binary.getUnflavoredBuildTarget()).addAllFlavors(flavors);
    if (!(AppleLibraryDescription.LIBRARY_TYPE.getFlavor(flavors).isPresent())) {
        buildTargetBuilder.addAllFlavors(binary.getFlavors());
    } else {
        buildTargetBuilder.addAllFlavors(Sets.difference(binary.getFlavors(), AppleLibraryDescription.LIBRARY_TYPE.getFlavors()));
    }
    BuildTarget buildTarget = buildTargetBuilder.build();
    final TargetNode<?, ?> binaryTargetNode = targetGraph.get(buildTarget);
    if (binaryTargetNode.getDescription() instanceof AppleTestDescription) {
        return resolver.getRule(binary);
    }
    // must be specified.
    if (binaryTargetNode.getDescription() instanceof AppleLibraryDescription && (Sets.intersection(AppleBundleDescription.SUPPORTED_LIBRARY_FLAVORS, buildTarget.getFlavors()).size() != 1)) {
        throw new HumanReadableException("AppleExtension bundle [%s] must have exactly one of these flavors: [%s].", binaryTargetNode.getBuildTarget().toString(), Joiner.on(", ").join(AppleBundleDescription.SUPPORTED_LIBRARY_FLAVORS));
    }
    if (!StripStyle.FLAVOR_DOMAIN.containsAnyOf(buildTarget.getFlavors())) {
        buildTarget = buildTarget.withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
    }
    return resolver.requireRule(buildTarget);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) AbstractGenruleDescription(com.facebook.buck.shell.AbstractGenruleDescription) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1 Flavor (com.facebook.buck.model.Flavor)1 InternalFlavor (com.facebook.buck.model.InternalFlavor)1 AbstractGenruleDescription (com.facebook.buck.shell.AbstractGenruleDescription)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1