Search in sources :

Example 1 with SizeConfiguration

use of com.android.tools.build.bundletool.model.SizeConfiguration in project bundletool by google.

the class GetSizeCsvUtils method getSizeTotalOutputInCsv.

public static String getSizeTotalOutputInCsv(ConfigurationSizes configurationSizes, ImmutableSet<Dimension> dimensions, SizeFormatter sizeFormatter) {
    checkState(configurationSizes.getMinSizeConfigurationMap().keySet().equals(configurationSizes.getMaxSizeConfigurationMap().keySet()), "Min and Max maps should contains same keys.");
    CsvFormatter.Builder csvFormatter = CsvFormatter.builder();
    csvFormatter.setHeader(getSizeTotalCsvHeader(dimensions));
    for (SizeConfiguration sizeConfiguration : configurationSizes.getMinSizeConfigurationMap().keySet()) {
        csvFormatter.addRow(getSizeTotalCsvRow(sizeFormatter, dimensions, sizeConfiguration, configurationSizes.getMinSizeConfigurationMap().get(sizeConfiguration), configurationSizes.getMaxSizeConfigurationMap().get(sizeConfiguration)));
    }
    return csvFormatter.build().format();
}
Also used : SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration)

Example 2 with SizeConfiguration

use of com.android.tools.build.bundletool.model.SizeConfiguration in project bundletool by google.

the class GetSizeCommand method getSizeTotalInternal.

@VisibleForTesting
ConfigurationSizes getSizeTotalInternal() {
    BuildApksResult buildApksResult = ResultUtils.readTableOfContents(getApksArchivePath());
    ImmutableList<Variant> variants = new VariantMatcher(getDeviceSpec(), getInstant()).getAllMatchingVariants(buildApksResult);
    ImmutableMap<String, Long> variantCompressedSizeByApkPaths = getVariantCompressedSizeByApkPaths(variants, getApksArchivePath());
    ImmutableList<String> assetModuleApks = buildApksResult.getAssetSliceSetList().stream().flatMap(module -> module.getApkDescriptionList().stream()).map(ApkDescription::getPath).collect(toImmutableList());
    ImmutableMap<String, Long> assetModuleCompressedSizeByApkPaths = getCompressedSizeByApkPaths(assetModuleApks, getApksArchivePath());
    ImmutableMap<SizeConfiguration, Long> minSizeConfigurationMap = ImmutableMap.of();
    ImmutableMap<SizeConfiguration, Long> maxSizeConfigurationMap = ImmutableMap.of();
    for (Variant variant : variants) {
        ConfigurationSizes variantConfigurationSizes = new VariantTotalSizeAggregator(variantCompressedSizeByApkPaths, Version.of(buildApksResult.getBundletool().getVersion()), variant, this).getSize();
        ConfigurationSizes assetModuleConfigurationSizes = new AssetModuleSizeAggregator(buildApksResult.getAssetSliceSetList(), variant.getTargeting(), assetModuleCompressedSizeByApkPaths, this).getSize();
        ConfigurationSizes configurationSizes = ConfigurationSizesMerger.merge(variantConfigurationSizes, assetModuleConfigurationSizes);
        minSizeConfigurationMap = combineMaps(minSizeConfigurationMap, configurationSizes.getMinSizeConfigurationMap(), Math::min);
        maxSizeConfigurationMap = combineMaps(maxSizeConfigurationMap, configurationSizes.getMaxSizeConfigurationMap(), Math::max);
    }
    return ConfigurationSizes.create(minSizeConfigurationMap, maxSizeConfigurationMap);
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) VariantMatcher(com.android.tools.build.bundletool.device.VariantMatcher) AssetModuleSizeAggregator(com.android.tools.build.bundletool.device.AssetModuleSizeAggregator) Variant(com.android.bundle.Commands.Variant) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) VariantTotalSizeAggregator(com.android.tools.build.bundletool.device.VariantTotalSizeAggregator) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with SizeConfiguration

use of com.android.tools.build.bundletool.model.SizeConfiguration in project bundletool by google.

the class AbstractSizeAggregator method getSizesPerConfiguration.

protected ConfigurationSizes getSizesPerConfiguration(ImmutableSet<SdkVersionTargeting> sdkTargetingOptions, ImmutableSet<AbiTargeting> abiTargetingOptions, ImmutableSet<LanguageTargeting> languageTargetingOptions, ImmutableSet<ScreenDensityTargeting> screenDensityTargetingOptions, ImmutableSet<TextureCompressionFormatTargeting> textureCompressionFormatTargetingOptions, ImmutableSet<DeviceTierTargeting> deviceTierTargetingOptions) {
    Map<SizeConfiguration, Long> minSizeByConfiguration = new HashMap<>();
    Map<SizeConfiguration, Long> maxSizeByConfiguration = new HashMap<>();
    for (SdkVersionTargeting sdkVersionTargeting : sdkTargetingOptions) {
        for (AbiTargeting abiTargeting : abiTargetingOptions) {
            for (ScreenDensityTargeting screenDensityTargeting : screenDensityTargetingOptions) {
                for (LanguageTargeting languageTargeting : languageTargetingOptions) {
                    for (TextureCompressionFormatTargeting textureCompressionFormatTargeting : textureCompressionFormatTargetingOptions) {
                        for (DeviceTierTargeting deviceTierTargeting : deviceTierTargetingOptions) {
                            SizeConfiguration configuration = mergeWithDeviceSpec(getSizeConfiguration(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting), getSizeRequest.getDeviceSpec());
                            long compressedSize = getCompressedSize(getMatchingApks(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting));
                            minSizeByConfiguration.merge(configuration, compressedSize, Math::min);
                            maxSizeByConfiguration.merge(configuration, compressedSize, Math::max);
                        }
                    }
                }
            }
        }
    }
    return ConfigurationSizes.create(/* minSizeConfigurationMap= */
    ImmutableMap.copyOf(minSizeByConfiguration), /* maxSizeConfigurationMap= */
    ImmutableMap.copyOf(maxSizeByConfiguration));
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) DeviceTierTargeting(com.android.bundle.Targeting.DeviceTierTargeting) HashMap(java.util.HashMap) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration) ScreenDensityTargeting(com.android.bundle.Targeting.ScreenDensityTargeting)

Example 4 with SizeConfiguration

use of com.android.tools.build.bundletool.model.SizeConfiguration in project bundletool by google.

the class VariantTotalSizeAggregator method getSizeStandaloneVariant.

private ConfigurationSizes getSizeStandaloneVariant() {
    checkState(!getSizeRequest.getInstant(), "Standalone Variants can't be selected when instant flag is set");
    // When modules are specified we ignore standalone variants.
    if (getSizeRequest.getModules().isPresent()) {
        return ConfigurationSizes.create(ImmutableMap.of(), ImmutableMap.of());
    }
    VariantTargeting variantTargeting = variant.getTargeting();
    SizeConfiguration sizeConfiguration = mergeWithDeviceSpec(getSizeConfiguration(variantTargeting.getSdkVersionTargeting(), variantTargeting.getAbiTargeting(), variantTargeting.getScreenDensityTargeting(), LanguageTargeting.getDefaultInstance(), variantTargeting.getTextureCompressionFormatTargeting(), DeviceTierTargeting.getDefaultInstance()), getSizeRequest.getDeviceSpec());
    // Variants of standalone APKs have only one APK each.
    long compressedSize = sizeByApkPaths.get(Iterables.getOnlyElement(Iterables.getOnlyElement(variant.getApkSetList()).getApkDescriptionList()).getPath());
    ImmutableMap<SizeConfiguration, Long> sizeConfigurationMap = ImmutableMap.of(sizeConfiguration, compressedSize);
    return ConfigurationSizes.create(sizeConfigurationMap, sizeConfigurationMap);
}
Also used : VariantTargeting(com.android.bundle.Targeting.VariantTargeting) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration)

Aggregations

SizeConfiguration (com.android.tools.build.bundletool.model.SizeConfiguration)4 BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 Variant (com.android.bundle.Commands.Variant)1 AbiTargeting (com.android.bundle.Targeting.AbiTargeting)1 DeviceTierTargeting (com.android.bundle.Targeting.DeviceTierTargeting)1 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)1 ScreenDensityTargeting (com.android.bundle.Targeting.ScreenDensityTargeting)1 SdkVersionTargeting (com.android.bundle.Targeting.SdkVersionTargeting)1 TextureCompressionFormatTargeting (com.android.bundle.Targeting.TextureCompressionFormatTargeting)1 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)1 AssetModuleSizeAggregator (com.android.tools.build.bundletool.device.AssetModuleSizeAggregator)1 VariantMatcher (com.android.tools.build.bundletool.device.VariantMatcher)1 VariantTotalSizeAggregator (com.android.tools.build.bundletool.device.VariantTotalSizeAggregator)1 ConfigurationSizes (com.android.tools.build.bundletool.model.ConfigurationSizes)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1