Support resources shrinking in compiledump
Bug: 287398085
Change-Id: Iff5cc5595d9346be8d83a76ca121d08975c925fa
diff --git a/src/main/java/com/android/tools/r8/utils/CompileDumpCompatR8.java b/src/main/java/com/android/tools/r8/utils/CompileDumpCompatR8.java
index cd01544..2421d95 100644
--- a/src/main/java/com/android/tools/r8/utils/CompileDumpCompatR8.java
+++ b/src/main/java/com/android/tools/r8/utils/CompileDumpCompatR8.java
@@ -3,6 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.utils;
+import com.android.tools.r8.ArchiveProtoAndroidResourceConsumer;
+import com.android.tools.r8.ArchiveProtoAndroidResourceProvider;
import com.android.tools.r8.CompatProguardCommandBuilder;
import com.android.tools.r8.CompilationFailedException;
import com.android.tools.r8.CompilationMode;
@@ -64,7 +66,7 @@
"--startup-profile");
private static final List<String> VALID_OPTIONS_WITH_TWO_OPERANDS =
- Arrays.asList("--art-profile", "--feature-jar");
+ Arrays.asList("--art-profile", "--feature-jar", "--android-resources");
private static boolean FileUtils_isArchive(Path path) {
String name = path.getFileName().toString().toLowerCase(Locale.ROOT);
@@ -91,6 +93,8 @@
List<Path> mainDexRulesFiles = new ArrayList<>();
Map<Path, Path> artProfileFiles = new LinkedHashMap<>();
List<Path> startupProfileFiles = new ArrayList<>();
+ Path androidResourcesInput = null;
+ Path androidResourcesOutput = null;
int minApi = 1;
int threads = -1;
boolean enableMissingLibraryApiModeling = false;
@@ -202,6 +206,12 @@
artProfileFiles.put(Paths.get(firstOperand), Paths.get(secondOperand));
break;
}
+ case "--android-resources":
+ {
+ androidResourcesInput = Paths.get(firstOperand);
+ androidResourcesOutput = Paths.get(secondOperand);
+ break;
+ }
case "--feature-jar":
{
Path featureIn = Paths.get(firstOperand);
@@ -237,6 +247,13 @@
if (desugaredLibJson != null) {
commandBuilder.addDesugaredLibraryConfiguration(readAllBytesJava7(desugaredLibJson));
}
+ if (androidResourcesInput != null) {
+ commandBuilder.setAndroidResourceProvider(
+ new ArchiveProtoAndroidResourceProvider(androidResourcesInput));
+ assert androidResourcesOutput != null;
+ commandBuilder.setAndroidResourceConsumer(
+ new ArchiveProtoAndroidResourceConsumer(androidResourcesOutput));
+ }
if (desugaredLibKeepRuleConsumer != null) {
commandBuilder.setDesugaredLibraryKeepRuleConsumer(desugaredLibKeepRuleConsumer);
}
diff --git a/tools/compiledump.py b/tools/compiledump.py
index 83f775d..66a2152 100755
--- a/tools/compiledump.py
+++ b/tools/compiledump.py
@@ -223,6 +223,9 @@
def main_dex_rules_resource(self):
return self.if_exists('main-dex-rules.txt')
+ def resource_ap_file(self):
+ return self.if_exists('app-res.ap_')
+
def art_profile_resources(self):
art_profile_resources = []
while True:
@@ -633,6 +636,10 @@
cmd.append('--isolated-splits')
if dump.library_jar():
cmd.extend(['--lib', dump.library_jar()])
+ if dump.resource_ap_file():
+ res_output = os.path.join(temp, 'ap-res-out.ap_')
+ cmd.extend(['--android-resources', dump.resource_ap_file(),
+ res_output])
if dump.classpath_jar() and not is_l8_compiler(compiler):
cmd.extend([
'--target' if compiler == 'tracereferences' else '--classpath',