Skip to content

Commit

Permalink
Prepare for release 1.7.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iurii Makhno committed Aug 3, 2021
1 parent 7e12a24 commit a7bcb53
Show file tree
Hide file tree
Showing 63 changed files with 773 additions and 579 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ https://developer.android.com/studio/command-line/bundletool

## Releases

Latest release: [1.7.0](https://github.com/google/bundletool/releases)
Latest release: [1.7.1](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 = 1.7.0
release_version = 1.7.1
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public enum OutputFormat {
private static final Flag<Path> DEVICE_SPEC_FLAG = Flag.path("device-spec");
private static final Flag<ImmutableSet<SystemApkOption>> SYSTEM_APK_OPTIONS =
Flag.enumSet("system-apk-options", SystemApkOption.class);
private static final Flag<String> DEVICE_TIER_FLAG = Flag.string("device-tier");
private static final Flag<Integer> DEVICE_TIER_FLAG = Flag.nonNegativeInteger("device-tier");

private static final Flag<Boolean> VERBOSE_FLAG = Flag.booleanFlag("verbose");

Expand Down Expand Up @@ -206,7 +206,7 @@ public enum OutputFormat {

public abstract Optional<DeviceSpec> getDeviceSpec();

public abstract Optional<String> getDeviceTier();
public abstract Optional<Integer> getDeviceTier();

public abstract ImmutableSet<SystemApkOption> getSystemApkOptions();

Expand Down Expand Up @@ -340,7 +340,7 @@ public Builder setDeviceSpec(Path deviceSpecFile) {
* Sets the device tier to use for APK matching. This will override the device tier of the given
* device spec.
*/
public abstract Builder setDeviceTier(String deviceTier);
public abstract Builder setDeviceTier(Integer deviceTier);

/** Sets options to generated APKs in system mode. */
public abstract Builder setSystemApkOptions(ImmutableSet<SystemApkOption> options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.android.tools.build.bundletool.validation.AppBundleValidator;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -108,6 +109,7 @@ public final class BuildApksManager {
}

public void execute() throws IOException {
ImmutableSet<BundleModuleName> permanentlyFusedModules = ImmutableSet.of();
ImmutableSet<BundleModule> requestedModules =
command.getModules().isEmpty()
? ImmutableSet.of()
Expand All @@ -131,6 +133,9 @@ public void execute() throws IOException {
AppBundleValidator bundleValidator = AppBundleValidator.create(command.getExtraValidators());
bundleValidator.validate(mergedAppBundle);
generatedApksBuilder.setSplitApks(generateSplitApks(mergedAppBundle));
permanentlyFusedModules =
Sets.difference(appBundle.getModules().keySet(), mergedAppBundle.getModules().keySet())
.immutableCopy();
}

// Instant APKs
Expand Down Expand Up @@ -192,7 +197,8 @@ public void execute() throws IOException {
generatedAssetSlices.build(),
command.getApkBuildMode(),
deviceSpec,
getLocalTestingInfo(appBundle));
getLocalTestingInfo(appBundle),
permanentlyFusedModules);

if (command.getOverwriteOutput()) {
Files.deleteIfExists(command.getOutputFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.android.tools.build.bundletool.optimizations.ApkOptimizations;
import com.android.tools.build.bundletool.optimizations.OptimizationsMerger;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.protobuf.Int32Value;
import dagger.Module;
import dagger.Provides;
import java.io.PrintStream;
Expand Down Expand Up @@ -130,7 +131,10 @@ static Optional<DeviceSpec> provideDeviceSpec(BuildApksCommand command) {
checkState(deviceSpec.isPresent(), "Device tier specified but no device was provided.");
deviceSpec =
deviceSpec.map(
spec -> spec.toBuilder().setDeviceTier(command.getDeviceTier().get()).build());
spec ->
spec.toBuilder()
.setDeviceTier(Int32Value.of(command.getDeviceTier().get()))
.build());
}
return deviceSpec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import com.google.protobuf.Int32Value;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -333,20 +334,21 @@ private static Path createTempDirectory() {
}

private static DeviceSpec applyDefaultsToDeviceSpec(DeviceSpec deviceSpec, BuildApksResult toc) {
if (!deviceSpec.getDeviceTier().isEmpty()) {
if (deviceSpec.hasDeviceTier()) {
return deviceSpec;
}
Optional<String> defaultDeviceTier =
int defaultDeviceTier =
toc.getDefaultTargetingValueList().stream()
.filter(
defaultTargetingValue ->
defaultTargetingValue.getDimension().equals(Value.DEVICE_TIER))
.map(DefaultTargetingValue::getDefaultValue)
.collect(toOptional());
if (defaultDeviceTier.isPresent()) {
return deviceSpec.toBuilder().setDeviceTier(defaultDeviceTier.get()).build();
}
return deviceSpec;
// Don't fail if the default value is empty.
.filter(defaultValue -> !defaultValue.isEmpty())
.map(Integer::parseInt)
.collect(toOptional())
.orElse(0);
return deviceSpec.toBuilder().setDeviceTier(Int32Value.of(defaultDeviceTier)).build();
}

public static CommandHelp help() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.MoreFiles;
import com.google.protobuf.Int32Value;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -55,7 +56,7 @@ public abstract class GetDeviceSpecCommand {
private static final Flag<String> DEVICE_ID_FLAG = Flag.string("device-id");
private static final Flag<Path> OUTPUT_FLAG = Flag.path("output");
private static final Flag<Boolean> OVERWRITE_OUTPUT_FLAG = Flag.booleanFlag("overwrite");
private static final Flag<String> DEVICE_TIER_FLAG = Flag.string("device-tier");
private static final Flag<Integer> DEVICE_TIER_FLAG = Flag.nonNegativeInteger("device-tier");
private static final Flag<ImmutableSet<String>> DEVICE_GROUPS_FLAG =
Flag.stringSet("device-groups");

Expand All @@ -74,7 +75,7 @@ public abstract class GetDeviceSpecCommand {

abstract AdbServer getAdbServer();

public abstract Optional<String> getDeviceTier();
public abstract Optional<Integer> getDeviceTier();

public abstract Optional<ImmutableSet<String>> getDeviceGroups();

Expand Down Expand Up @@ -102,7 +103,7 @@ public abstract static class Builder {
/** The caller is responsible for the lifecycle of the {@link AdbServer}. */
public abstract Builder setAdbServer(AdbServer adbServer);

public abstract Builder setDeviceTier(String deviceTier);
public abstract Builder setDeviceTier(Integer deviceTier);

public abstract Builder setDeviceGroups(ImmutableSet<String> deviceGroups);

Expand Down Expand Up @@ -160,7 +161,8 @@ public DeviceSpec execute() {
adb.init(getAdbPath());
DeviceSpec deviceSpec = new DeviceAnalyzer(adb).getDeviceSpec(getDeviceId());
if (getDeviceTier().isPresent()) {
deviceSpec = deviceSpec.toBuilder().setDeviceTier(getDeviceTier().get()).build();
deviceSpec =
deviceSpec.toBuilder().setDeviceTier(Int32Value.of(getDeviceTier().get())).build();
}
if (getDeviceGroups().isPresent()) {
deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.protobuf.Int32Value;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
Expand All @@ -66,7 +67,7 @@ public abstract class InstallApksCommand {
private static final Flag<ImmutableSet<String>> MODULES_FLAG = Flag.stringSet("modules");
private static final Flag<Boolean> ALLOW_DOWNGRADE_FLAG = Flag.booleanFlag("allow-downgrade");
private static final Flag<Boolean> ALLOW_TEST_ONLY_FLAG = Flag.booleanFlag("allow-test-only");
private static final Flag<String> DEVICE_TIER_FLAG = Flag.string("device-tier");
private static final Flag<Integer> DEVICE_TIER_FLAG = Flag.nonNegativeInteger("device-tier");
private static final Flag<ImmutableSet<String>> DEVICE_GROUPS_FLAG =
Flag.stringSet("device-groups");
private static final Flag<ImmutableList<Path>> ADDITIONAL_LOCAL_TESTING_FILES_FLAG =
Expand All @@ -88,7 +89,7 @@ public abstract class InstallApksCommand {

public abstract boolean getAllowTestOnly();

public abstract Optional<String> getDeviceTier();
public abstract Optional<Integer> getDeviceTier();

public abstract Optional<ImmutableSet<String>> getDeviceGroups();

Expand Down Expand Up @@ -123,7 +124,7 @@ public abstract static class Builder {

public abstract Builder setAllowTestOnly(boolean allowTestOnly);

public abstract Builder setDeviceTier(String deviceTier);
public abstract Builder setDeviceTier(Integer deviceTier);

public abstract Builder setDeviceGroups(ImmutableSet<String> deviceGroups);

Expand All @@ -149,7 +150,7 @@ public static InstallApksCommand fromFlags(
Optional<ImmutableSet<String>> modules = MODULES_FLAG.getValue(flags);
Optional<Boolean> allowDowngrade = ALLOW_DOWNGRADE_FLAG.getValue(flags);
Optional<Boolean> allowTestOnly = ALLOW_TEST_ONLY_FLAG.getValue(flags);
Optional<String> deviceTier = DEVICE_TIER_FLAG.getValue(flags);
Optional<Integer> deviceTier = DEVICE_TIER_FLAG.getValue(flags);
Optional<ImmutableSet<String>> deviceGroups = DEVICE_GROUPS_FLAG.getValue(flags);
Optional<ImmutableList<Path>> additionalLocalTestingFiles =
ADDITIONAL_LOCAL_TESTING_FILES_FLAG.getValue(flags);
Expand Down Expand Up @@ -181,7 +182,8 @@ public void execute() {
try (TempDirectory tempDirectory = new TempDirectory()) {
DeviceSpec deviceSpec = new DeviceAnalyzer(adbServer).getDeviceSpec(getDeviceId());
if (getDeviceTier().isPresent()) {
deviceSpec = deviceSpec.toBuilder().setDeviceTier(getDeviceTier().get()).build();
deviceSpec =
deviceSpec.toBuilder().setDeviceTier(Int32Value.of(getDeviceTier().get())).build();
}
if (getDeviceGroups().isPresent()) {
deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected SizeConfiguration getSizeConfiguration(
}

if (dimensions.contains(DEVICE_TIER)) {
SizeConfiguration.getDeviceTierName(deviceTierTargeting)
SizeConfiguration.getDeviceTierLevel(deviceTierTargeting)
.ifPresent(sizeConfiguration::setDeviceTier);
}

Expand Down Expand Up @@ -319,7 +319,7 @@ protected SizeConfiguration mergeWithDeviceSpec(
}

if (dimensions.contains(DEVICE_TIER) && !isDeviceTierMissing(deviceSpec)) {
mergedSizeConfiguration.setDeviceTier(deviceSpec.getDeviceTier());
mergedSizeConfiguration.setDeviceTier(deviceSpec.getDeviceTier().getValue());
}

return mergedSizeConfiguration.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.android.bundle.Commands.BuildApksResult;
import com.android.bundle.Commands.DeliveryType;
import com.android.bundle.Commands.ModuleMetadata;
import com.android.bundle.Commands.PermanentlyFusedModule;
import com.android.bundle.Commands.Variant;
import com.android.bundle.Devices.DeviceSpec;
import com.android.bundle.Targeting.ApkTargeting;
Expand Down Expand Up @@ -252,13 +253,17 @@ private void validateVariant(Variant variant, BuildApksResult buildApksResult) {

Set<String> availableModules =
Sets.union(
variant.getApkSetList().stream()
.map(ApkSet::getModuleMetadata)
.map(ModuleMetadata::getName)
.collect(toImmutableSet()),
buildApksResult.getAssetSliceSetList().stream()
.map(AssetSliceSet::getAssetModuleMetadata)
.map(AssetModuleMetadata::getName)
Sets.union(
variant.getApkSetList().stream()
.map(ApkSet::getModuleMetadata)
.map(ModuleMetadata::getName)
.collect(toImmutableSet()),
buildApksResult.getAssetSliceSetList().stream()
.map(AssetSliceSet::getAssetModuleMetadata)
.map(AssetModuleMetadata::getName)
.collect(toImmutableSet())),
buildApksResult.getPermanentlyFusedModulesList().stream()
.map(PermanentlyFusedModule::getName)
.collect(toImmutableSet()));
Set<String> unknownModules = Sets.difference(requestedModuleNames.get(), availableModules);
if (!unknownModules.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean matchesTargeting(DeviceGroupModuleTargeting targetingValue) {

@Override
protected boolean isDeviceDimensionPresent() {
return !getDeviceSpec().getDeviceTier().isEmpty();
return !getDeviceSpec().getDeviceGroupsList().isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.protobuf.Int32Value;
import java.util.Optional;

/** Utils for {@link DeviceSpec}. */
Expand Down Expand Up @@ -63,7 +64,7 @@ public static boolean isTextureCompressionFormatMissing(DeviceSpec deviceSpec) {
}

public static boolean isDeviceTierMissing(DeviceSpec deviceSpec) {
return deviceSpec.getDeviceTier().isEmpty();
return !deviceSpec.hasDeviceTier();
}

/** Extracts the GL ES version, if any, form the device features. */
Expand Down Expand Up @@ -163,7 +164,8 @@ DeviceSpecFromTargetingBuilder setSupportedTextureCompressionFormats(

DeviceSpecFromTargetingBuilder setDeviceTier(DeviceTierTargeting deviceTierTargeting) {
if (!deviceTierTargeting.equals(DeviceTierTargeting.getDefaultInstance())) {
deviceSpec.setDeviceTier(Iterables.getOnlyElement(deviceTierTargeting.getValueList()));
deviceSpec.setDeviceTier(
Int32Value.of(Iterables.getOnlyElement(deviceTierTargeting.getValueList()).getValue()));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.android.tools.build.bundletool.device;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.stream.Collectors.joining;

import com.android.bundle.Devices.DeviceSpec;
import com.android.bundle.Targeting.ApkTargeting;
Expand All @@ -25,6 +27,8 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import com.google.common.collect.Streams;
import com.google.protobuf.Int32Value;

/**
* A {@link TargetingDimensionMatcher} that provides APK matching on device tier.
Expand Down Expand Up @@ -55,46 +59,50 @@ public boolean matchesTargeting(DeviceTierTargeting targeting) {
return true;
}

ImmutableSet<String> values = ImmutableSet.copyOf(targeting.getValueList());
ImmutableSet<String> alternatives = ImmutableSet.copyOf(targeting.getAlternativesList());
ImmutableSet<Integer> values =
targeting.getValueList().stream().map(Int32Value::getValue).collect(toImmutableSet());
ImmutableSet<Integer> alternatives =
targeting.getAlternativesList().stream()
.map(Int32Value::getValue)
.collect(toImmutableSet());

SetView<String> intersection = Sets.intersection(values, alternatives);
SetView<Integer> intersection = Sets.intersection(values, alternatives);
checkArgument(
intersection.isEmpty(),
"Expected targeting values and alternatives to be mutually exclusive, but both contain: %s",
intersection);

if (getDeviceSpec().getDeviceTier().isEmpty()) {
if (!getDeviceSpec().hasDeviceTier()) {
throw InvalidDeviceSpecException.builder()
.withUserMessage(
"The bundle uses device tier targeting, but no device tier was specified.")
.build();
}
if (values.contains(getDeviceSpec().getDeviceTier())) {
if (values.contains(getDeviceSpec().getDeviceTier().getValue())) {
return true;
}
return false;
}

@Override
protected boolean isDeviceDimensionPresent() {
return !getDeviceSpec().getDeviceTier().isEmpty();
return getDeviceSpec().hasDeviceTier();
}

@Override
protected void checkDeviceCompatibleInternal(DeviceTierTargeting targeting) {
if (targeting.equals(DeviceTierTargeting.getDefaultInstance())) {
return;
}
ImmutableSet<String> valuesAndAlternatives =
ImmutableSet.<String>builder()
.addAll(targeting.getValueList())
.addAll(targeting.getAlternativesList())
.build();
ImmutableSet<Integer> valuesAndAlternatives =
Streams.concat(
targeting.getValueList().stream().map(Int32Value::getValue),
targeting.getAlternativesList().stream().map(Int32Value::getValue))
.collect(toImmutableSet());
checkArgument(
valuesAndAlternatives.contains(getDeviceSpec().getDeviceTier()),
valuesAndAlternatives.contains(getDeviceSpec().getDeviceTier().getValue()),
"The specified device tier '%s' does not match any of the available values: %s.",
getDeviceSpec().getDeviceTier(),
String.join(", ", valuesAndAlternatives));
getDeviceSpec().getDeviceTier().getValue(),
valuesAndAlternatives.stream().map(i -> i.toString()).collect(joining(", ")));
}
}
Loading

0 comments on commit a7bcb53

Please sign in to comment.