Add d8 desugar of library libs support.
@@ -22,6 +22,7 @@ import com.android.tools.r8.D8;
import com.android.tools.r8.D8Command;
import com.android.tools.r8.Diagnostic;
import com.android.tools.r8.DiagnosticsHandler;
+import com.android.tools.r8.StringResource;
import com.android.tools.r8.errors.InterfaceDesugarMissingTypeDiagnostic;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.android.Converters.ExistingPathConverter;
@@ -338,6 +339,18 @@ public class Desugar {
metadataTags = {OptionMetadataTag.HIDDEN},
help = "Run as a Bazel persistent worker.")
public boolean persistentWorker;
+
+ @Option(
+ name = "desugared_lib_config",
+ defaultValue = "null",
+ category = "input",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ converter = ExistingPathConverter.class,
+ help =
+ "Specify desugared library configuration. "
+ + "The input file is a desugared library configuration (json)")
+ public Path desugaredLibConfig;
}
private final DesugarOptions options;
@@ -411,7 +424,8 @@ public class Desugar {
List<ClassFileResourceProvider> bootclasspathProviders,
ClassFileResourceProvider classpath,
Path input,
- Path output)
+ Path output,
+ Path desugaredLibConfig)
throws CompilationFailedException {
checkArgument(!Files.isDirectory(input), "Input must be a jar (%s is a directory)", input);
DependencyCollector dependencyCollector = createDependencyCollector();
@@ -424,6 +438,9 @@ public class Desugar {
.setMinApiLevel(options.minSdkVersion)
.setProgramConsumer(consumer);
bootclasspathProviders.forEach(builder::addLibraryResourceProvider);
+ if (desugaredLibConfig != null) {
+ builder.addDesugaredLibraryConfiguration(StringResource.fromFile(desugaredLibConfig));
+ }
D8.run(builder.build());
}
@@ -458,7 +475,8 @@ public class Desugar {
bootclasspathProviders,
classpathProvider,
options.inputJars.get(i),
- options.outputJars.get(i));
+ options.outputJars.get(i),
+ options.desugaredLibConfig);
}
}
@@ -493,7 +511,11 @@ public class Desugar {
throw new AssertionError("--best_effort_tolerate_missing_deps must be enabled");
}
if (options.desugarCoreLibs) {
- throw new AssertionError("--desugar_supported_core_libs is not supported");
+ if (options.desugaredLibConfig == null) {
+ throw new AssertionError(
+ "If --desugar_supported_core_libs is set --desugared_lib_config "
+ + " must also be set.");
+ }
}
if (!options.desugarInterfaceMethodBodiesIfNeeded) {
throw new AssertionError("--desugar_interface_method_bodies_if_needed must be enabled");
