Move testing of styleable attributes out to have seperate R class
This actually shows an issue with the existing resource shrinker where
we remove the attr resources clearly references through the styleable.
Bug: b/319802261
Change-Id: Id618627c3644b93265a9db4709d5fb715a0a0540
diff --git a/src/test/java/com/android/tools/r8/androidresources/AndroidResourceTestingUtils.java b/src/test/java/com/android/tools/r8/androidresources/AndroidResourceTestingUtils.java
index 021902d..e0a3a59 100644
--- a/src/test/java/com/android/tools/r8/androidresources/AndroidResourceTestingUtils.java
+++ b/src/test/java/com/android/tools/r8/androidresources/AndroidResourceTestingUtils.java
@@ -269,7 +269,7 @@
// This takes the actual inner classes (e.g., R$String)
// These R classes will be used to rewrite the namespace and class names on the aapt2
// generated names.
- AndroidTestResourceBuilder addRClassInitializeWithDefaultValues(Class<?>... rClasses) {
+ public AndroidTestResourceBuilder addRClassInitializeWithDefaultValues(Class<?>... rClasses) {
for (Class<?> rClass : rClasses) {
classesToRemap.add(rClass);
RClassType rClassType = RClassType.fromClass(rClass);
@@ -301,7 +301,7 @@
return this;
}
- AndroidTestResourceBuilder withSimpleManifestAndAppNameString() {
+ public AndroidTestResourceBuilder withSimpleManifestAndAppNameString() {
this.manifest = SIMPLE_MANIFEST_WITH_APP_NAME;
addStringValue("app_name", "Most important app ever.");
return this;
@@ -337,7 +337,7 @@
return this;
}
- AndroidTestResource build(TemporaryFolder temp) throws IOException {
+ public AndroidTestResource build(TemporaryFolder temp) throws IOException {
Path manifestPath =
FileUtils.writeTextFile(temp.newFile("AndroidManifest.xml").toPath(), this.manifest);
Path resFolder = temp.newFolder("res").toPath();
diff --git a/src/test/java/com/android/tools/r8/androidresources/optimizedshrinking/R.java b/src/test/java/com/android/tools/r8/androidresources/optimizedshrinking/R.java
new file mode 100644
index 0000000..de7a408
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/androidresources/optimizedshrinking/R.java
@@ -0,0 +1,27 @@
+// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.androidresources.optimizedshrinking;
+
+// For testing the legacy shrinker support for R class indification we use a R class that is not
+// an innner class (the legacy shrinker explicitly match on R$type names, so it will not
+// match SomeTest$R$type).
+public class R {
+ public static class string {
+ public static int bar;
+ public static int foo;
+ public static int unused_string;
+ }
+
+ public static class styleable {
+ public static int[] our_styleable;
+ public static int[] unused_styleable;
+ }
+
+ public static class drawable {
+
+ public static int foobar;
+ public static int unused_drawable;
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/androidresources/TestOptimizedShrinking.java b/src/test/java/com/android/tools/r8/androidresources/optimizedshrinking/TestOptimizedShrinking.java
similarity index 84%
rename from src/test/java/com/android/tools/r8/androidresources/TestOptimizedShrinking.java
rename to src/test/java/com/android/tools/r8/androidresources/optimizedshrinking/TestOptimizedShrinking.java
index 7a396ef..88d9860 100644
--- a/src/test/java/com/android/tools/r8/androidresources/TestOptimizedShrinking.java
+++ b/src/test/java/com/android/tools/r8/androidresources/optimizedshrinking/TestOptimizedShrinking.java
@@ -1,14 +1,13 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8.androidresources;
+package com.android.tools.r8.androidresources.optimizedshrinking;
import com.android.tools.r8.ResourceShrinkerConfiguration;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.androidresources.AndroidResourceTestingUtils.AndroidTestResource;
import com.android.tools.r8.androidresources.AndroidResourceTestingUtils.AndroidTestResourceBuilder;
-import com.android.tools.r8.androidresources.TestOptimizedShrinking.R.styleable;
import com.android.tools.r8.utils.BooleanUtils;
import java.util.List;
import org.junit.Test;
@@ -85,8 +84,14 @@
"styleable", "unused_styleable");
// We do remove the attributes pointed at by the unreachable styleable.
for (int i = 0; i < 4; i++) {
- resourceTableInspector.assertContainsResourceWithName(
- "attr", "attr_our_styleable" + i);
+ if (optimized) {
+ resourceTableInspector.assertContainsResourceWithName(
+ "attr", "attr_our_styleable" + i);
+ } else {
+ // TODO(b/319802261): We should not remove these in legacy mode
+ resourceTableInspector.assertDoesNotContainResourceWithName(
+ "attr", "attr_our_styleable" + i);
+ }
if (!debug || optimized) {
resourceTableInspector.assertDoesNotContainResourceWithName(
"attr", "attr_unused_styleable" + i);
@@ -104,28 +109,8 @@
System.out.println(R.drawable.foobar);
System.out.println(R.string.bar);
System.out.println(R.string.foo);
- System.out.println(styleable.our_styleable);
+ System.out.println(R.styleable.our_styleable);
}
}
}
-
- public static class R {
-
- public static class string {
- public static int bar;
- public static int foo;
- public static int unused_string;
- }
-
- public static class styleable {
- public static int[] our_styleable;
- public static int[] unused_styleable;
- }
-
- public static class drawable {
-
- public static int foobar;
- public static int unused_drawable;
- }
- }
}