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();
}
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());
}
}
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();
}
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());
}
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);
}
Aggregations