Skip to content

Commit

Permalink
Prepare for release 0.14.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iurii Makhno committed Apr 23, 2020
1 parent 24e8e6e commit 9831cec
Show file tree
Hide file tree
Showing 76 changed files with 4,036 additions and 499 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.13.4](https://github.com/google/bundletool/releases)
Latest release: [0.14.0](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.13.4
release_version = 0.14.0
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.android.tools.build.bundletool.commands.GetDeviceSpecCommand;
import com.android.tools.build.bundletool.commands.GetSizeCommand;
import com.android.tools.build.bundletool.commands.InstallApksCommand;
import com.android.tools.build.bundletool.commands.InstallMultiApksCommand;
import com.android.tools.build.bundletool.commands.ValidateBundleCommand;
import com.android.tools.build.bundletool.commands.VersionCommand;
import com.android.tools.build.bundletool.device.AdbServer;
Expand Down Expand Up @@ -88,6 +89,11 @@ static void main(String[] args, Runtime runtime) {
InstallApksCommand.fromFlags(flags, adbServer).execute();
}
break;
case InstallMultiApksCommand.COMMAND_NAME:
try (AdbServer adbServer = DdmlibAdbServer.getInstance()) {
InstallMultiApksCommand.fromFlags(flags, adbServer).execute();
}
break;
case ValidateBundleCommand.COMMAND_NAME:
ValidateBundleCommand.fromFlags(flags).execute();
break;
Expand Down Expand Up @@ -134,6 +140,7 @@ public static void help() {
ExtractApksCommand.help(),
GetDeviceSpecCommand.help(),
InstallApksCommand.help(),
InstallMultiApksCommand.help(),
ValidateBundleCommand.help(),
DumpCommand.help(),
GetSizeCommand.help(),
Expand Down Expand Up @@ -165,6 +172,9 @@ public static void help(String commandName, Runtime runtime) {
case InstallApksCommand.COMMAND_NAME:
commandHelp = InstallApksCommand.help();
break;
case InstallMultiApksCommand.COMMAND_NAME:
commandHelp = InstallMultiApksCommand.help();
break;
case ValidateBundleCommand.COMMAND_NAME:
commandHelp = ValidateBundleCommand.help();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM;
import static com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM_COMPRESSED;
import static com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL;
import static com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE;
import static com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE;
import static com.android.tools.build.bundletool.model.utils.SdkToolsLocator.SYSTEM_PATH_VARIABLE;
import static com.google.common.base.Preconditions.checkArgument;
Expand All @@ -42,7 +43,6 @@
import com.android.tools.build.bundletool.model.exceptions.CommandExecutionException;
import com.android.tools.build.bundletool.model.exceptions.ValidationException;
import com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider;
import com.android.tools.build.bundletool.model.utils.SdkToolsLocator;
import com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider;
import com.android.tools.build.bundletool.splitters.DexCompressionSplitter;
import com.android.tools.build.bundletool.splitters.NativeLibrariesCompressionSplitter;
Expand Down Expand Up @@ -113,7 +113,6 @@ public final boolean isAnySystemMode() {
private static final Flag<Path> ADB_PATH_FLAG = Flag.path("adb");
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 Down Expand Up @@ -492,19 +491,8 @@ static BuildApksCommand fromFlags(

// Applied only when --connected-device flag is set, because we don't want to fail command
// if ADB cannot be found in a normal mode.
Optional<Path> adbPathFromFlag = ADB_PATH_FLAG.getValue(flags);
if (connectedDeviceMode) {
Path adbPath =
adbPathFromFlag.orElseGet(
() ->
new SdkToolsLocator()
.locateAdb(systemEnvironmentProvider)
.orElseThrow(
() ->
new CommandExecutionException(
"Unable to determine the location of ADB. Please set the --adb "
+ "flag or define ANDROID_HOME or PATH environment "
+ "variable.")));
Path adbPath = CommandUtils.getAdbPath(flags, ADB_PATH_FLAG, systemEnvironmentProvider);
buildApksCommand.setAdbPath(adbPath).setAdbServer(adbServer);
}

Expand All @@ -531,22 +519,11 @@ static BuildApksCommand fromFlags(
public Path execute() {
try (TempDirectory tempDir = new TempDirectory()) {
Aapt2Command aapt2 =
getAapt2Command().orElseGet(() -> extractAapt2FromJar(tempDir.getPath()));
getAapt2Command().orElseGet(() -> CommandUtils.extractAapt2FromJar(tempDir.getPath()));
return new BuildApksManager(this, aapt2, tempDir.getPath()).execute();
}
}

private static Aapt2Command extractAapt2FromJar(Path tempDir) {
return new SdkToolsLocator()
.extractAapt2(tempDir)
.map(Aapt2Command::createFromExecutablePath)
.orElseThrow(
() ->
new CommandExecutionException(
"Could not extract aapt2: consider updating bundletool to a more recent "
+ "version or providing the path to aapt2 using the flag --aapt2."));
}

/**
* Creates an internal executor service that uses at most the given number of threads.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.android.tools.build.bundletool.optimizations.ApkOptimizations;
import com.android.tools.build.bundletool.optimizations.OptimizationsMerger;
import com.android.tools.build.bundletool.preprocessors.AppBundle64BitNativeLibrariesPreprocessor;
import com.android.tools.build.bundletool.preprocessors.EmbeddedApkSigningPreprocessor;
import com.android.tools.build.bundletool.preprocessors.EntryCompressionPreprocessor;
import com.android.tools.build.bundletool.preprocessors.LocalTestingPreprocessor;
import com.android.tools.build.bundletool.splitters.ApkGenerationConfiguration;
Expand Down Expand Up @@ -184,7 +185,7 @@ private void executeWithZip(
// Note: Universal APK is a special type of standalone, with no optimization dimensions.
ImmutableList<BundleModule> modulesToFuse =
requestedModules.isEmpty()
? modulesToFuse(appBundle.getFeatureModules().values().asList())
? modulesToFuse(getModulesForStandaloneApks(appBundle))
: requestedModules.asList();
generatedApksBuilder.setStandaloneApks(
new ShardedApksGenerator(
Expand Down Expand Up @@ -521,6 +522,7 @@ private AppBundle applyPreprocessors(AppBundle bundle) {
bundle = new LocalTestingPreprocessor().preprocess(bundle);
}
bundle = new EntryCompressionPreprocessor().preprocess(bundle);
bundle = new EmbeddedApkSigningPreprocessor().preprocess(bundle);
return bundle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ private static Optional<ApexImages> generateApexImagesTargeting(BundleModule mod
}

return Optional.of(
new TargetingGenerator()
.generateTargetingForApexImages(
module.getBundleConfig().getApexConfig(), apexImageFiles, hasBuildInfo));
new TargetingGenerator().generateTargetingForApexImages(apexImageFiles, hasBuildInfo));
}

private static BundleConfig parseBundleConfigJson(Path bundleConfigJsonPath) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/

package com.android.tools.build.bundletool.commands;

import com.android.tools.build.bundletool.flags.Flag;
import com.android.tools.build.bundletool.flags.ParsedFlags;
import com.android.tools.build.bundletool.model.Aapt2Command;
import com.android.tools.build.bundletool.model.exceptions.CommandExecutionException;
import com.android.tools.build.bundletool.model.utils.SdkToolsLocator;
import com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider;
import java.nio.file.Path;
import java.util.Optional;

final class CommandUtils {
static final String ANDROID_SERIAL_VARIABLE = "ANDROID_SERIAL";

private CommandUtils() {}

static Path getAdbPath(
ParsedFlags flags, Flag<Path> adbFlag, SystemEnvironmentProvider systemEnvironmentProvider) {
return adbFlag
.getValue(flags)
.orElseGet(
() ->
new SdkToolsLocator()
.locateAdb(systemEnvironmentProvider)
.orElseThrow(
() ->
new CommandExecutionException(
"Unable to determine the location of ADB. Please set the --adb "
+ "flag or define ANDROID_HOME or PATH environment "
+ "variable.")));
}

static Optional<String> getDeviceSerialName(
ParsedFlags flags,
Flag<String> deviceIdFlag,
SystemEnvironmentProvider systemEnvironmentProvider) {
Optional<String> deviceSerialName = deviceIdFlag.getValue(flags);
if (!deviceSerialName.isPresent()) {
deviceSerialName = systemEnvironmentProvider.getVariable(ANDROID_SERIAL_VARIABLE);
}
return deviceSerialName;
}

static Aapt2Command extractAapt2FromJar(Path tempDir) {
return new SdkToolsLocator()
.extractAapt2(tempDir)
.map(Aapt2Command::createFromExecutablePath)
.orElseThrow(
() ->
new CommandExecutionException(
"Could not extract aapt2: consider updating bundletool to a more recent "
+ "version or providing the path to aapt2 using the flag --aapt2."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.android.tools.build.bundletool.commands;

import static com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE;
import static com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE;
import static com.android.tools.build.bundletool.model.utils.SdkToolsLocator.SYSTEM_PATH_VARIABLE;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand All @@ -27,10 +28,8 @@
import com.android.tools.build.bundletool.device.DeviceAnalyzer;
import com.android.tools.build.bundletool.flags.Flag;
import com.android.tools.build.bundletool.flags.ParsedFlags;
import com.android.tools.build.bundletool.model.exceptions.CommandExecutionException;
import com.android.tools.build.bundletool.model.exceptions.ValidationException;
import com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider;
import com.android.tools.build.bundletool.model.utils.SdkToolsLocator;
import com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider;
import com.android.tools.build.bundletool.model.utils.files.FilePreconditions;
import com.google.auto.value.AutoValue;
Expand All @@ -56,8 +55,6 @@ public abstract class GetDeviceSpecCommand {
private static final Flag<Path> OUTPUT_FLAG = Flag.path("output");
private static final Flag<Boolean> OVERWRITE_OUTPUT_FLAG = Flag.booleanFlag("overwrite");

private static final String ANDROID_SERIAL_VARIABLE = "ANDROID_SERIAL";

private static final SystemEnvironmentProvider DEFAULT_PROVIDER =
new DefaultSystemEnvironmentProvider();

Expand Down Expand Up @@ -123,25 +120,11 @@ public static GetDeviceSpecCommand fromFlags(
GetDeviceSpecCommand.Builder builder =
builder().setAdbServer(adbServer).setOutputPath(OUTPUT_FLAG.getRequiredValue(flags));

Optional<String> deviceSerialName = DEVICE_ID_FLAG.getValue(flags);
if (!deviceSerialName.isPresent()) {
deviceSerialName = systemEnvironmentProvider.getVariable(ANDROID_SERIAL_VARIABLE);
}
Optional<String> deviceSerialName =
CommandUtils.getDeviceSerialName(flags, DEVICE_ID_FLAG, systemEnvironmentProvider);
deviceSerialName.ifPresent(builder::setDeviceId);

Path adbPath =
ADB_PATH_FLAG
.getValue(flags)
.orElseGet(
() ->
new SdkToolsLocator()
.locateAdb(systemEnvironmentProvider)
.orElseThrow(
() ->
new CommandExecutionException(
"Unable to determine the location of ADB. Please set the --adb "
+ "flag or define ANDROID_HOME or PATH environment "
+ "variable.")));
Path adbPath = CommandUtils.getAdbPath(flags, ADB_PATH_FLAG, systemEnvironmentProvider);
builder.setAdbPath(adbPath);

OVERWRITE_OUTPUT_FLAG.getValue(flags).ifPresent(builder::setOverwriteOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
import static com.android.tools.build.bundletool.commands.GetSizeCommand.GetSizeSubcommand.STRING_TO_SUBCOMMAND;
import static com.android.tools.build.bundletool.commands.GetSizeCommand.GetSizeSubcommand.TOTAL;
import static com.android.tools.build.bundletool.model.utils.ApkSizeUtils.getCompressedSizeByApkPaths;
import static com.android.tools.build.bundletool.model.utils.ApkSizeUtils.getVariantCompressedSizeByApkPaths;
import static com.android.tools.build.bundletool.model.utils.CollectorUtils.combineMaps;
import static com.android.tools.build.bundletool.model.utils.GetSizeCsvUtils.getSizeTotalOutputInCsv;
import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.function.Function.identity;

import com.android.bundle.Commands.ApkDescription;
import com.android.bundle.Commands.BuildApksResult;
import com.android.bundle.Commands.Variant;
import com.android.bundle.Devices.DeviceSpec;
import com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription;
import com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription;
import com.android.tools.build.bundletool.device.AssetModuleSizeAggregator;
import com.android.tools.build.bundletool.device.DeviceSpecParser;
import com.android.tools.build.bundletool.device.VariantMatcher;
import com.android.tools.build.bundletool.device.VariantTotalSizeAggregator;
Expand All @@ -40,6 +44,7 @@
import com.android.tools.build.bundletool.model.GetSizeRequest.Dimension;
import com.android.tools.build.bundletool.model.SizeConfiguration;
import com.android.tools.build.bundletool.model.exceptions.ValidationException;
import com.android.tools.build.bundletool.model.utils.ConfigurationSizesMerger;
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;
Expand Down Expand Up @@ -220,20 +225,37 @@ ConfigurationSizes getSizeTotalInternal() {

ImmutableList<Variant> variants =
new VariantMatcher(getDeviceSpec(), getInstant()).getAllMatchingVariants(buildApksResult);
ImmutableMap<String, Long> compressedSizeByApkPaths =
getCompressedSizeByApkPaths(variants, getApksArchivePath());
ImmutableMap<String, Long> variantCompressedSizeByApkPaths =
getVariantCompressedSizeByApkPaths(variants, getApksArchivePath());

ImmutableList<String> assetModuleApks =
buildApksResult.getAssetSliceSetList().stream()
.flatMap(module -> module.getApkDescriptionList().stream())
.map(ApkDescription::getPath)
.collect(toImmutableList());
ImmutableMap<String, Long> assetModuleCompressedSizeByApkPaths =
getCompressedSizeByApkPaths(assetModuleApks, getApksArchivePath());

ImmutableMap<SizeConfiguration, Long> minSizeConfigurationMap = ImmutableMap.of();
ImmutableMap<SizeConfiguration, Long> maxSizeConfigurationMap = ImmutableMap.of();

for (Variant variant : variants) {
ConfigurationSizes configurationSizes =
ConfigurationSizes variantConfigurationSizes =
new VariantTotalSizeAggregator(
compressedSizeByApkPaths,
variantCompressedSizeByApkPaths,
Version.of(buildApksResult.getBundletool().getVersion()),
variant,
this)
.getSize();
ConfigurationSizes assetModuleConfigurationSizes =
new AssetModuleSizeAggregator(
buildApksResult.getAssetSliceSetList(),
variant.getTargeting(),
assetModuleCompressedSizeByApkPaths,
this)
.getSize();
ConfigurationSizes configurationSizes =
ConfigurationSizesMerger.merge(variantConfigurationSizes, assetModuleConfigurationSizes);
minSizeConfigurationMap =
combineMaps(
minSizeConfigurationMap, configurationSizes.getMinSizeConfigurationMap(), Math::min);
Expand Down
Loading

0 comments on commit 9831cec

Please sign in to comment.