diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java | 17 | ||||
-rw-r--r-- | java/com/google/devtools/build/android/desugar/Desugar.java | 26 |
2 files changed, 29 insertions, 14 deletions
diff --git a/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java b/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java index 72c7edd..90e6bc0 100644 --- a/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java +++ b/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java @@ -17,8 +17,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import java.lang.reflect.Method; import java.util.Iterator; import java.util.LinkedHashSet; @@ -37,21 +37,24 @@ class CoreLibrarySupport { private final CoreLibraryRewriter rewriter; private final ClassLoader targetLoader; /** Internal name prefixes that we want to move to a custom package. */ - private final ImmutableList<String> renamedPrefixes; + private final ImmutableSet<String> renamedPrefixes; /** Internal names of interfaces whose default and static interface methods we'll emulate. */ - private final ImmutableList<Class<?>> emulatedInterfaces; + private final ImmutableSet<Class<?>> emulatedInterfaces; /** Map from {@code owner#name} core library members to their new owners. */ private final ImmutableMap<String, String> memberMoves; - public CoreLibrarySupport(CoreLibraryRewriter rewriter, ClassLoader targetLoader, - ImmutableList<String> renamedPrefixes, ImmutableList<String> emulatedInterfaces, + public CoreLibrarySupport( + CoreLibraryRewriter rewriter, + ClassLoader targetLoader, + List<String> renamedPrefixes, + List<String> emulatedInterfaces, List<String> memberMoves) { this.rewriter = rewriter; this.targetLoader = targetLoader; checkArgument( renamedPrefixes.stream().allMatch(prefix -> prefix.startsWith("java/")), renamedPrefixes); - this.renamedPrefixes = renamedPrefixes; - ImmutableList.Builder<Class<?>> classBuilder = ImmutableList.builder(); + this.renamedPrefixes = ImmutableSet.copyOf(renamedPrefixes); + ImmutableSet.Builder<Class<?>> classBuilder = ImmutableSet.builder(); for (String itf : emulatedInterfaces) { checkArgument(itf.startsWith("java/util/"), itf); Class<?> clazz = loadFromInternal(rewriter.getPrefix() + itf); diff --git a/java/com/google/devtools/build/android/desugar/Desugar.java b/java/com/google/devtools/build/android/desugar/Desugar.java index eee8802..0fad8c2 100644 --- a/java/com/google/devtools/build/android/desugar/Desugar.java +++ b/java/com/google/devtools/build/android/desugar/Desugar.java @@ -196,6 +196,15 @@ class Desugar { public boolean tolerateMissingDependencies; @Option( + name = "desugar_supported_core_libs", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Enable core library desugaring, which requires configuration with related flags." + ) + public boolean desugarCoreLibs; + + @Option( name = "desugar_interface_method_bodies_if_needed", defaultValue = "true", category = "misc", @@ -393,15 +402,14 @@ class Desugar { ImmutableSet.Builder<String> interfaceLambdaMethodCollector = ImmutableSet.builder(); ClassVsInterface interfaceCache = new ClassVsInterface(classpathReader); CoreLibrarySupport coreLibrarySupport = - options.rewriteCoreLibraryPrefixes.isEmpty() - && options.emulateCoreLibraryInterfaces.isEmpty() - ? null - : new CoreLibrarySupport( + options.desugarCoreLibs + ? new CoreLibrarySupport( rewriter, loader, - ImmutableList.copyOf(options.rewriteCoreLibraryPrefixes), - ImmutableList.copyOf(options.emulateCoreLibraryInterfaces), - options.retargetCoreLibraryMembers); + options.rewriteCoreLibraryPrefixes, + options.emulateCoreLibraryInterfaces, + options.retargetCoreLibraryMembers) + : null; desugarClassesInInput( inputFiles, @@ -900,6 +908,10 @@ class Desugar { for (Path path : options.bootclasspath) { checkArgument(!Files.isDirectory(path), "Bootclasspath entry must be a jar file: %s", path); } + checkArgument(!options.desugarCoreLibs + || !options.rewriteCoreLibraryPrefixes.isEmpty() + || !options.emulateCoreLibraryInterfaces.isEmpty(), + "--desugar_supported_core_libs requires specifying renamed and/or emulated core libraries"); return options; } |