use of com.facebook.buck.android.aapt.MergeAndroidResourceSources in project buck by facebook.
the class AndroidAarDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams originalBuildRuleParams, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
UnflavoredBuildTarget originalBuildTarget = originalBuildRuleParams.getBuildTarget().checkUnflavored();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
ImmutableList.Builder<BuildRule> aarExtraDepsBuilder = ImmutableList.<BuildRule>builder().addAll(originalBuildRuleParams.getExtraDeps().get());
/* android_manifest */
AndroidManifestDescription.Arg androidManifestArgs = androidManifestDescription.createUnpopulatedConstructorArg();
androidManifestArgs.skeleton = args.manifestSkeleton;
androidManifestArgs.deps = args.deps;
BuildRuleParams androidManifestParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_MANIFEST_FLAVOR));
AndroidManifest manifest = androidManifestDescription.createBuildRule(targetGraph, androidManifestParams, resolver, androidManifestArgs);
aarExtraDepsBuilder.add(resolver.addToIndex(manifest));
final APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph, originalBuildRuleParams.getBuildTarget(), Optional.empty());
/* assemble dirs */
AndroidPackageableCollector collector = new AndroidPackageableCollector(originalBuildRuleParams.getBuildTarget(), /* buildTargetsToExcludeFromDex */
ImmutableSet.of(), /* resourcesToExclude */
ImmutableSet.of(), apkModuleGraph);
collector.addPackageables(AndroidPackageableCollector.getPackageableRules(originalBuildRuleParams.getDeps()));
AndroidPackageableCollection packageableCollection = collector.build();
ImmutableSortedSet<BuildRule> androidResourceDeclaredDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getDeclaredDeps().get());
ImmutableSortedSet<BuildRule> androidResourceExtraDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getExtraDeps().get());
BuildRuleParams assembleAssetsParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_ASSETS_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
ImmutableCollection<SourcePath> assetsDirectories = packageableCollection.getAssetsDirectories();
AssembleDirectories assembleAssetsDirectories = new AssembleDirectories(assembleAssetsParams, assetsDirectories);
aarExtraDepsBuilder.add(resolver.addToIndex(assembleAssetsDirectories));
BuildRuleParams assembleResourceParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_RESOURCE_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
ImmutableCollection<SourcePath> resDirectories = packageableCollection.getResourceDetails().getResourceDirectories();
MergeAndroidResourceSources assembleResourceDirectories = new MergeAndroidResourceSources(assembleResourceParams, resDirectories);
aarExtraDepsBuilder.add(resolver.addToIndex(assembleResourceDirectories));
/* android_resource */
BuildRuleParams androidResourceParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_RESOURCE_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(manifest, assembleAssetsDirectories, assembleResourceDirectories)), Suppliers.ofInstance(ImmutableSortedSet.of()));
AndroidResource androidResource = new AndroidResource(androidResourceParams, ruleFinder, /* deps */
ImmutableSortedSet.<BuildRule>naturalOrder().add(assembleAssetsDirectories).add(assembleResourceDirectories).addAll(originalBuildRuleParams.getDeclaredDeps().get()).build(), assembleResourceDirectories.getSourcePathToOutput(), /* resSrcs */
ImmutableSortedMap.of(), /* rDotJavaPackage */
null, assembleAssetsDirectories.getSourcePathToOutput(), /* assetsSrcs */
ImmutableSortedMap.of(), manifest.getSourcePathToOutput(), /* hasWhitelistedStrings */
false);
aarExtraDepsBuilder.add(resolver.addToIndex(androidResource));
ImmutableSortedSet.Builder<SourcePath> classpathToIncludeInAar = ImmutableSortedSet.naturalOrder();
classpathToIncludeInAar.addAll(packageableCollection.getClasspathEntriesToDex());
aarExtraDepsBuilder.addAll(BuildRules.toBuildRulesFor(originalBuildRuleParams.getBuildTarget(), resolver, packageableCollection.getJavaLibrariesToDex()));
if (!args.buildConfigValues.getNameToField().isEmpty() && !args.includeBuildConfigClass) {
throw new HumanReadableException("Rule %s has build_config_values set but does not set " + "include_build_config_class to True. Either indicate you want to include the " + "BuildConfig class in the final .aar or do not specify build config values.", originalBuildRuleParams.getBuildTarget());
}
if (args.includeBuildConfigClass) {
ImmutableSortedSet<JavaLibrary> buildConfigRules = AndroidBinaryGraphEnhancer.addBuildConfigDeps(originalBuildRuleParams, AndroidBinary.PackageType.RELEASE, EnumSet.noneOf(AndroidBinary.ExopackageMode.class), args.buildConfigValues, Optional.empty(), resolver, javacOptions, packageableCollection);
resolver.addAllToIndex(buildConfigRules);
aarExtraDepsBuilder.addAll(buildConfigRules);
classpathToIncludeInAar.addAll(buildConfigRules.stream().map(BuildRule::getSourcePathToOutput).collect(Collectors.toList()));
}
/* native_libraries */
AndroidNativeLibsPackageableGraphEnhancer packageableGraphEnhancer = new AndroidNativeLibsPackageableGraphEnhancer(resolver, originalBuildRuleParams, nativePlatforms, ImmutableSet.of(), cxxBuckConfig, /* nativeLibraryMergeMap */
Optional.empty(), /* nativeLibraryMergeGlue */
Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
Optional<ImmutableMap<APKModule, CopyNativeLibraries>> nativeLibrariesOptional = packageableGraphEnhancer.enhance(packageableCollection).getCopyNativeLibraries();
if (nativeLibrariesOptional.isPresent() && nativeLibrariesOptional.get().containsKey(apkModuleGraph.getRootAPKModule())) {
aarExtraDepsBuilder.add(resolver.addToIndex(nativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule())));
}
Optional<Path> assembledNativeLibsDir = nativeLibrariesOptional.map(input -> {
CopyNativeLibraries copyNativeLibraries = input.get(apkModuleGraph.getRootAPKModule());
if (copyNativeLibraries == null) {
throw new HumanReadableException("Native libraries are present but not in the root application module.");
}
return copyNativeLibraries.getPathToNativeLibsDir();
});
BuildRuleParams androidAarParams = originalBuildRuleParams.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(aarExtraDepsBuilder.build())));
return new AndroidAar(androidAarParams, manifest, androidResource, assembleResourceDirectories.getSourcePathToOutput(), assembleAssetsDirectories.getSourcePathToOutput(), assembledNativeLibsDir, ImmutableSet.copyOf(packageableCollection.getNativeLibAssetsDirectories().values()), classpathToIncludeInAar.build());
}
Aggregations