use of com.android.bundle.Files.NativeLibraries in project bundletool by google.
the class BuildBundleCommandTest method nativeLibrariesPresent_abiTargetingIsPresent.
@Test
public void nativeLibrariesPresent_abiTargetingIsPresent() throws Exception {
Path moduleWithAbi = new ZipBuilder().addFileWithContent(ZipPath.create("lib/x86/libfast.so"), "native data".getBytes(UTF_8)).addFileWithContent(ZipPath.create("lib/x86/libfaster.so"), "native data".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(moduleWithAbi)).build().execute();
NativeLibraries actualTargeting;
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/native.pb");
actualTargeting = NativeLibraries.parseFrom(bundle.getInputStream(new ZipEntry("base/native.pb")));
}
NativeLibraries expectedTargeting = NativeLibraries.newBuilder().addDirectory(TargetedNativeDirectory.newBuilder().setPath("lib/x86").setTargeting(NativeDirectoryTargeting.newBuilder().setAbi(Abi.newBuilder().setAlias(X86)))).build();
Truth.assertThat(actualTargeting).isEqualTo(expectedTargeting);
}
use of com.android.bundle.Files.NativeLibraries in project bundletool by google.
the class TargetingGenerator method generateTargetingForNativeLibraries.
/**
* Processes given native library directories, generating targeting based on their names.
*
* @param libDirectories Names of directories under lib/, including the "lib/" prefix.
* @return Targeting for the given native libraries directories.
*/
public NativeLibraries generateTargetingForNativeLibraries(Collection<String> libDirectories) {
NativeLibraries.Builder nativeLibraries = NativeLibraries.newBuilder();
for (String directory : libDirectories) {
checkRootDirectoryName(LIB_DIR, directory);
// Split the directory under lib/ into tokens.
String subDirName = directory.substring(LIB_DIR.length());
Abi abi = checkAbiName(subDirName, directory);
NativeDirectoryTargeting.Builder nativeBuilder = NativeDirectoryTargeting.newBuilder().setAbi(abi);
if (subDirName.equals("arm64-v8a-hwasan")) {
nativeBuilder.setSanitizer(Sanitizer.newBuilder().setAlias(SanitizerAlias.HWADDRESS));
}
nativeLibraries.addDirectory(TargetedNativeDirectory.newBuilder().setPath(directory).setTargeting(nativeBuilder).build());
}
return nativeLibraries.build();
}
use of com.android.bundle.Files.NativeLibraries in project bundletool by google.
the class TargetingGeneratorTest method generateTargetingForNativeLibraries_sanitizer.
@Test
public void generateTargetingForNativeLibraries_sanitizer() throws Exception {
NativeLibraries nativeTargeting = generator.generateTargetingForNativeLibraries(ImmutableList.of("lib/arm64-v8a-hwasan"));
List<TargetedNativeDirectory> directories = nativeTargeting.getDirectoryList();
assertThat(directories).hasSize(1);
assertThat(directories.get(0)).isEqualTo(TargetedNativeDirectory.newBuilder().setPath("lib/arm64-v8a-hwasan").setTargeting(nativeDirectoryTargeting(AbiAlias.ARM64_V8A, SanitizerAlias.HWADDRESS)).build());
}
use of com.android.bundle.Files.NativeLibraries in project bundletool by google.
the class ModuleAbiSanitizer method sanitizedModule.
private static BundleModule sanitizedModule(BundleModule module, ImmutableMultimap<ZipPath, ModuleEntry> libFilesByAbiDirToKeep) {
// Construct new module by making minimal modifications to the existing module.
BundleModule.Builder newModule = module.toBuilder();
if (module.getNativeConfig().isPresent()) {
NativeLibraries newNativeConfig = filterNativeTargeting(module.getNativeConfig().get(), libFilesByAbiDirToKeep);
newModule.setNativeConfig(newNativeConfig);
}
newModule.setEntryMap(module.getEntries().stream().filter(entry -> !entry.getPath().startsWith(LIB_DIRECTORY) || libFilesByAbiDirToKeep.containsValue(entry)).collect(toImmutableMap(ModuleEntry::getPath, Function.identity())));
return newModule.build();
}
use of com.android.bundle.Files.NativeLibraries in project bundletool by google.
the class NativeTargetingValidatorTest method validateModule_pathOutsideLib_throws.
@Test
public void validateModule_pathOutsideLib_throws() throws Exception {
NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("assets/lib/x86_64", nativeDirectoryTargeting(X86_64)));
BundleModule module = new BundleModuleBuilder("testModule").setNativeConfig(config).addFile("lib/x86/libX.so").setManifest(androidManifest("com.test.app")).build();
InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module));
assertThat(e).hasMessageThat().contains("directory must be in format 'lib/<directory>'");
}
Aggregations