Search in sources :

Example 11 with ZipPath

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);
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Sanitizer(com.android.bundle.Targeting.Sanitizer) ImmutableCollection(com.google.common.collect.ImmutableCollection) Set(java.util.Set) SanitizerTargeting(com.android.bundle.Targeting.SanitizerTargeting) HashSet(java.util.HashSet) List(java.util.List) SanitizerAlias(com.android.bundle.Targeting.Sanitizer.SanitizerAlias) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) TargetedNativeDirectory(com.android.bundle.Files.TargetedNativeDirectory) TargetedNativeDirectory(com.android.bundle.Files.TargetedNativeDirectory) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ZipPath(com.android.tools.build.bundletool.model.ZipPath) HashSet(java.util.HashSet)

Example 12 with ZipPath

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());
    }
}
Also used : SpecialModuleEntry(com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry) ImmutableSet(com.google.common.collect.ImmutableSet) Predicates.not(com.google.common.base.Predicates.not) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Files(com.google.common.io.Files) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ZipFile(java.util.zip.ZipFile) AppBundle(com.android.tools.build.bundletool.model.AppBundle) Collections(java.util.Collections) ZipEntry(java.util.zip.ZipEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath)

Example 13 with ZipPath

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();
    }
}
Also used : NativeDirectoryTargeting(com.android.bundle.Targeting.NativeDirectoryTargeting) TargetedNativeDirectory(com.android.bundle.Files.TargetedNativeDirectory) ZipPath(com.android.tools.build.bundletool.model.ZipPath)

Example 14 with ZipPath

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);
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 15 with ZipPath

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());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Aggregations

ZipPath (com.android.tools.build.bundletool.model.ZipPath)194 Test (org.junit.Test)154 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 Path (java.nio.file.Path)55 DeviceSpec (com.android.bundle.Devices.DeviceSpec)44 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)23 ImmutableSet (com.google.common.collect.ImmutableSet)23 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)19 Variant (com.android.bundle.Commands.Variant)16 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)15 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)10 Theory (org.junit.experimental.theories.Theory)10 AdbServer (com.android.tools.build.bundletool.device.AdbServer)9 IOException (java.io.IOException)9 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)8 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 UncheckedIOException (java.io.UncheckedIOException)8