Search in sources :

Example 1 with TargetedApexImage

use of com.android.bundle.Files.TargetedApexImage in project bundletool by google.

the class TargetingUtilsTest method targetedApexImage.

@Test
public void targetedApexImage() {
    ApexImageTargeting targeting = ApexImageTargeting.newBuilder().setMultiAbi(MULTI_ABI_WITH_ALTERNATIVES).build();
    TargetedApexImage apexImage = TargetingUtils.targetedApexImage("path", targeting);
    assertThat(apexImage.getPath()).isEqualTo("path");
    assertThat(apexImage.getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(targeting);
}
Also used : ApexImageTargeting(com.android.bundle.Targeting.ApexImageTargeting) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Test(org.junit.Test)

Example 2 with TargetedApexImage

use of com.android.bundle.Files.TargetedApexImage in project bundletool by google.

the class AbiApexImagesSplitter method split.

/**
 * Generates {@link ModuleSplit} objects dividing the APEX images by ABI.
 */
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
    if (!moduleSplit.isApex()) {
        return ImmutableList.of(moduleSplit);
    }
    List<TargetedApexImage> allTargetedImages = moduleSplit.getApexConfig().get().getImageList();
    // A set of all MultiAbis (flattened for repeated values) for easy generation of alternatives.
    ImmutableSet<MultiAbi> allTargeting = allTargetedImages.stream().flatMap(image -> image.getTargeting().getMultiAbi().getValueList().stream()).collect(toImmutableSet());
    // This prevents O(n^2).
    ImmutableMap<String, ModuleEntry> apexPathToEntryMap = buildApexPathToEntryMap(allTargetedImages, moduleSplit);
    ImmutableList.Builder<ModuleSplit> splits = new ImmutableList.Builder<>();
    for (TargetedApexImage targetedApexImage : allTargetedImages) {
        ModuleEntry entry = apexPathToEntryMap.get(targetedApexImage.getPath());
        List<MultiAbi> targeting = targetedApexImage.getTargeting().getMultiAbi().getValueList();
        ModuleSplit.Builder splitBuilder = moduleSplit.toBuilder().setApkTargeting(moduleSplit.getApkTargeting().toBuilder().setMultiAbiTargeting(MultiAbiTargeting.newBuilder().addAllValue(targeting).addAllAlternatives(Sets.difference(allTargeting, ImmutableSet.copyOf(targeting)))).build()).setMasterSplit(false).setEntries(targetedApexImage.getBuildInfoPath().isEmpty() ? ImmutableList.of(entry) : ImmutableList.of(entry, apexPathToEntryMap.get(targetedApexImage.getBuildInfoPath())));
        splits.add(splitBuilder.build());
    }
    return splits.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableCollection(com.google.common.collect.ImmutableCollection) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Stream(java.util.stream.Stream) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) Function.identity(java.util.function.Function.identity) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) MultiAbi(com.android.bundle.Targeting.MultiAbi) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) MultiAbi(com.android.bundle.Targeting.MultiAbi)

Example 3 with TargetedApexImage

use of com.android.bundle.Files.TargetedApexImage in project bundletool by google.

the class TargetingUtilsTest method apexImages.

@Test
public void apexImages() {
    TargetedApexImage firstTargeting = TargetedApexImage.newBuilder().setPath("path1").build();
    TargetedApexImage secondTargeting = TargetedApexImage.newBuilder().setPath("path2").build();
    ApexImages apexImages = TargetingUtils.apexImages(firstTargeting, secondTargeting);
    assertThat(apexImages.getImageList()).containsExactly(firstTargeting, secondTargeting);
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Test(org.junit.Test)

Example 4 with TargetedApexImage

use of com.android.bundle.Files.TargetedApexImage in project bundletool by google.

the class TargetingGeneratorTest method generateTargetingForApexImages_createsAllTargeting.

@Test
public void generateTargetingForApexImages_createsAllTargeting() throws Exception {
    ImmutableSet<String> abis = Arrays.stream(AbiName.values()).map(AbiName::getPlatformName).collect(toImmutableSet());
    Set<String> abiPairs = Sets.cartesianProduct(abis, abis).stream().map(pair -> Joiner.on('.').join(pair)).collect(toImmutableSet());
    Collection<ZipPath> allAbiFiles = Sets.union(abis, abiPairs).stream().map(abi -> ZipPath.create(abi + ".img")).collect(toImmutableList());
    // Otherwise this test is useless.
    checkState(allAbiFiles.size() > 1);
    ApexImages apexImages = generator.generateTargetingForApexImages(allAbiFiles, /*hasBuildInfo=*/
    true);
    List<TargetedApexImage> images = apexImages.getImageList();
    assertThat(images).hasSize(allAbiFiles.size());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AbiName(com.android.tools.build.bundletool.model.AbiName) Arrays(java.util.Arrays) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) RunWith(org.junit.runner.RunWith) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) TargetingUtils.deviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.deviceTierTargeting) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) ImmutableList(com.google.common.collect.ImmutableList) AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) TargetingUtils.mergeAssetsTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeAssetsTargeting) ImmutableSet(com.google.common.collect.ImmutableSet) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) NativeLibraries(com.android.bundle.Files.NativeLibraries) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) ApexImages(com.android.bundle.Files.ApexImages) List(java.util.List) SanitizerAlias(com.android.bundle.Targeting.Sanitizer.SanitizerAlias) TargetedAssetsDirectory(com.android.bundle.Files.TargetedAssetsDirectory) Assets(com.android.bundle.Files.Assets) TargetedNativeDirectory(com.android.bundle.Files.TargetedNativeDirectory) TextureCompressionFormatAlias(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) Joiner(com.google.common.base.Joiner) ApexImages(com.android.bundle.Files.ApexImages) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Test(org.junit.Test)

Aggregations

TargetedApexImage (com.android.bundle.Files.TargetedApexImage)4 Test (org.junit.Test)3 ApexImages (com.android.bundle.Files.ApexImages)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 Sets (com.google.common.collect.Sets)2 List (java.util.List)2 Assets (com.android.bundle.Files.Assets)1 NativeLibraries (com.android.bundle.Files.NativeLibraries)1 TargetedAssetsDirectory (com.android.bundle.Files.TargetedAssetsDirectory)1 TargetedNativeDirectory (com.android.bundle.Files.TargetedNativeDirectory)1 AbiAlias (com.android.bundle.Targeting.Abi.AbiAlias)1 ApexImageTargeting (com.android.bundle.Targeting.ApexImageTargeting)1 AssetsDirectoryTargeting (com.android.bundle.Targeting.AssetsDirectoryTargeting)1 MultiAbi (com.android.bundle.Targeting.MultiAbi)1 MultiAbiTargeting (com.android.bundle.Targeting.MultiAbiTargeting)1 SanitizerAlias (com.android.bundle.Targeting.Sanitizer.SanitizerAlias)1 TextureCompressionFormatAlias (com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias)1 AbiName (com.android.tools.build.bundletool.model.AbiName)1