use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class SanitizerNativeLibrariesSplitter method split.
/**
* Generates {@link ModuleSplit} objects dividing the native libraries by sanitizer.
*/
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
if (!moduleSplit.getNativeConfig().isPresent()) {
return ImmutableList.of(moduleSplit);
}
Set<ZipPath> hwasanDirs = new HashSet<>();
for (TargetedNativeDirectory dir : moduleSplit.getNativeConfig().get().getDirectoryList()) {
if (!dir.getTargeting().hasSanitizer()) {
continue;
}
if (dir.getTargeting().getSanitizer().getAlias().equals(SanitizerAlias.HWADDRESS)) {
hwasanDirs.add(ZipPath.create(dir.getPath()));
}
}
List<ModuleEntry> hwasanEntries = moduleSplit.getEntries().stream().filter(entry -> hwasanDirs.contains(entry.getPath().subpath(0, 2))).collect(toImmutableList());
if (hwasanEntries.isEmpty()) {
return ImmutableList.of(moduleSplit);
}
List<ModuleEntry> nonHwasanEntries = moduleSplit.getEntries().stream().filter(entry -> !hwasanDirs.contains(entry.getPath().subpath(0, 2))).collect(toImmutableList());
ModuleSplit hwasanSplit = moduleSplit.toBuilder().setApkTargeting(moduleSplit.getApkTargeting().toBuilder().setSanitizerTargeting(SanitizerTargeting.newBuilder().addValue(Sanitizer.newBuilder().setAlias(SanitizerAlias.HWADDRESS))).build()).setMasterSplit(false).setEntries(hwasanEntries).build();
ModuleSplit nonHwasanSplit = moduleSplit.toBuilder().setEntries(nonHwasanEntries).build();
return ImmutableList.of(hwasanSplit, nonHwasanSplit);
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class MandatoryFilesPresenceValidator method validateBundleZipFile.
@Override
public void validateBundleZipFile(ZipFile bundleFile) {
ImmutableSet<ZipPath> moduleDirectories = Collections.list(bundleFile.entries()).stream().map(ZipEntry::getName).map(ZipPath::create).filter(entryPath -> entryPath.getNameCount() > 1).map(entryPath -> entryPath.getName(0)).filter(not(nonModuleDirectories::contains)).collect(toImmutableSet());
checkBundleHasBundleConfig(bundleFile);
for (ZipPath moduleDir : moduleDirectories) {
checkModuleHasAndroidManifest(bundleFile, moduleDir, /* moduleName= */
moduleDir.toString());
}
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class NativeTargetingValidator method validateTargeting.
private static void validateTargeting(BundleModule module, NativeLibraries nativeLibraries) {
for (TargetedNativeDirectory targetedDirectory : nativeLibraries.getDirectoryList()) {
ZipPath path = ZipPath.create(targetedDirectory.getPath());
NativeDirectoryTargeting targeting = targetedDirectory.getTargeting();
if (!targeting.hasAbi()) {
throw InvalidBundleException.builder().withUserMessage("Targeted native directory '%s' does not have the ABI dimension set.", targetedDirectory.getPath()).build();
}
if (!path.startsWith(LIB_DIRECTORY) || path.getNameCount() != 2) {
throw InvalidBundleException.builder().withUserMessage("Path of targeted native directory must be in format 'lib/<directory>' but " + "found '%s'.", path).build();
}
if (BundleValidationUtils.directoryContainsNoFiles(module, path)) {
throw InvalidBundleException.builder().withUserMessage("Targeted directory '%s' is empty.", path).build();
}
}
SetView<String> libDirsWithoutTargeting = Sets.difference(module.findEntriesUnderPath(LIB_DIRECTORY).map(libFile -> libFile.getPath().subpath(0, 2).toString()).collect(toImmutableSet()), nativeLibraries.getDirectoryList().stream().map(TargetedNativeDirectory::getPath).collect(toImmutableSet()));
if (!libDirsWithoutTargeting.isEmpty()) {
throw InvalidBundleException.builder().withUserMessage("Following native directories are not targeted: %s", libDirsWithoutTargeting).build();
}
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ValidatorRunner method validateSdkBundleUsingSubValidator.
private static void validateSdkBundleUsingSubValidator(SdkBundle bundle, SubValidator subValidator) {
subValidator.validateSdkBundle(bundle);
BundleModule module = bundle.getModule();
subValidator.validateModule(module);
for (ZipPath moduleFile : getModuleFiles(module)) {
subValidator.validateModuleFile(moduleFile);
}
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class InstallApksCommandTest method localTestingMode_allModules.
@Test
@Theory
public void localTestingMode_allModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
String installTimeFeature = "installtime_feature";
String onDemandFeature = "ondemand_feature";
String installTimeAsset = "installtime_asset";
String onDemandAsset = "ondemand_asset";
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath baseEnApk = ZipPath.create("base-en.apk");
ZipPath installTimeFeatureMasterApk = ZipPath.create(installTimeFeature + "-master.apk");
ZipPath installTimeFeatureEnApk = ZipPath.create(installTimeFeature + "-en.apk");
ZipPath installTimeFeaturePlApk = ZipPath.create(installTimeFeature + "-pl.apk");
ZipPath onDemandFeatureMasterApk = ZipPath.create(onDemandFeature + "-master.apk");
ZipPath installTimeAssetMasterApk = ZipPath.create(installTimeAsset + "-master.apk");
ZipPath installTimeAssetEnApk = ZipPath.create(installTimeAsset + "-en.apk");
ZipPath onDemandAssetMasterApk = ZipPath.create(onDemandAsset + "-master.apk");
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
false)), createSplitApkSet(installTimeFeature, createMasterApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureMasterApk), createApkDescription(apkLanguageTargeting("en"), installTimeFeatureEnApk, /* isMasterSplit= */
false), createApkDescription(apkLanguageTargeting("pl"), installTimeFeaturePlApk, /* isMasterSplit= */
false)), createSplitApkSet(onDemandFeature, DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeAsset).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeAssetMasterApk)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeAssetEnApk))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandAsset).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandAssetMasterApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
Path apksFile = createApks(tableOfContent, apksInDirectory);
List<Path> installedApks = new ArrayList<>();
List<Path> pushedFiles = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("_ALL_")).build().execute();
// Base, install-time and on-demand features and install-time assets.
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), onDemandFeatureMasterApk.toString(), installTimeAssetMasterApk.toString(), installTimeAssetEnApk.toString());
// Base config splits, install-time and on-demand features and on-demand assets. All languages.
assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeFeaturePlApk.toString(), onDemandFeatureMasterApk.toString(), onDemandAssetMasterApk.toString());
}
Aggregations