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