Search in sources :

Example 1 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class AndroidBinaryGraphEnhancer method addBuildConfigDeps.

/**
   * If the user specified any android_build_config() rules, then we must add some build rules to
   * generate the production {@code BuildConfig.class} files and ensure that they are included in
   * the list of {@link AndroidPackageableCollection#getClasspathEntriesToDex}.
   */
public static ImmutableSortedSet<JavaLibrary> addBuildConfigDeps(BuildRuleParams originalParams, PackageType packageType, EnumSet<ExopackageMode> exopackageModes, BuildConfigFields buildConfigValues, Optional<SourcePath> buildConfigValuesFile, BuildRuleResolver ruleResolver, JavacOptions javacOptions, AndroidPackageableCollection packageableCollection) throws NoSuchBuildTargetException {
    ImmutableSortedSet.Builder<JavaLibrary> result = ImmutableSortedSet.naturalOrder();
    BuildConfigFields buildConfigConstants = BuildConfigFields.fromFields(ImmutableList.of(BuildConfigFields.Field.of("boolean", BuildConfigs.DEBUG_CONSTANT, String.valueOf(packageType != AndroidBinary.PackageType.RELEASE)), BuildConfigFields.Field.of("boolean", BuildConfigs.IS_EXO_CONSTANT, String.valueOf(!exopackageModes.isEmpty())), BuildConfigFields.Field.of("int", BuildConfigs.EXOPACKAGE_FLAGS, String.valueOf(ExopackageMode.toBitmask(exopackageModes)))));
    for (Map.Entry<String, BuildConfigFields> entry : packageableCollection.getBuildConfigs().entrySet()) {
        // Merge the user-defined constants with the APK-specific overrides.
        BuildConfigFields totalBuildConfigValues = BuildConfigFields.empty().putAll(entry.getValue()).putAll(buildConfigValues).putAll(buildConfigConstants);
        // Each enhanced dep needs a unique build target, so we parameterize the build target by the
        // Java package.
        String javaPackage = entry.getKey();
        Flavor flavor = InternalFlavor.of("buildconfig_" + javaPackage.replace('.', '_'));
        BuildTarget buildTargetWithFlavors = BuildTarget.builder(originalParams.getBuildTarget()).addFlavors(flavor).build();
        BuildRuleParams buildConfigParams = new BuildRuleParams(buildTargetWithFlavors, /* declaredDeps */
        Suppliers.ofInstance(ImmutableSortedSet.of()), /* extraDeps */
        Suppliers.ofInstance(ImmutableSortedSet.of()), originalParams.getProjectFilesystem(), originalParams.getCellRoots());
        JavaLibrary buildConfigJavaLibrary = AndroidBuildConfigDescription.createBuildRule(buildConfigParams, javaPackage, totalBuildConfigValues, buildConfigValuesFile, /* useConstantExpressions */
        true, javacOptions, ruleResolver);
        ruleResolver.addToIndex(buildConfigJavaLibrary);
        Preconditions.checkNotNull(buildConfigJavaLibrary.getSourcePathToOutput(), "%s must have an output file.", buildConfigJavaLibrary);
        result.add(buildConfigJavaLibrary);
    }
    return result.build();
}
Also used : JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildConfigFields(com.facebook.buck.rules.coercer.BuildConfigFields)

Example 2 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class ApplePackageDescription method getApplePackageConfig.

/**
   * Get the correct package configuration based on the platform flavors of this build target.
   *
   * Validates that all named platforms yields the identical package config.
   *
   * @return If found, a package config for this target.
   * @throws HumanReadableException if there are multiple possible package configs.
   */
private Optional<ApplePackageConfigAndPlatformInfo> getApplePackageConfig(BuildTarget target, Function<String, com.facebook.buck.rules.args.Arg> macroExpander) {
    Set<Flavor> platformFlavors = getPlatformFlavorsOrDefault(target);
    // Ensure that different platforms generate the same config.
    // The value of this map is just for error reporting.
    Multimap<Optional<ApplePackageConfigAndPlatformInfo>, Flavor> packageConfigs = MultimapBuilder.hashKeys().arrayListValues().build();
    for (Flavor flavor : platformFlavors) {
        AppleCxxPlatform platform = appleCxxPlatformFlavorDomain.getValue(flavor);
        Optional<ApplePackageConfig> packageConfig = config.getPackageConfigForPlatform(platform.getAppleSdk().getApplePlatform());
        packageConfigs.put(packageConfig.isPresent() ? Optional.of(ApplePackageConfigAndPlatformInfo.of(packageConfig.get(), macroExpander, platform)) : Optional.empty(), flavor);
    }
    if (packageConfigs.isEmpty()) {
        return Optional.empty();
    } else if (packageConfigs.keySet().size() == 1) {
        return Iterables.getOnlyElement(packageConfigs.keySet());
    } else {
        throw new HumanReadableException("In target %s: Multi-architecture package has different package configs for targets: %s", target.getFullyQualifiedName(), packageConfigs.asMap().values());
    }
}
Also used : Optional(java.util.Optional) HumanReadableException(com.facebook.buck.util.HumanReadableException) Flavor(com.facebook.buck.model.Flavor)

Example 3 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class MultiarchFileInfos method generateThinFlavors.

/**
   * Expand flavors representing a fat binary into its thin binary equivalents.
   *
   * Useful when dealing with functions unaware of fat binaries.
   *
   * This does not actually check that the particular flavor set is valid.
   */
public static ImmutableList<ImmutableSortedSet<Flavor>> generateThinFlavors(Set<Flavor> platformFlavors, SortedSet<Flavor> flavors) {
    Set<Flavor> platformFreeFlavors = Sets.difference(flavors, platformFlavors);
    ImmutableList.Builder<ImmutableSortedSet<Flavor>> thinTargetsBuilder = ImmutableList.builder();
    for (Flavor flavor : flavors) {
        if (platformFlavors.contains(flavor)) {
            thinTargetsBuilder.add(ImmutableSortedSet.<Flavor>naturalOrder().addAll(platformFreeFlavors).add(flavor).build());
        }
    }
    return thinTargetsBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Flavor(com.facebook.buck.model.Flavor)

Example 4 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class MultiarchFileInfos method create.

/**
   * Inspect the given build target and return information about it if its a fat binary.
   *
   * @return non-empty when the target represents a fat binary.
   * @throws com.facebook.buck.util.HumanReadableException
   *    when the target is a fat binary but has incompatible flavors.
   */
public static Optional<MultiarchFileInfo> create(final FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, BuildTarget target) {
    ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors(appleCxxPlatforms.getFlavors(), target.getFlavors());
    if (thinFlavorSets.size() <= 1) {
        // Actually a thin binary
        return Optional.empty();
    }
    if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) {
        throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target);
    }
    AppleCxxPlatform representativePlatform = null;
    AppleSdk sdk = null;
    for (SortedSet<Flavor> flavorSet : thinFlavorSets) {
        AppleCxxPlatform platform = Preconditions.checkNotNull(appleCxxPlatforms.getValue(flavorSet).orElse(null));
        if (sdk == null) {
            sdk = platform.getAppleSdk();
            representativePlatform = platform;
        } else if (sdk != platform.getAppleSdk()) {
            throw new HumanReadableException("%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target);
        }
    }
    MultiarchFileInfo.Builder builder = MultiarchFileInfo.builder().setFatTarget(target).setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform));
    BuildTarget platformFreeTarget = target.withoutFlavors(appleCxxPlatforms.getFlavors());
    for (SortedSet<Flavor> flavorSet : thinFlavorSets) {
        builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet));
    }
    return Optional.of(builder.build());
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Flavor(com.facebook.buck.model.Flavor)

Example 5 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class CxxInferEnhancer method requireInferAnalyzeBuildRuleForCxxDescriptionArg.

public static CxxInferAnalyze requireInferAnalyzeBuildRuleForCxxDescriptionArg(BuildRuleParams params, BuildRuleResolver resolver, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, CxxConstructorArg args, InferBuckConfig inferConfig, CxxInferSourceFilter sourceFilter) throws NoSuchBuildTargetException {
    Flavor inferAnalyze = InferFlavors.INFER_ANALYZE.get();
    BuildRuleParams paramsWithInferAnalyzeFlavor = InferFlavors.paramsWithoutAnyInferFlavor(params).withAppendedFlavor(inferAnalyze);
    Optional<CxxInferAnalyze> existingRule = resolver.getRuleOptionalWithType(paramsWithInferAnalyzeFlavor.getBuildTarget(), CxxInferAnalyze.class);
    if (existingRule.isPresent()) {
        return existingRule.get();
    }
    CxxInferCaptureAndAggregatingRules<CxxInferAnalyze> cxxInferCaptureAndAnalyzeRules = requireTransitiveCaptureAndAggregatingRules(params, resolver, cxxBuckConfig, cxxPlatform, args, inferConfig, sourceFilter, inferAnalyze, CxxInferAnalyze.class);
    return createInferAnalyzeRule(paramsWithInferAnalyzeFlavor, resolver, inferConfig, cxxInferCaptureAndAnalyzeRules);
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) InternalFlavor(com.facebook.buck.model.InternalFlavor) 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