private ImmutableSortedSet<BuildRule> getAdditionalAaptDeps( ImmutableSortedSet<BuildRule> resourceRules) { ImmutableSortedSet.Builder<BuildRule> builder = ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(resourceRules) .addAll( getTargetsAsRules( FluentIterable.from(androidResourceDepsFinder.getAssetOnlyAndroidResources()) .transform(HasBuildTarget.TO_TARGET) .toList())) .addAll( getTargetsAsRules( androidResourceDepsFinder.getAndroidTransitiveDependencies() .nativeTargetsWithAssets)); if (manifest instanceof BuildRuleSourcePath) { builder.add(((BuildRuleSourcePath) manifest).getRule()); } return builder.build(); }
EnhancementResult createAdditionalBuildables() { ImmutableSortedSet.Builder<BuildRule> enhancedDeps = ImmutableSortedSet.naturalOrder(); enhancedDeps.addAll(originalDeps); ImmutableSortedSet<BuildRule> resourceRules = getAndroidResourcesAsRules(); BuildTarget buildTargetForFilterResources = createBuildTargetWithFlavor(RESOURCES_FILTER_FLAVOR); FilteredResourcesProvider filteredResourcesProvider; boolean needsResourceFiltering = resourceFilter.isEnabled() || resourceCompressionMode.isStoreStringsAsAssets(); if (needsResourceFiltering) { ResourcesFilter resourcesFilter = new ResourcesFilter( buildTargetForFilterResources, androidResourceDepsFinder, resourceCompressionMode, resourceFilter); BuildRule resourcesFilterBuildRule = buildRuleAndAddToIndex( resourcesFilter, BuildRuleType.RESOURCES_FILTER, buildTargetForFilterResources, resourceRules); filteredResourcesProvider = resourcesFilter; enhancedDeps.add(resourcesFilterBuildRule); resourceRules = ImmutableSortedSet.of(resourcesFilterBuildRule); } else { filteredResourcesProvider = new IdentityResourcesProvider(androidResourceDepsFinder); } BuildTarget buildTargetForUberRDotJava = createBuildTargetWithFlavor(UBER_R_DOT_JAVA_FLAVOR); UberRDotJava uberRDotJava = new UberRDotJava( buildTargetForUberRDotJava, filteredResourcesProvider, javacOptions, androidResourceDepsFinder, shouldPreDex, shouldBuildStringSourceMap); BuildRule uberRDotJavaBuildRule = buildRuleAndAddToIndex( uberRDotJava, BuildRuleType.UBER_R_DOT_JAVA, buildTargetForUberRDotJava, resourceRules); enhancedDeps.add(uberRDotJavaBuildRule); Optional<PackageStringAssets> packageStringAssets = Optional.absent(); if (resourceCompressionMode.isStoreStringsAsAssets()) { BuildTarget buildTargetForPackageStringAssets = createBuildTargetWithFlavor(PACKAGE_STRING_ASSETS_FLAVOR); packageStringAssets = Optional.of( new PackageStringAssets( buildTargetForPackageStringAssets, filteredResourcesProvider, uberRDotJava)); BuildRule packageStringAssetsRule = buildRuleAndAddToIndex( packageStringAssets.get(), BuildRuleType.PACKAGE_STRING_ASSETS, buildTargetForPackageStringAssets, ImmutableSortedSet.of(uberRDotJavaBuildRule)); enhancedDeps.add(packageStringAssetsRule); } // Create the AaptPackageResourcesBuildable. BuildTarget buildTargetForAapt = createBuildTargetWithFlavor(AAPT_PACKAGE_FLAVOR); AaptPackageResources aaptPackageResources = new AaptPackageResources( buildTargetForAapt, manifest, filteredResourcesProvider, androidResourceDepsFinder.getAndroidTransitiveDependencies(), packageType, cpuFilters); BuildRule aaptPackageResourcesBuildRule = buildRuleAndAddToIndex( aaptPackageResources, BuildRuleType.AAPT_PACKAGE, buildTargetForAapt, getAdditionalAaptDeps(resourceRules)); enhancedDeps.add(aaptPackageResourcesBuildRule); Optional<PreDexMerge> preDexMerge = Optional.absent(); if (shouldPreDex) { BuildRule preDexMergeRule = createPreDexMergeRule(uberRDotJava); preDexMerge = Optional.of((PreDexMerge) preDexMergeRule.getBuildable()); enhancedDeps.add(preDexMergeRule); } ImmutableSortedSet<BuildRule> finalDeps; Optional<ComputeExopackageDepsAbi> computeExopackageDepsAbi = Optional.absent(); if (exopackage) { BuildTarget buildTargetForAbiCalculation = createBuildTargetWithFlavor(CALCULATE_ABI_FLAVOR); computeExopackageDepsAbi = Optional.of( new ComputeExopackageDepsAbi( buildTargetForAbiCalculation, androidResourceDepsFinder, uberRDotJava, aaptPackageResources, packageStringAssets, preDexMerge, keystore)); BuildRule computeExopackageDepsAbiRule = buildRuleAndAddToIndex( computeExopackageDepsAbi.get(), BuildRuleType.EXOPACKAGE_DEPS_ABI, buildTargetForAbiCalculation, enhancedDeps.build()); finalDeps = ImmutableSortedSet.of(computeExopackageDepsAbiRule); } else { finalDeps = enhancedDeps.build(); } return new EnhancementResult( filteredResourcesProvider, uberRDotJava, aaptPackageResources, packageStringAssets, preDexMerge, computeExopackageDepsAbi, finalDeps); }