Skip to content

Commit

Permalink
Prepare for release 0.10.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitish Chappidi committed Jul 19, 2019
1 parent b2542c9 commit 2e9ac4e
Show file tree
Hide file tree
Showing 54 changed files with 1,643 additions and 366 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ https://developer.android.com/studio/command-line/bundletool

## Releases

Latest release: [0.10.1](https://github.com/google/bundletool/releases)
Latest release: [0.10.2](https://github.com/google/bundletool/releases)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = 0.10.1
release_version = 0.10.2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public final boolean isAnySystemMode() {
private static final Flag<Boolean> CONNECTED_DEVICE_FLAG = Flag.booleanFlag("connected-device");
private static final Flag<String> DEVICE_ID_FLAG = Flag.string("device-id");
private static final String ANDROID_SERIAL_VARIABLE = "ANDROID_SERIAL";
private static final Flag<ImmutableSet<String>> MODULES_FLAG = Flag.stringSet("modules");

private static final Flag<Path> DEVICE_SPEC_FLAG = Flag.path("device-spec");

Expand All @@ -131,6 +132,8 @@ public final boolean isAnySystemMode() {

public abstract ImmutableSet<OptimizationDimension> getOptimizationDimensions();

public abstract ImmutableSet<String> getModules();

public abstract Optional<DeviceSpec> getDeviceSpec();

public abstract boolean getGenerateOnlyForConnectedDevice();
Expand Down Expand Up @@ -174,7 +177,8 @@ public static Builder builder() {
.setApkBuildMode(DEFAULT)
.setGenerateOnlyForConnectedDevice(false)
.setCreateApkSetArchive(true)
.setOptimizationDimensions(ImmutableSet.of());
.setOptimizationDimensions(ImmutableSet.of())
.setModules(ImmutableSet.of());
}

/** Builder for the {@link BuildApksCommand}. */
Expand Down Expand Up @@ -211,6 +215,8 @@ public abstract Builder setOptimizationDimensions(
*/
public abstract Builder setGenerateOnlyForConnectedDevice(boolean onlyForConnectedDevice);

public abstract Builder setModules(ImmutableSet<String> modules);

/** Sets the {@link DeviceSpec} for which the only the matching APKs will be generated. */
public abstract Builder setDeviceSpec(DeviceSpec deviceSpec);

Expand Down Expand Up @@ -384,6 +390,17 @@ public BuildApksCommand build() {
}
}

if (!command.getModules().isEmpty()
&& !command.getApkBuildMode().isAnySystemMode()
&& !command.getApkBuildMode().equals(UNIVERSAL)) {
throw ValidationException.builder()
.withMessage(
"Modules can be only set when running with '%s', '%s' or '%s' mode flag.",
UNIVERSAL.getLowerCaseName(),
SYSTEM.getLowerCaseName(),
SYSTEM_COMPRESSED.getLowerCaseName())
.build();
}
return command;
}
}
Expand Down Expand Up @@ -493,6 +510,8 @@ static BuildApksCommand fromFlags(
.map(deviceSpecParser)
.ifPresent(buildApksCommand::setDeviceSpec);

MODULES_FLAG.getValue(flags).ifPresent(buildApksCommand::setModules);

flags.checkNoUnknownFlags();

return buildApksCommand.build();
Expand Down Expand Up @@ -692,6 +711,18 @@ public static CommandHelp help() {
MODE_FLAG.getName(),
DEFAULT.getLowerCaseName())
.build())
.addFlag(
FlagDescription.builder()
.setFlagName(MODULES_FLAG.getName())
.setExampleValue("base,module1,module2")
.setOptional(true)
.setDescription(
"List of module names to include in the generated APK Set in modes %s, %s and "
+ "%s.",
UNIVERSAL.getLowerCaseName(),
SYSTEM.getLowerCaseName(),
SYSTEM_COMPRESSED.getLowerCaseName())
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package com.android.tools.build.bundletool.commands;

import static com.android.tools.build.bundletool.model.utils.ModuleDependenciesUtils.getModulesIncludingDependencies;
import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist;
import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndExecutable;
import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;

import com.android.bundle.Config.BundleConfig;
import com.android.bundle.Config.Compression;
Expand All @@ -41,6 +43,7 @@
import com.android.tools.build.bundletool.model.ApkModifier;
import com.android.tools.build.bundletool.model.AppBundle;
import com.android.tools.build.bundletool.model.BundleModule;
import com.android.tools.build.bundletool.model.BundleModuleName;
import com.android.tools.build.bundletool.model.GeneratedApks;
import com.android.tools.build.bundletool.model.GeneratedAssetSlices;
import com.android.tools.build.bundletool.model.ModuleSplit;
Expand All @@ -61,6 +64,7 @@
import com.android.tools.build.bundletool.splitters.SplitApksGenerator;
import com.android.tools.build.bundletool.validation.AppBundleValidator;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -133,6 +137,12 @@ private void executeWithZip(ZipFile bundleZip, Optional<DeviceSpec> deviceSpec)
+ "APKs.");
}

ImmutableSet<BundleModule> requestedModules =
command.getModules().isEmpty()
? ImmutableSet.of()
: getModulesIncludingDependencies(
appBundle, getBundleModules(appBundle, command.getModules()));

BundleConfig bundleConfig = appBundle.getBundleConfig();
Version bundleVersion = BundleToolVersion.getVersionFromBundleConfig(bundleConfig);

Expand Down Expand Up @@ -160,28 +170,22 @@ private void executeWithZip(ZipFile bundleZip, Optional<DeviceSpec> deviceSpec)
// Universal APK
if (apksToGenerate.generateUniversalApk()) {
// Note: Universal APK is a special type of standalone, with no optimization dimensions.
ImmutableList<BundleModule> featureModules = appBundle.getFeatureModules().values().asList();
ImmutableList<BundleModule> modulesToFuse =
requestedModules.isEmpty()
? modulesToFuse(appBundle.getFeatureModules().values().asList())
: requestedModules.asList();
generatedApksBuilder.setStandaloneApks(
new ShardedApksGenerator(tempDir, bundleVersion)
.generateSplits(
modulesToFuse(featureModules),
modulesToFuse,
appBundle.getBundleMetadata(),
ApkOptimizations.getOptimizationsForUniversalApk()));
}

// System APKs
if (apksToGenerate.generateSystemApks()) {
ImmutableList<BundleModule> featureModules = appBundle.getFeatureModules().values().asList();
generatedApksBuilder.setSystemApks(
new ShardedApksGenerator(
tempDir,
bundleVersion,
/* generate64BitShards= */ !appBundle.has32BitRenderscriptCode())
.generateSystemSplits(
featureModules,
appBundle.getBundleMetadata(),
getApkOptimizations(bundleConfig),
deviceSpec));
generateSystemApks(appBundle, deviceSpec, requestedModules));
}

// Asset Slices
Expand Down Expand Up @@ -289,6 +293,28 @@ private ImmutableList<ModuleSplit> generateSplitApks(AppBundle appBundle) throws
.generateSplits();
}

private ImmutableList<ModuleSplit> generateSystemApks(
AppBundle appBundle,
Optional<DeviceSpec> deviceSpec,
ImmutableSet<BundleModule> requestedModules) {
Version bundleVersion = Version.of(appBundle.getBundleConfig().getBundletool().getVersion());
ImmutableList<BundleModule> featureModules = appBundle.getFeatureModules().values().asList();
ImmutableList<BundleModule> modulesToFuse =
requestedModules.isEmpty() ? modulesToFuse(featureModules) : requestedModules.asList();
return new ShardedApksGenerator(
tempDir,
bundleVersion,
/* generate64BitShards= */ !appBundle.has32BitRenderscriptCode())
.generateSystemSplits(
/* modules= */ featureModules,
/* modulesToFuse= */ modulesToFuse.stream()
.map(BundleModule::getName)
.collect(toImmutableSet()),
appBundle.getBundleMetadata(),
getApkOptimizations(appBundle.getBundleConfig()),
deviceSpec);
}

private static void checkDeviceCompatibilityWithBundle(
GeneratedApks generatedApks, DeviceSpec deviceSpec) {
ApkMatcher apkMatcher = new ApkMatcher(deviceSpec);
Expand Down Expand Up @@ -371,7 +397,7 @@ private ApkGenerationConfiguration getAssetSliceGenerationConfiguration() {
.build();
}

private ImmutableList<BundleModule> modulesToFuse(ImmutableList<BundleModule> modules) {
private static ImmutableList<BundleModule> modulesToFuse(ImmutableList<BundleModule> modules) {
return modules.stream().filter(BundleModule::isIncludedInFusing).collect(toImmutableList());
}

Expand Down Expand Up @@ -411,6 +437,14 @@ private static boolean targetsPreL(AppBundle bundle) {
return baseMinSdkVersion < Versions.ANDROID_L_API_VERSION;
}

private static ImmutableList<BundleModule> getBundleModules(
AppBundle appBundle, ImmutableSet<String> moduleNames) {
return moduleNames.stream()
.map(BundleModuleName::create)
.map(appBundle::getModule)
.collect(toImmutableList());
}

private static class ApksToGenerate {
private final AppBundle appBundle;
private final ApkBuildMode apkBuildMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.android.tools.build.bundletool.model.BundleModuleName;
import com.android.tools.build.bundletool.model.ResourceTableEntry;
import com.android.tools.build.bundletool.model.ZipPath;
import com.android.tools.build.bundletool.model.exceptions.BundleInvalidZipException;
import com.android.tools.build.bundletool.model.exceptions.ValidationException;
import com.android.tools.build.bundletool.model.utils.ResourcesUtils;
import com.android.tools.build.bundletool.model.utils.ZipUtils;
Expand All @@ -49,6 +50,7 @@
import java.util.Optional;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
Expand Down Expand Up @@ -159,6 +161,8 @@ private static <T> T extractAndParse(
Path bundlePath, ZipPath filePath, ProtoParser<T> protoParser) {
try (ZipFile zipFile = new ZipFile(bundlePath.toFile())) {
return extractAndParse(zipFile, filePath, protoParser);
} catch (ZipException e) {
throw new BundleInvalidZipException(e);
} catch (IOException e) {
throw new UncheckedIOException("Error occurred when trying to open the bundle.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,21 @@ public Builder setDeviceSpec(Path deviceSpecPath) {
public abstract Builder setInstant(boolean instant);


public abstract ExtractApksCommand build();
abstract ExtractApksCommand autoBuild();

/**
* Builds the command
*
* @throws ValidationException if the device spec is invalid. See {@link
* DeviceSpecParser#validateDeviceSpec}
*/
public ExtractApksCommand build() {
ExtractApksCommand command = autoBuild();
DeviceSpecParser.validateDeviceSpec(
command.getDeviceSpec(),
/* canSkipFields= */ true); // Allow partial device spec for APEX bundles
return command;
}
}

public static ExtractApksCommand fromFlags(ParsedFlags flags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void writeDeviceSpecToFile(DeviceSpec deviceSpec, Path outputFile) {
}

Path outputDirectory = getOutputPath().getParent();
if (!Files.exists(outputDirectory)) {
if (outputDirectory != null && !Files.exists(outputDirectory)) {
logger.info("Output directory '" + outputDirectory + "' does not exist, creating it.");
Files.createDirectories(outputDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.android.tools.build.bundletool.model.exceptions.ValidationException;
import com.android.tools.build.bundletool.model.utils.ResultUtils;
import com.android.tools.build.bundletool.model.utils.files.FilePreconditions;
import com.android.tools.build.bundletool.model.version.Version;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
Expand Down Expand Up @@ -227,7 +228,12 @@ ConfigurationSizes getSizeTotalInternal() {

for (Variant variant : variants) {
ConfigurationSizes configurationSizes =
new VariantTotalSizeAggregator(compressedSizeByApkPaths, variant, this).getSize();
new VariantTotalSizeAggregator(
compressedSizeByApkPaths,
Version.of(buildApksResult.getBundletool().getVersion()),
variant,
this)
.getSize();
minSizeConfigurationMap =
combineMaps(
minSizeConfigurationMap, configurationSizes.getMinSizeConfigurationMap(), Math::min);
Expand Down
Loading

0 comments on commit 2e9ac4e

Please sign in to comment.