Search in sources :

Example 1 with AbiName

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));
}
Also used : AbiName(com.android.tools.build.bundletool.model.AbiName) JsonObject(com.google.gson.JsonObject) ApexManifest(com.android.apex.ApexManifestProto.ApexManifest) ZipPath(com.android.tools.build.bundletool.model.ZipPath) JsonParser(com.google.gson.JsonParser) ARMEABI_V7A(com.android.tools.build.bundletool.model.AbiName.ARMEABI_V7A) JsonElement(com.google.gson.JsonElement) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) ImmutableList(com.google.common.collect.ImmutableList) ARM64_V8A(com.android.tools.build.bundletool.model.AbiName.ARM64_V8A) X86(com.android.tools.build.bundletool.model.AbiName.X86) X86_64(com.android.tools.build.bundletool.model.AbiName.X86_64) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) APEX_MANIFEST_JSON_PATH(com.android.tools.build.bundletool.model.BundleModule.APEX_MANIFEST_JSON_PATH) APEX_PUBKEY_PATH(com.android.tools.build.bundletool.model.BundleModule.APEX_PUBKEY_PATH) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ABI_SPLITTER(com.android.tools.build.bundletool.model.BundleModule.ABI_SPLITTER) ImmutableSet(com.google.common.collect.ImmutableSet) UTF_8(java.nio.charset.StandardCharsets.UTF_8) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) UncheckedIOException(java.io.UncheckedIOException) ApexImages(com.android.bundle.Files.ApexImages) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) APEX_DIRECTORY(com.android.tools.build.bundletool.model.BundleModule.APEX_DIRECTORY) APEX_NOTICE_PATH(com.android.tools.build.bundletool.model.BundleModule.APEX_NOTICE_PATH) BundleModule(com.android.tools.build.bundletool.model.BundleModule) APEX_MANIFEST_PATH(com.android.tools.build.bundletool.model.BundleModule.APEX_MANIFEST_PATH) Joiner(com.google.common.base.Joiner) InputStream(java.io.InputStream) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath)

Example 2 with AbiName

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

Example 3 with AbiName

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());
}
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) TargetedNativeDirectory(com.android.bundle.Files.TargetedNativeDirectory) NativeLibraries(com.android.bundle.Files.NativeLibraries) AbiName(com.android.tools.build.bundletool.model.AbiName) Test(org.junit.Test)

Aggregations

ApexImages (com.android.bundle.Files.ApexImages)3 TargetedApexImage (com.android.bundle.Files.TargetedApexImage)3 AbiName (com.android.tools.build.bundletool.model.AbiName)3 ZipPath (com.android.tools.build.bundletool.model.ZipPath)3 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)3 Joiner (com.google.common.base.Joiner)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Sets (com.google.common.collect.Sets)3 Assets (com.android.bundle.Files.Assets)2 NativeLibraries (com.android.bundle.Files.NativeLibraries)2 TargetedAssetsDirectory (com.android.bundle.Files.TargetedAssetsDirectory)2 TargetedNativeDirectory (com.android.bundle.Files.TargetedNativeDirectory)2 AbiAlias (com.android.bundle.Targeting.Abi.AbiAlias)2 AssetsDirectoryTargeting (com.android.bundle.Targeting.AssetsDirectoryTargeting)2 SanitizerAlias (com.android.bundle.Targeting.Sanitizer.SanitizerAlias)2 TextureCompressionFormatAlias (com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias)2 TargetingUtils.alternativeLanguageTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting)2 TargetingUtils.assetsDirectoryTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting)2