Search in sources :

Example 6 with NativeLibraries

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

the class SanitizerNativeLibrariesSplitterTest method splittingNoSanitizerLib.

@Test
public void splittingNoSanitizerLib() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").setManifest(androidManifest("com.test.app")).build();
    SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
    ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
    ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
    assertThat(splits).hasSize(1);
    ModuleSplit nonHwasanSplit = splits.asList().get(0);
    assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
    assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 7 with NativeLibraries

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

the class SanitizerNativeLibrariesSplitterTest method splittingBySanitizer.

@Test
public void splittingBySanitizer() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").addFile("lib/arm64-v8a-hwasan/libtest.so").setManifest(androidManifest("com.test.app")).build();
    SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
    ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
    ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
    assertThat(splits).hasSize(2);
    ModuleSplit nonHwasanSplit = splits.asList().get(1);
    assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
    assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
    ModuleSplit hwasanSplit = splits.asList().get(0);
    assertThat(hwasanSplit.getApkTargeting()).isEqualTo(mergeApkTargeting(apkAbiTargeting(ARM64_V8A), apkSanitizerTargeting(HWADDRESS)));
    assertThat(extractPaths(hwasanSplit.getEntries())).containsExactly("lib/arm64-v8a-hwasan/libtest.so");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 8 with NativeLibraries

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

the class ModuleSplitterTest method nativeSplits_areGenerated.

@Test
public void nativeSplits_areGenerated() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting("x86")));
    BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeConfig).addFile("lib/x86/liba.so").build();
    ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(testModule).splitModule();
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
    assertThat(splits).hasSize(2);
    boolean hasMasterSplit = false;
    boolean hasX86Split = false;
    ApkTargeting x86SplitTargeting = mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkAbiTargeting(AbiAlias.X86));
    for (ModuleSplit split : splits) {
        if (split.getApkTargeting().equals(DEFAULT_MASTER_SPLIT_SDK_TARGETING)) {
            assertThat(split.isMasterSplit()).isTrue();
            hasMasterSplit = true;
        } else if (split.getApkTargeting().equals(x86SplitTargeting)) {
            assertThat(split.isMasterSplit()).isFalse();
            hasX86Split = true;
        } else {
            fail(String.format("Unexpected split targeting: %s", split.getApkTargeting()));
        }
    }
    assertThat(hasMasterSplit).isTrue();
    assertThat(hasX86Split).isTrue();
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 9 with NativeLibraries

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

the class AbiNativeLibrariesSplitterTest method splittingByMultipleAbis.

@Test
public void splittingByMultipleAbis() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("lib/x86/libtest.so").addFile("lib/x86_64/libtest.so").setNativeConfig(nativeConfig).setManifest(androidManifest("com.test.app")).build();
    AbiNativeLibrariesSplitter abiNativeLibrariesSplitter = new AbiNativeLibrariesSplitter();
    ImmutableCollection<ModuleSplit> splits = abiNativeLibrariesSplitter.split(ModuleSplit.forNativeLibraries(bundleModule));
    assertThat(splits).hasSize(2);
    assertThat(splits.stream().map(ModuleSplit::getApkTargeting).collect(toList())).containsExactly(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), apkAbiTargeting(X86_64, ImmutableSet.of(X86)));
    for (ModuleSplit split : splits) {
        if (split.getApkTargeting().equals(apkAbiTargeting(ImmutableSet.of(X86), ImmutableSet.of(X86_64)))) {
            assertThat(extractPaths(split.getEntries())).containsExactly("lib/x86/libtest.so");
        }
        if (split.getApkTargeting().equals(apkAbiTargeting(ImmutableSet.of(X86_64), ImmutableSet.of(X86)))) {
            assertThat(extractPaths(split.getEntries())).containsExactly("lib/x86_64/libtest.so");
        }
    }
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 10 with NativeLibraries

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

the class ModuleAbiSanitizerTest method inconsistentNativeLibraries_libFilesFilteredAwayAndNativeTargetingAdjusted.

@Test
public void inconsistentNativeLibraries_libFilesFilteredAwayAndNativeTargetingAdjusted() 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/mips/lib1.so").setNativeConfig(nativeConfig).setManifest(androidManifest("com.test.app")).build();
    BundleModule sanitizedModule = new ModuleAbiSanitizer().sanitize(testModule);
    assertThat(sanitizedModule.getEntries().stream().map(ModuleEntry::getPath).filter(entryPath -> entryPath.startsWith(ZipPath.create("lib"))).map(ZipPath::toString)).containsExactly("lib/x86/lib1.so", "lib/x86/lib2.so", "lib/x86/lib3.so");
    assertThat(sanitizedModule.getNativeConfig().get()).isEqualTo(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86))));
}
Also used : X86(com.android.bundle.Targeting.Abi.AbiAlias.X86) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) X86_64(com.android.bundle.Targeting.Abi.AbiAlias.X86_64) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) NativeLibraries(com.android.bundle.Files.NativeLibraries) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) MIPS(com.android.bundle.Targeting.Abi.AbiAlias.MIPS) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) Test(org.junit.Test)

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