Allow test usage of resource shrinker dependencies
The depsjar needs to be include for the test to actually use any
functionality from the transitive dependencies of the resource shrinker.
This also allows for easier access to utility methods in the proto library for the resource model should we need it.
Bug: b/287398085
Change-Id: I54f124e40eb0da0f646dddd8054336ae42c736b5
diff --git a/d8_r8/test_modules/tests_java_8/build.gradle.kts b/d8_r8/test_modules/tests_java_8/build.gradle.kts
index 5c1ef38..4d75106 100644
--- a/d8_r8/test_modules/tests_java_8/build.gradle.kts
+++ b/d8_r8/test_modules/tests_java_8/build.gradle.kts
@@ -32,6 +32,7 @@
implementation(keepAnnoJarTask.outputs.files)
implementation(projectTask("main", "jar").outputs.files)
implementation(projectTask("resourceshrinker", "jar").outputs.files)
+ implementation(projectTask("resourceshrinker", "depsJar").outputs.files)
implementation(Deps.asm)
implementation(Deps.asmCommons)
implementation(Deps.asmUtil)
@@ -149,6 +150,7 @@
withType<KotlinCompile> {
dependsOn(gradle.includedBuild("keepanno").task(":jar"))
+ dependsOn(gradle.includedBuild("resourceshrinker").task(":jar"))
dependsOn(gradle.includedBuild("main").task(":jar"))
dependsOn(thirdPartyCompileDependenciesTask)
kotlinOptions {
@@ -177,6 +179,7 @@
val depsJar by registering(Jar::class) {
dependsOn(gradle.includedBuild("keepanno").task(":jar"))
+ dependsOn(gradle.includedBuild("resourceshrinker").task(":jar"))
dependsOn(thirdPartyCompileDependenciesTask)
doFirst {
println(header("Test Java 8 dependencies"))
diff --git a/src/main/java/com/android/tools/r8/utils/resourceshrinker/ResourceTracingImpl.java b/src/main/java/com/android/tools/r8/utils/resourceshrinker/ResourceTracingImpl.java
index c9ff5b1..d600063 100644
--- a/src/main/java/com/android/tools/r8/utils/resourceshrinker/ResourceTracingImpl.java
+++ b/src/main/java/com/android/tools/r8/utils/resourceshrinker/ResourceTracingImpl.java
@@ -6,8 +6,12 @@
import com.android.build.shrinker.r8integration.R8ResourceShrinkerState;
import com.android.tools.r8.AndroidResourceConsumer;
+import com.android.tools.r8.AndroidResourceInput;
+import com.android.tools.r8.AndroidResourceInput.Kind;
import com.android.tools.r8.AndroidResourceProvider;
import com.android.tools.r8.DiagnosticsHandler;
+import com.android.tools.r8.ResourceException;
+import com.android.tools.r8.errors.CompilationError;
import com.android.tools.r8.utils.ResourceTracing;
import java.util.Collections;
import java.util.List;
@@ -30,10 +34,16 @@
@Override
public void setProvider(AndroidResourceProvider provider) {
this.provider = provider;
- new R8ResourceShrinkerState();
- // TODO(b/287398085): Instantiate with resource table, currently the resource table in the tests
- // is not valid. This just ensures that we can access the class from r8 with the new gradle
- // setup.
+ R8ResourceShrinkerState r8ResourceShrinkerState = new R8ResourceShrinkerState();
+ try {
+ for (AndroidResourceInput androidResource : provider.getAndroidResources()) {
+ if (androidResource.getKind() == Kind.RESOURCE_TABLE) {
+ r8ResourceShrinkerState.setResourceTableInput(androidResource.getByteStream());
+ }
+ }
+ } catch (ResourceException e) {
+ throw new CompilationError("Failed reading the resource table inputs", e);
+ }
}
@Override