Remove references to Jdk11 flag
Bug: b:231287675
Change-Id: I859a3a3f3fcb44a49a30b378636da8d5b13de06b
diff --git a/src/test/java/com/android/tools/r8/BackportedMethodListTest.java b/src/test/java/com/android/tools/r8/BackportedMethodListTest.java
index b2b78d1..dcf816e 100644
--- a/src/test/java/com/android/tools/r8/BackportedMethodListTest.java
+++ b/src/test/java/com/android/tools/r8/BackportedMethodListTest.java
@@ -3,11 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8;
-import static com.android.tools.r8.desugar.desugaredlibrary.DesugaredLibraryTestBase.isJDK11DesugaredLibrary;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification;
import com.android.tools.r8.utils.AndroidApiLevel;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -28,7 +28,8 @@
enum Mode {
NO_LIBRARY,
LIBRARY,
- LIBRARY_DESUGAR
+ LIBRARY_DESUGAR,
+ LIBRARY_DESUGAR_11
}
@Parameterized.Parameters(name = "Mode: {0}")
@@ -42,6 +43,16 @@
this.mode = mode;
}
+ private LibraryDesugaringSpecification getLibraryDesugaringSpecification() {
+ if (mode == Mode.LIBRARY_DESUGAR) {
+ return LibraryDesugaringSpecification.JDK8;
+ }
+ if (mode == Mode.LIBRARY_DESUGAR_11) {
+ return LibraryDesugaringSpecification.JDK11;
+ }
+ return null;
+ }
+
private static class ListStringConsumer implements StringConsumer {
List<String> strings = new ArrayList<>();
boolean finished = false;
@@ -71,17 +82,14 @@
// Java 9, 10 and 11 Optional methods which require Android N or library desugaring.
// The methods are not backported in desugared library JDK 11 (already present).
assertEquals(
- (mode == Mode.LIBRARY_DESUGAR && !isJDK11DesugaredLibrary())
- || apiLevel >= AndroidApiLevel.N.getLevel(),
+ (mode == Mode.LIBRARY_DESUGAR) || apiLevel >= AndroidApiLevel.N.getLevel(),
backports.contains(
"java/util/Optional#or(Ljava/util/function/Supplier;)Ljava/util/Optional;"));
assertEquals(
- (mode == Mode.LIBRARY_DESUGAR && !isJDK11DesugaredLibrary())
- || apiLevel >= AndroidApiLevel.N.getLevel(),
+ (mode == Mode.LIBRARY_DESUGAR) || apiLevel >= AndroidApiLevel.N.getLevel(),
backports.contains("java/util/OptionalInt#orElseThrow()I"));
assertEquals(
- (mode == Mode.LIBRARY_DESUGAR && !isJDK11DesugaredLibrary())
- || apiLevel >= AndroidApiLevel.N.getLevel(),
+ (mode == Mode.LIBRARY_DESUGAR) || apiLevel >= AndroidApiLevel.N.getLevel(),
backports.contains("java/util/OptionalLong#isEmpty()Z"));
// Java 9, 10 and 11 method added at API level S.
@@ -103,8 +111,8 @@
private void addLibraryDesugaring(BackportedMethodListCommand.Builder builder) {
builder
.addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
- .addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.R.getLevel()));
+ StringResource.fromFile(getLibraryDesugaringSpecification().getSpecification()))
+ .addLibraryFiles(getLibraryDesugaringSpecification().getLibraryFiles());
}
@Test
@@ -115,7 +123,7 @@
BackportedMethodListCommand.builder().setMinApiLevel(apiLevel).setConsumer(consumer);
if (mode == Mode.LIBRARY) {
builder.addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P.getLevel()));
- } else if (mode == Mode.LIBRARY_DESUGAR) {
+ } else if (mode == Mode.LIBRARY_DESUGAR || mode == Mode.LIBRARY_DESUGAR_11) {
addLibraryDesugaring(builder);
}
BackportedMethodList.run(builder.build());
@@ -132,7 +140,7 @@
BackportedMethodListCommand.builder().setMinApiLevel(apiLevel).setOutputPath(output);
if (mode == Mode.LIBRARY) {
builder.addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P.getLevel()));
- } else if (mode == Mode.LIBRARY_DESUGAR) {
+ } else if (mode == Mode.LIBRARY_DESUGAR || mode == Mode.LIBRARY_DESUGAR_11) {
addLibraryDesugaring(builder);
}
BackportedMethodList.run(builder.build());
@@ -152,13 +160,13 @@
@Test
public void requireLibraryForDesugar() {
- Assume.assumeTrue(mode == Mode.LIBRARY_DESUGAR);
+ Assume.assumeTrue(mode == Mode.LIBRARY_DESUGAR || mode == Mode.LIBRARY_DESUGAR_11);
// Require library when a desugar configuration is passed.
try {
BackportedMethodList.run(
BackportedMethodListCommand.builder()
.addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ StringResource.fromFile(getLibraryDesugaringSpecification().getSpecification()))
.setConsumer(new ListStringConsumer())
.build());
fail("Expected failure");
diff --git a/src/test/java/com/android/tools/r8/L8CommandTest.java b/src/test/java/com/android/tools/r8/L8CommandTest.java
index dbc7ebd..3526d0c 100644
--- a/src/test/java/com/android/tools/r8/L8CommandTest.java
+++ b/src/test/java/com/android/tools/r8/L8CommandTest.java
@@ -6,6 +6,7 @@
import static com.android.tools.r8.DiagnosticsMatcher.diagnosticMessage;
import static com.android.tools.r8.MarkerMatcher.assertMarkersMatch;
import static com.android.tools.r8.MarkerMatcher.markerTool;
+import static com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification.getJdk8Jdk11;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -15,11 +16,11 @@
import com.android.tools.r8.AssertionsConfiguration.AssertionTransformationScope;
import com.android.tools.r8.StringConsumer.FileConsumer;
+import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification;
import com.android.tools.r8.dex.Marker.Tool;
import com.android.tools.r8.origin.EmbeddedOrigin;
import com.android.tools.r8.origin.Origin;
import com.android.tools.r8.references.Reference;
-import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.FileUtils;
import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.ThreadUtils;
@@ -41,19 +42,27 @@
@RunWith(Parameterized.class)
public class L8CommandTest extends CommandTestBase<L8Command> {
- @Parameters(name = "{0}")
- public static TestParametersCollection data() {
- return getTestParameters().withNoneRuntime().build();
+ private final LibraryDesugaringSpecification libraryDesugaringSpecification;
+
+ @Parameters(name = "{0}, spec: {1}, {2}")
+ public static List<Object[]> data() {
+ return buildParameters(getTestParameters().withNoneRuntime().build(), getJdk8Jdk11());
}
- public L8CommandTest(TestParameters parameters) {
+ public L8CommandTest(
+ TestParameters parameters, LibraryDesugaringSpecification libraryDesugaringSpecification) {
parameters.assertNoneRuntime();
+ this.libraryDesugaringSpecification = libraryDesugaringSpecification;
}
protected final Matcher<Diagnostic> cfL8NotSupportedDiagnostic =
diagnosticMessage(
containsString("L8 does not support shrinking when generating class files"));
+ private StringResource getDesugaredLibraryConfiguration() {
+ return StringResource.fromFile(libraryDesugaringSpecification.getSpecification());
+ }
+
@Test(expected = CompilationFailedException.class)
public void emptyBuilder() throws Throwable {
verifyEmptyCommand(L8Command.builder().build());
@@ -64,8 +73,7 @@
verifyEmptyCommand(
L8Command.builder()
.setProgramConsumer(DexIndexedConsumer.emptyConsumer())
- .addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ .addDesugaredLibraryConfiguration(getDesugaredLibraryConfiguration())
.build());
}
@@ -82,11 +90,10 @@
Path output = temp.newFolder().toPath().resolve("desugar_jdk_libs.zip");
L8.run(
L8Command.builder()
- .addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P))
- .addProgramFiles(ToolHelper.getDesugarJDKLibs())
+ .addLibraryFiles(libraryDesugaringSpecification.getLibraryFiles())
+ .addProgramFiles(libraryDesugaringSpecification.getDesugarJdkLibs())
.setMinApiLevel(20)
- .addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ .addDesugaredLibraryConfiguration(getDesugaredLibraryConfiguration())
.setOutput(output, OutputMode.DexIndexed)
.build());
assertMarkersMatch(
@@ -99,30 +106,38 @@
Path output = temp.newFolder().toPath().resolve("desugar_jdk_libs.zip");
L8.run(
L8Command.builder()
- .addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P))
- .addProgramFiles(ToolHelper.getDesugarJDKLibs())
+ .addLibraryFiles(libraryDesugaringSpecification.getLibraryFiles())
+ .addProgramFiles(libraryDesugaringSpecification.getDesugarJdkLibs())
.setMinApiLevel(20)
- .addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ .addDesugaredLibraryConfiguration(getDesugaredLibraryConfiguration())
.setOutput(output, OutputMode.ClassFile)
.build());
assertMarkersMatch(ExtractMarker.extractMarkerFromDexFile(output), markerTool(Tool.L8));
}
+ private List<String> buildCommand(int minAPI, Path output) {
+ ArrayList<String> command = new ArrayList<>();
+ for (Path desugarJDKLib : libraryDesugaringSpecification.getDesugarJdkLibs()) {
+ command.add(desugarJDKLib.toString());
+ }
+ for (Path libraryFile : libraryDesugaringSpecification.getLibraryFiles()) {
+ command.add("--lib");
+ command.add(libraryFile.toString());
+ }
+ command.add("--min-api");
+ command.add(Integer.toString(minAPI));
+ command.add("--desugared-lib");
+ command.add(libraryDesugaringSpecification.getSpecification().toString());
+ command.add("--output");
+ command.add(output.toString());
+ return command;
+ }
+
@Test
public void testDexMarkerCommandLine() throws Throwable {
Path output = temp.newFolder().toPath().resolve("desugar_jdk_libs.zip");
- L8Command l8Command =
- parse(
- ToolHelper.getDesugarJDKLibs().toString(),
- "--lib",
- ToolHelper.getAndroidJar(AndroidApiLevel.P).toString(),
- "--min-api",
- "20",
- "--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
- "--output",
- output.toString());
+ List<String> command = buildCommand(20, output);
+ L8Command l8Command = parse(command.toArray(new String[0]));
L8.run(l8Command);
assertMarkersMatch(
ExtractMarker.extractMarkerFromDexFile(output),
@@ -132,18 +147,9 @@
@Test
public void testClassFileMarkerCommandLine() throws Throwable {
Path output = temp.newFolder().toPath().resolve("desugar_jdk_libs.zip");
- L8Command l8Command =
- parse(
- ToolHelper.getDesugarJDKLibs().toString(),
- "--lib",
- ToolHelper.getAndroidJar(AndroidApiLevel.P).toString(),
- "--min-api",
- "20",
- "--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
- "--output",
- output.toString(),
- "--classfile");
+ List<String> command = buildCommand(20, output);
+ command.add("--classfile");
+ L8Command l8Command = parse(command.toArray(new String[0]));
L8.run(l8Command);
assertMarkersMatch(ExtractMarker.extractMarkerFromDexFile(output), markerTool(Tool.L8));
}
@@ -156,7 +162,7 @@
parse(
diagnostics,
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
+ libraryDesugaringSpecification.getSpecification().toString(),
"--pg-conf",
pgconf.toString());
}
@@ -171,7 +177,7 @@
parse(
diagnostics,
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
+ libraryDesugaringSpecification.getSpecification().toString(),
"--pg-conf",
pgconf.toString(),
"--pg-map-output",
@@ -193,7 +199,7 @@
parse(
diagnostics,
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
+ libraryDesugaringSpecification.getSpecification().toString(),
"--pg-conf",
pgconf.toString(),
"--classfile");
@@ -210,7 +216,7 @@
parse(
diagnostics,
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
+ libraryDesugaringSpecification.getSpecification().toString(),
"--pg-conf");
fail("Expected parse error");
} catch (CompilationFailedException e) {
@@ -220,8 +226,8 @@
private L8Command.Builder prepareBuilder(DiagnosticsHandler handler) {
return L8Command.builder(handler)
- .addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P))
- .addProgramFiles(ToolHelper.getDesugarJDKLibs())
+ .addLibraryFiles(libraryDesugaringSpecification.getLibraryFiles())
+ .addProgramFiles(libraryDesugaringSpecification.getDesugarJdkLibs())
.setMinApiLevel(20);
}
@@ -286,8 +292,7 @@
L8Command.Builder builder =
prepareBuilder(diagnostics)
.setProgramConsumer(programConsumer)
- .addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ .addDesugaredLibraryConfiguration(getDesugaredLibraryConfiguration())
.addProguardConfiguration(keepRules, Origin.unknown());
assertTrue(builder.isShrinking());
assertNotNull(builder.build().getR8Command());
@@ -319,8 +324,7 @@
L8Command.Builder builder1 =
prepareBuilder(diagnostics)
.setProgramConsumer(programConsumer)
- .addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ .addDesugaredLibraryConfiguration(getDesugaredLibraryConfiguration())
.addProguardConfigurationFiles(keepRuleFile);
assertTrue(builder1.isShrinking());
assertNotNull(builder1.build().getR8Command());
@@ -330,8 +334,7 @@
L8Command.Builder builder2 =
prepareBuilder(new TestDiagnosticMessagesImpl())
.setProgramConsumer(DexIndexedConsumer.emptyConsumer())
- .addDesugaredLibraryConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()))
+ .addDesugaredLibraryConfiguration(getDesugaredLibraryConfiguration())
.addProguardConfigurationFiles(keepRuleFiles);
assertTrue(builder2.isShrinking());
assertNotNull(builder2.build().getR8Command());
@@ -356,12 +359,14 @@
@Test
public void desugaredLibrary() throws CompilationFailedException, IOException {
- L8Command l8Command =
- parse(
- "--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString(),
- "--lib",
- ToolHelper.getAndroidJar(AndroidApiLevel.R).toString());
+ ArrayList<String> command = new ArrayList<>();
+ command.add("--desugared-lib");
+ command.add(libraryDesugaringSpecification.getSpecification().toString());
+ for (Path libraryFile : libraryDesugaringSpecification.getLibraryFiles()) {
+ command.add("--lib");
+ command.add(libraryFile.toString());
+ }
+ L8Command l8Command = parse(command.toArray(new String[0]));
InternalOptions options = getOptionsWithLoadedDesugaredLibraryConfiguration(l8Command, true);
assertFalse(options.machineDesugaredLibrarySpecification.getRewriteType().isEmpty());
}
@@ -403,21 +408,21 @@
parse(
"--force-enable-assertions",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
AssertionsConfiguration::isCompileTimeEnabled);
checkSingleForceAllAssertion(
parse(
"--force-disable-assertions",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
AssertionsConfiguration::isCompileTimeDisabled);
checkSingleForceAllAssertion(
parse(
"--force-passthrough-assertions",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
AssertionsConfiguration::isPassthrough);
checkSingleForceClassAndPackageAssertion(
@@ -425,7 +430,7 @@
"--force-enable-assertions:ClassName",
"--force-enable-assertions:PackageName...",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
AssertionsConfiguration::isCompileTimeEnabled);
checkSingleForceClassAndPackageAssertion(
@@ -433,7 +438,7 @@
"--force-disable-assertions:ClassName",
"--force-disable-assertions:PackageName...",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
AssertionsConfiguration::isCompileTimeDisabled);
checkSingleForceClassAndPackageAssertion(
@@ -441,14 +446,14 @@
"--force-passthrough-assertions:ClassName",
"--force-passthrough-assertions:PackageName...",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
AssertionsConfiguration::isPassthrough);
checkSingleForceAllAssertion(
parse(
"--force-assertions-handler:com.example.MyHandler.handler",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
configuration ->
configuration.isAssertionHandler()
@@ -466,7 +471,7 @@
"--force-assertions-handler:com.example.MyHandler.handler1:ClassName",
"--force-assertions-handler:com.example.MyHandler.handler2:PackageName...",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getAssertionsConfiguration(),
configuration ->
configuration.isAssertionHandler()
@@ -496,7 +501,7 @@
public void numThreadsOption() throws Exception {
assertEquals(
ThreadUtils.NOT_SPECIFIED,
- parse("--desugared-lib", ToolHelper.getDesugarLibJsonForTesting().toString())
+ parse("--desugared-lib", libraryDesugaringSpecification.getSpecification().toString())
.getThreadCount());
assertEquals(
1,
@@ -504,7 +509,7 @@
"--thread-count",
"1",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getThreadCount());
assertEquals(
2,
@@ -512,7 +517,7 @@
"--thread-count",
"2",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getThreadCount());
assertEquals(
10,
@@ -520,7 +525,7 @@
"--thread-count",
"10",
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString())
+ libraryDesugaringSpecification.getSpecification().toString())
.getThreadCount());
}
@@ -535,7 +540,7 @@
"--thread-count",
value,
"--desugared-lib",
- ToolHelper.getDesugarLibJsonForTesting().toString()));
+ libraryDesugaringSpecification.getSpecification().toString()));
fail("Expected failure");
} catch (CompilationFailedException e) {
// Expected.
@@ -551,7 +556,9 @@
@Override
String[] requiredArgsForTest() {
- return new String[] {"--desugared-lib", ToolHelper.getDesugarLibJsonForTesting().toString()};
+ return new String[] {
+ "--desugared-lib", libraryDesugaringSpecification.getSpecification().toString()
+ };
}
@Override
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ExtractWrapperTypesTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ExtractWrapperTypesTest.java
index 40486c3..3ab4008 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ExtractWrapperTypesTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ExtractWrapperTypesTest.java
@@ -291,8 +291,8 @@
Path out = temp.newFolder().toPath();
GenerateLintFiles desugaredApi =
new GenerateLintFiles(
- ToolHelper.getDesugarLibJsonForTesting().toString(),
- ToolHelper.getDesugarJDKLibs().toString(),
+ libraryDesugaringSpecification.getSpecification().toString(),
+ libraryDesugaringSpecification.getDesugarJdkLibs().toString(),
out.toString());
desugaredApi.run(targetApi.getLevel());
return new CodeInspector(
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/specification/ConvertExportReadTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/specification/ConvertExportReadTest.java
index 4b6506c..7c98dbe 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/specification/ConvertExportReadTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/specification/ConvertExportReadTest.java
@@ -59,8 +59,7 @@
MultiAPILevelLegacyDesugaredLibrarySpecification spec =
new MultiAPILevelLegacyDesugaredLibrarySpecificationParser(
options.dexItemFactory(), options.reporter)
- .parseMultiLevelConfiguration(
- StringResource.fromFile(ToolHelper.getDesugarLibJsonForTesting()));
+ .parseMultiLevelConfiguration(StringResource.fromFile(legacySpec.getSpecification()));
MultiAPILevelHumanDesugaredLibrarySpecification humanSpec1 =
converter.convertAllAPILevels(