use of com.android.tools.build.bundletool.model.AbiName in project bundletool by google.
the class ApexBundleValidator method validateModule.
@Override
public void validateModule(BundleModule module) {
if (module.findEntriesUnderPath(APEX_DIRECTORY).count() == 0) {
return;
}
Optional<ModuleEntry> apexManifest = module.getEntry(APEX_MANIFEST_PATH);
if (apexManifest.isPresent()) {
validateApexManifest(apexManifest.get());
} else {
apexManifest = module.getEntry(APEX_MANIFEST_JSON_PATH);
if (!apexManifest.isPresent()) {
throw InvalidBundleException.builder().withUserMessage("Missing expected file in APEX bundle: '%s' or '%s'.", APEX_MANIFEST_PATH, APEX_MANIFEST_JSON_PATH).build();
}
validateApexManifestJson(apexManifest.get());
}
ImmutableSet.Builder<String> apexImagesBuilder = ImmutableSet.builder();
ImmutableSet.Builder<String> apexBuildInfosBuilder = ImmutableSet.builder();
ImmutableSet.Builder<String> apexFileNamesBuilder = ImmutableSet.builder();
for (ModuleEntry entry : module.getEntries()) {
ZipPath path = entry.getPath();
if (path.startsWith(APEX_DIRECTORY)) {
if (path.getFileName().toString().endsWith(BundleModule.APEX_IMAGE_SUFFIX)) {
apexImagesBuilder.add(path.toString());
apexFileNamesBuilder.add(path.getFileName().toString());
} else if (path.getFileName().toString().endsWith(BundleModule.BUILD_INFO_SUFFIX)) {
apexBuildInfosBuilder.add(path.toString());
} else {
throw InvalidBundleException.builder().withUserMessage("Unexpected file in apex directory of bundle: '%s'.", entry.getPath()).build();
}
} else if (!ALLOWED_APEX_FILES_OUTSIDE_APEX_DIRECTORY.contains(path)) {
throw InvalidBundleException.builder().withUserMessage("Unexpected file in APEX bundle: '%s'.", entry.getPath()).build();
}
}
ImmutableSet<String> apexBuildInfos = apexBuildInfosBuilder.build();
ImmutableSet<String> apexImages = apexImagesBuilder.build();
ImmutableSet<ImmutableSet<AbiName>> allAbiNameSets = apexFileNamesBuilder.build().stream().map(ApexBundleValidator::abiNamesFromFile).collect(toImmutableSet());
if (allAbiNameSets.size() != apexImages.size()) {
throw InvalidBundleException.builder().withUserMessage("Every APEX image file must target a unique set of architectures, " + "but found multiple files that target the same set of architectures.").build();
}
ImmutableSet<String> expectedImages = apexBuildInfos.stream().map(f -> f.replace(BundleModule.BUILD_INFO_SUFFIX, BundleModule.APEX_IMAGE_SUFFIX)).collect(toImmutableSet());
if (!apexBuildInfos.isEmpty() && !expectedImages.equals(apexImages)) {
throw InvalidBundleException.builder().withUserMessage("If APEX build info is provided then one must be provided for each APEX image file:\n" + " Expected %s\n" + " Found %s.", expectedImages, apexImages).build();
}
if (REQUIRED_ONE_OF_ABI_SETS.stream().anyMatch(one_of -> one_of.stream().noneMatch(allAbiNameSets::contains))) {
throw InvalidBundleException.builder().withUserMessage("APEX bundle must contain one of %s.", Joiner.on(" and one of ").join(REQUIRED_ONE_OF_ABI_SETS)).build();
}
module.getApexConfig().ifPresent(targeting -> validateTargeting(apexImages, targeting));
}
use of com.android.tools.build.bundletool.model.AbiName 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());
}
use of com.android.tools.build.bundletool.model.AbiName in project bundletool by google.
the class TargetingGeneratorTest method generateTargetingForNativeLibraries_createsSingleDirectoryGroup.
@Test
public void generateTargetingForNativeLibraries_createsSingleDirectoryGroup() throws Exception {
Collection<String> manyDirectories = Arrays.stream(AbiName.values()).map(AbiName::getPlatformName).map(abi -> "lib/" + abi).collect(toImmutableList());
// Otherwise this test is useless.
checkState(manyDirectories.size() > 1);
NativeLibraries nativeTargeting = generator.generateTargetingForNativeLibraries(manyDirectories);
List<TargetedNativeDirectory> directories = nativeTargeting.getDirectoryList();
assertThat(directories).hasSize(manyDirectories.size());
}
Aggregations