Search in sources :

Example 21 with NativeLibraries

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

the class NativeTargetingValidatorTest method validateModule_emptyTargetedDirectory_throws.

@Test
public void validateModule_emptyTargetedDirectory_throws() throws Exception {
    NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)));
    BundleModule module = new BundleModuleBuilder("testModule").setNativeConfig(config).addFile("lib/x86/libX.so").addFile("lib/x86_64/libX.so").setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module));
    assertThat(e).hasMessageThat().contains("Targeted directory 'lib/mips' is empty.");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 22 with NativeLibraries

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

the class ModuleAbiSanitizerTest method consistentNativeLibraries_moduleUnchanged.

@Test
public void consistentNativeLibraries_moduleUnchanged() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)));
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("lib/x86/lib1.so").addFile("lib/x86/lib2.so").addFile("lib/x86/lib3.so").addFile("lib/x86_64/lib1.so").addFile("lib/x86_64/lib2.so").addFile("lib/x86_64/lib3.so").addFile("lib/mips/lib1.so").addFile("lib/mips/lib2.so").addFile("lib/mips/lib3.so").setNativeConfig(nativeConfig).setManifest(androidManifest("com.test.app")).build();
    BundleModule sanitizedModule = new ModuleAbiSanitizer().sanitize(testModule);
    assertThat(sanitizedModule.getNativeConfig().get()).isEqualTo(testModule.getNativeConfig().get());
    assertThat(sanitizedModule.getEntries()).containsExactlyElementsIn(testModule.getEntries());
    // Sanity check that nothing else changed as well.
    assertThat(sanitizedModule).isEqualTo(testModule);
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) Test(org.junit.Test)

Example 23 with NativeLibraries

use of com.android.bundle.Files.NativeLibraries 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)

Example 24 with NativeLibraries

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

the class BundleModuleTest method correctNativeProtoFile_parsedAndReturned.

@Test
public void correctNativeProtoFile_parsedAndReturned() throws Exception {
    NativeLibraries nativeConfig = NativeLibraries.newBuilder().addDirectory(TargetedNativeDirectory.newBuilder().setPath("native/x86")).build();
    BundleModule bundleModule = createMinimalModuleBuilder().addEntry(createModuleEntryForFile("native.pb", nativeConfig.toByteArray())).build();
    assertThat(bundleModule.getNativeConfig()).hasValue(nativeConfig);
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) Test(org.junit.Test)

Example 25 with NativeLibraries

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

the class SameTargetingMerger method mergeSplits.

private ModuleSplit mergeSplits(ImmutableCollection<ModuleSplit> splits) {
    ModuleSplit.Builder builder = ModuleSplit.builder();
    ImmutableList.Builder<ModuleEntry> entries = ImmutableList.builder();
    AndroidManifest mergedManifest = null;
    ResourceTable mergedResourceTable = null;
    NativeLibraries mergedNativeConfig = null;
    Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
    ApexImages mergedApexConfig = null;
    ImmutableList<ApexEmbeddedApkConfig> mergedApexEmbeddedApkConfigs = null;
    BundleModuleName mergedModuleName = null;
    Boolean mergedIsMasterSplit = null;
    VariantTargeting mergedVariantTargeting = null;
    for (ModuleSplit split : splits) {
        mergedManifest = getSameValueOrNonNull(mergedManifest, split.getAndroidManifest()).orElseThrow(() -> new IllegalStateException("Encountered two distinct manifests while merging."));
        if (split.getResourceTable().isPresent()) {
            mergedResourceTable = getSameValueOrNonNull(mergedResourceTable, split.getResourceTable().get()).orElseThrow(() -> new IllegalStateException("Unsupported case: encountered two distinct resource tables while " + "merging."));
        }
        if (split.getNativeConfig().isPresent()) {
            mergedNativeConfig = getSameValueOrNonNull(mergedNativeConfig, split.getNativeConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct native configs while merging."));
        }
        if (split.getApexConfig().isPresent()) {
            mergedApexConfig = getSameValueOrNonNull(mergedApexConfig, split.getApexConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex configs while merging."));
        }
        mergedApexEmbeddedApkConfigs = getSameValueOrNonNull(mergedApexEmbeddedApkConfigs, split.getApexEmbeddedApkConfigs()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex embedded apk configs while merging."));
        mergedModuleName = getSameValueOrNonNull(mergedModuleName, split.getModuleName()).orElseThrow(() -> new IllegalStateException("Encountered two distinct module names while merging."));
        mergedIsMasterSplit = getSameValueOrNonNull(mergedIsMasterSplit, Boolean.valueOf(split.isMasterSplit())).orElseThrow(() -> new IllegalStateException("Encountered conflicting isMasterSplit flag values while merging."));
        mergedVariantTargeting = getSameValueOrNonNull(mergedVariantTargeting, split.getVariantTargeting()).orElseThrow(() -> new IllegalStateException("Encountered conflicting variant targeting values while merging."));
        entries.addAll(split.getEntries());
        builder.setApkTargeting(split.getApkTargeting());
        split.getAssetsConfig().ifPresent(assetsConfig -> {
            mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
        });
    }
    if (mergedManifest != null) {
        builder.setAndroidManifest(mergedManifest);
    }
    if (mergedResourceTable != null) {
        builder.setResourceTable(mergedResourceTable);
    }
    if (mergedNativeConfig != null) {
        builder.setNativeConfig(mergedNativeConfig);
    }
    if (!mergedAssetsConfig.isEmpty()) {
        builder.setAssetsConfig(Assets.newBuilder().addAllDirectory(mergedAssetsConfig.values()).build());
    }
    if (mergedApexConfig != null) {
        builder.setApexConfig(mergedApexConfig);
    }
    if (mergedApexEmbeddedApkConfigs != null) {
        builder.setApexEmbeddedApkConfigs(mergedApexEmbeddedApkConfigs);
    }
    if (mergedModuleName != null) {
        builder.setModuleName(mergedModuleName);
    }
    if (mergedIsMasterSplit != null) {
        builder.setMasterSplit(mergedIsMasterSplit);
    }
    builder.setVariantTargeting(mergedVariantTargeting);
    builder.setEntries(entries.build());
    return builder.build();
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) TargetedAssetsDirectory(com.android.bundle.Files.TargetedAssetsDirectory) NativeLibraries(com.android.bundle.Files.NativeLibraries) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ApexEmbeddedApkConfig(com.android.bundle.Config.ApexEmbeddedApkConfig) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ResourceTable(com.android.aapt.Resources.ResourceTable)

Aggregations

NativeLibraries (com.android.bundle.Files.NativeLibraries)26 Test (org.junit.Test)22 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)18 BundleModule (com.android.tools.build.bundletool.model.BundleModule)17 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)10 ZipPath (com.android.tools.build.bundletool.model.ZipPath)6 Assets (com.android.bundle.Files.Assets)5 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)5 TargetingUtils.nativeDirectoryTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting)5 ResourceTable (com.android.aapt.Resources.ResourceTable)4 AbiAlias (com.android.bundle.Targeting.Abi.AbiAlias)4 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)4 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)4 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)4 AppBundle (com.android.tools.build.bundletool.model.AppBundle)4 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)4 StampType (com.android.tools.build.bundletool.model.SourceStamp.StampType)4 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)4 TargetingUtils.mergeApkTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting)4 TargetingUtils.nativeLibraries (com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries)4