Skip to content

Commit

Permalink
Make shrinked_android_jar optional in AndroidSdkProvider.
Browse files Browse the repository at this point in the history
shrinked_android_jar is totally unused when legacy_main_dex_list_generator is
present. This makes the attribute Noneable so we can drop it from the
android_sdk as well.

PiperOrigin-RevId: 361233906
  • Loading branch information
Googler authored and copybara-github committed Mar 5, 2021
1 parent b77246c commit 1a48161
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ static Artifact createMainDexListAction(
Artifact jar,
@Nullable Artifact mainDexProguardSpec,
@Nullable Artifact proguardOutputMap)
throws InterruptedException {
throws InterruptedException, RuleErrorException {
AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
// Create the main dex classes list.
Artifact mainDexList = AndroidBinary.getDxArtifact(ruleContext, "main_dex_list.txt");
Expand All @@ -1841,6 +1841,11 @@ static Artifact createMainDexListAction(
// legacy_main_dex_list_generator is provided, use that tool instead.
// TODO(b/147692286): Remove the old main-dex list generation that relied on ProGuard.
if (legacyMainDexListGenerator == null) {
if (sdk.getShrinkedAndroidJar() == null) {
ruleContext.throwWithRuleError(
"In \"legacy\" multidex mode, either legacy_main_dex_list_generator or "
+ "shrinked_android_jar must be set in the android_sdk.");
}
// Process the input jar through Proguard into an intermediate, streamlined jar.
Artifact strippedJar = AndroidBinary.getDxArtifact(ruleContext, "main_dex_intermediate.jar");
SpawnAction.Builder streamlinedBuilder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class AndroidSdkProvider extends NativeInfo
private final TransitiveInfoCollection aidlLib;
private final Artifact androidJar;
private final Artifact sourceProperties;
private final Artifact shrinkedAndroidJar;
@Nullable private final Artifact shrinkedAndroidJar;
private final Artifact mainDexClasses;
private final FilesToRunProvider adb;
private final FilesToRunProvider dx;
Expand All @@ -75,7 +75,7 @@ public AndroidSdkProvider(
@Nullable TransitiveInfoCollection aidlLib,
Artifact androidJar,
@Nullable Artifact sourceProperties,
Artifact shrinkedAndroidJar,
@Nullable Artifact shrinkedAndroidJar,
Artifact mainDexClasses,
FilesToRunProvider adb,
FilesToRunProvider dx,
Expand Down Expand Up @@ -234,6 +234,7 @@ public Artifact getSourceProperties() {
}

@Override
@Nullable
public Artifact getShrinkedAndroidJar() {
return shrinkedAndroidJar;
}
Expand Down Expand Up @@ -320,7 +321,7 @@ public AndroidSdkProvider createInfo(
Object aidlLib,
Artifact androidJar,
Object sourceProperties,
Artifact shrinkedAndroidJar,
Object shrinkedAndroidJar,
Artifact mainDexClasses,
FilesToRunProvider adb,
FilesToRunProvider dx,
Expand All @@ -341,7 +342,7 @@ public AndroidSdkProvider createInfo(
fromNoneable(aidlLib, TransitiveInfoCollection.class),
androidJar,
fromNoneable(sourceProperties, Artifact.class),
shrinkedAndroidJar,
fromNoneable(shrinkedAndroidJar, Artifact.class),
mainDexClasses,
adb,
dx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public interface AndroidSdkProviderApi<
@Nullable
FileT getSourceProperties();

@StarlarkMethod(name = "shrinked_android_jar", structField = true, doc = "", documented = false)
@StarlarkMethod(
name = "shrinked_android_jar",
structField = true,
doc = "",
documented = false,
allowReturnNones = true)
@Nullable
FileT getShrinkedAndroidJar();

@StarlarkMethod(name = "main_dex_classes", structField = true, doc = "", documented = false)
Expand Down Expand Up @@ -186,7 +192,11 @@ interface Provider<
name = "shrinked_android_jar",
doc = "An artifact of the shrunk Android Jar.",
positional = true,
named = false),
named = false,
allowedTypes = {
@ParamType(type = FileApi.class),
@ParamType(type = NoneType.class),
}),
@Param(
name = "main_dex_classes",
doc = "An artifact of the main dex classes.",
Expand Down Expand Up @@ -270,7 +280,7 @@ AndroidSdkProviderApi<FileT, FilesToRunProviderT, TransT> createInfo(
Object aidlLib,
FileT androidJar,
Object sourceProperties,
FileT shrinkedAndroidJar,
Object shrinkedAndroidJar,
FileT mainDexClasses,
FilesToRunProviderT adb,
FilesToRunProviderT dx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public FileApi getSourceProperties() {
return null;
}

@Nullable
@Override
public FileApi getShrinkedAndroidJar() {
return null;
Expand Down Expand Up @@ -144,7 +145,7 @@ public static class FakeProvider
Object aidlLib,
FileApi androidJar,
Object sourceProperties,
FileApi shrinkedAndroidJar,
Object shrinkedAndroidJar,
FileApi mainDexClasses,
FilesToRunProviderApi<FileApi> adb,
FilesToRunProviderApi<FileApi> dx,
Expand Down

0 comments on commit 1a48161

Please sign in to comment.