Add API's to set min API level with both major and minor API level
This just adds the compiler API's to support minor version, but
the supplied value is not used yet.
Bug: b/356841164
Change-Id: Ied57e9837aee338e813a97dc7778e87c0bbf4bd7
diff --git a/src/main/java/com/android/tools/r8/BaseCompilerCommand.java b/src/main/java/com/android/tools/r8/BaseCompilerCommand.java
index f696981..51bacdc 100644
--- a/src/main/java/com/android/tools/r8/BaseCompilerCommand.java
+++ b/src/main/java/com/android/tools/r8/BaseCompilerCommand.java
@@ -280,7 +280,11 @@
private OutputMode outputMode = OutputMode.DexIndexed;
private CompilationMode mode;
- private int minApiLevel = 0;
+ private int minMajorApiLevel = 0;
+
+ @SuppressWarnings("UnusedVariable")
+ private int minMinorApiLevel = 0;
+
private int threadCount = ThreadUtils.NOT_SPECIFIED;
protected DesugarState desugarState = DesugarState.ON;
private final List<StringResource> desugaredLibrarySpecificationResources = new ArrayList<>();
@@ -579,19 +583,29 @@
/** Get the minimum API level (aka SDK version). */
public int getMinApiLevel() {
- return isMinApiLevelSet() ? minApiLevel : AndroidApiLevel.getDefault().getLevel();
+ return isMinApiLevelSet() ? minMajorApiLevel : AndroidApiLevel.getDefault().getLevel();
}
boolean isMinApiLevelSet() {
- return minApiLevel != 0;
+ return minMajorApiLevel != 0;
}
/** Set the minimum required API level (aka SDK version). */
- public B setMinApiLevel(int minApiLevel) {
- if (minApiLevel <= 0) {
- getReporter().error("Invalid minApiLevel: " + minApiLevel);
+ public B setMinApiLevel(int minMajorApiLevel) {
+ if (minMajorApiLevel <= 0) {
+ getReporter().error("Invalid minApiLevel: " + minMajorApiLevel);
+ return self();
+ }
+ return setMinApiLevel(minMajorApiLevel, 0);
+ }
+
+ /** Set the minimum required API level (aka SDK version). */
+ public B setMinApiLevel(int minMajorApiLevel, int minMinorApiLevel) {
+ if (minMajorApiLevel <= 0 || minMinorApiLevel < 0) {
+ getReporter().error("Invalid minApiLevel: " + minMajorApiLevel + "." + minMinorApiLevel);
} else {
- this.minApiLevel = minApiLevel;
+ this.minMajorApiLevel = minMajorApiLevel;
+ this.minMinorApiLevel = minMinorApiLevel;
}
return self();
}
diff --git a/src/main/java/com/android/tools/r8/GlobalSyntheticsGeneratorCommand.java b/src/main/java/com/android/tools/r8/GlobalSyntheticsGeneratorCommand.java
index 80a7691..d64053f 100644
--- a/src/main/java/com/android/tools/r8/GlobalSyntheticsGeneratorCommand.java
+++ b/src/main/java/com/android/tools/r8/GlobalSyntheticsGeneratorCommand.java
@@ -35,7 +35,11 @@
private final GlobalSyntheticsConsumer globalsConsumer;
private final Reporter reporter;
- private final int minApiLevel;
+ private final int minMajorApiLevel;
+
+ @SuppressWarnings("UnusedVariable")
+ private final int minMinorApiLevel;
+
private final boolean classfileDesugaringOnly;
private final boolean printHelp;
@@ -49,11 +53,13 @@
AndroidApp inputApp,
GlobalSyntheticsConsumer globalsConsumer,
Reporter reporter,
- int minApiLevel,
+ int minMajorApiLevel,
+ int minMinorApiLevel,
boolean classfileDesugaringOnly) {
this.inputApp = inputApp;
this.globalsConsumer = globalsConsumer;
- this.minApiLevel = minApiLevel;
+ this.minMajorApiLevel = minMajorApiLevel;
+ this.minMinorApiLevel = minMinorApiLevel;
this.classfileDesugaringOnly = classfileDesugaringOnly;
this.reporter = reporter;
this.printHelp = false;
@@ -66,7 +72,8 @@
this.inputApp = null;
this.globalsConsumer = null;
- this.minApiLevel = AndroidApiLevel.B.getLevel();
+ this.minMajorApiLevel = AndroidApiLevel.B.getLevel();
+ this.minMinorApiLevel = 0;
this.classfileDesugaringOnly = false;
reporter = new Reporter();
@@ -140,7 +147,7 @@
InternalOptions internal = new InternalOptions(factory, reporter);
assert !internal.debug;
assert !internal.minimalMainDex;
- internal.setMinApiLevel(AndroidApiLevel.getAndroidApiLevel(minApiLevel));
+ internal.setMinApiLevel(AndroidApiLevel.getAndroidApiLevel(minMajorApiLevel));
assert internal.retainCompileTimeAnnotations;
internal.intermediate = true;
internal.programConsumer =
@@ -205,7 +212,8 @@
private GlobalSyntheticsConsumer globalsConsumer = null;
private final Reporter reporter;
- private int minApiLevel = AndroidApiLevel.B.getLevel();
+ private int minMajorApiLevel = AndroidApiLevel.B.getLevel();
+ private int minMinorApiLevel = 0;
private boolean classfileDesugaringOnly = false;
private boolean printHelp = false;
private boolean printVersion = false;
@@ -220,8 +228,14 @@
}
/** Set the min api level. */
- public Builder setMinApiLevel(int minApiLevel) {
- this.minApiLevel = minApiLevel;
+ public Builder setMinApiLevel(int minMajorApiLevel) {
+ return setMinApiLevel(minMajorApiLevel, 0);
+ }
+
+ /** Set the min api level. */
+ public Builder setMinApiLevel(int minMajorApiLevel, int minMinorApiLevel) {
+ this.minMajorApiLevel = minMajorApiLevel;
+ this.minMinorApiLevel = minMinorApiLevel;
return this;
}
@@ -298,7 +312,12 @@
return new GlobalSyntheticsGeneratorCommand(printHelp, printVersion);
}
return new GlobalSyntheticsGeneratorCommand(
- appBuilder.build(), globalsConsumer, reporter, minApiLevel, classfileDesugaringOnly);
+ appBuilder.build(),
+ globalsConsumer,
+ reporter,
+ minMajorApiLevel,
+ minMinorApiLevel,
+ classfileDesugaringOnly);
}
private boolean isPrintHelpOrPrintVersion() {
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/lint/DesugaredMethodsListCommand.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/lint/DesugaredMethodsListCommand.java
index 1eb157f..c293a08 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/lint/DesugaredMethodsListCommand.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/lint/DesugaredMethodsListCommand.java
@@ -33,7 +33,10 @@
private final boolean help;
private final boolean version;
- private final int minApi;
+ private final int minMajorApi;
+
+ @SuppressWarnings("UnusedVariable")
+ private final int minMinorApi;
private final Reporter reporter;
private final StringResource desugarLibrarySpecification;
@@ -43,7 +46,8 @@
private final boolean androidPlatformBuild;
DesugaredMethodsListCommand(
- int minApi,
+ int minMajorApi,
+ int minMinorApi,
Reporter reporter,
StringResource desugarLibrarySpecification,
Collection<ProgramResourceProvider> desugarLibraryImplementation,
@@ -52,7 +56,8 @@
boolean androidPlatformBuild) {
this.help = false;
this.version = false;
- this.minApi = minApi;
+ this.minMajorApi = minMajorApi;
+ this.minMinorApi = minMinorApi;
this.reporter = reporter;
this.desugarLibrarySpecification = desugarLibrarySpecification;
this.desugarLibraryImplementation = desugarLibraryImplementation;
@@ -64,7 +69,8 @@
DesugaredMethodsListCommand(boolean help, boolean version) {
this.help = help;
this.version = version;
- this.minApi = -1;
+ this.minMajorApi = -1;
+ this.minMinorApi = 0;
this.reporter = null;
this.desugarLibrarySpecification = null;
this.desugarLibraryImplementation = null;
@@ -83,7 +89,7 @@
}
public int getMinApi() {
- return minApi;
+ return minMajorApi;
}
public boolean isAndroidPlatformBuild() {
@@ -134,7 +140,8 @@
@KeepForApi
public static class Builder {
- private int minApi = AndroidApiLevel.B.getLevel();
+ private int minMajorApi = AndroidApiLevel.B.getLevel();
+ private int minMinorApi = 0;
private final Reporter reporter;
private StringResource desugarLibrarySpecification = null;
private Collection<ProgramResourceProvider> desugarLibraryImplementation = new ArrayList<>();
@@ -149,8 +156,14 @@
this.reporter = new Reporter(diagnosticsHandler);
}
- public Builder setMinApi(int minApi) {
- this.minApi = minApi;
+ public Builder setMinApi(int minMajorApi) {
+ this.minMajorApi = minMajorApi;
+ return this;
+ }
+
+ public Builder setMinApi(int minMajorApi, int minMinorApi) {
+ this.minMajorApi = minMajorApi;
+ this.minMinorApi = minMinorApi;
return this;
}
@@ -237,7 +250,8 @@
};
}
return new DesugaredMethodsListCommand(
- minApi,
+ minMajorApi,
+ minMinorApi,
reporter,
desugarLibrarySpecification,
desugarLibraryImplementation,