aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-08-07 21:47:54 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-08-08 13:02:47 +0200
commit963db879575132933d9254406b4c76a8f10b0ad1 (patch)
tree917fb0d48edadedd2fd2b97e77b0fbc6f4bc6cf9
parentbd36e5f77c4c891132cb7578779946fa89c394ec (diff)
Remove special ordering of resources from PlaceholderIdFieldInitializerBuilder
Before this change, PlaceholderIdFieldInitializerBuilder attempted to exactly mimic the behavior of Aapt and Gradle in assigning resource IDs. However, nothing should be relying on that specific behavior. Even if code for some reason is relying on that behavior (by, for example, doing math on a resource ID to get another resource ID), this code is currently only used to compile library resource files, which are not actually used in finished android_binary targets. This change removes the part that relies on a specific ordering of ResourceTypes; it instead just relies on the names and ordering within ResourceType. This makes things a bit simpler and also ensures new resource types added to the ResourceType enum will be picked up automatically. In particular, this change will allow us to use the new Font resource type as soon as it is released in android_ide_common. RELNOTES: none PiperOrigin-RevId: 164497262
-rw-r--r--src/test/java/com/google/devtools/build/android/AndroidResourceClassWriterTest.java16
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java59
2 files changed, 14 insertions, 61 deletions
diff --git a/src/test/java/com/google/devtools/build/android/AndroidResourceClassWriterTest.java b/src/test/java/com/google/devtools/build/android/AndroidResourceClassWriterTest.java
index 72eac32a7f..62e20479a6 100644
--- a/src/test/java/com/google/devtools/build/android/AndroidResourceClassWriterTest.java
+++ b/src/test/java/com/google/devtools/build/android/AndroidResourceClassWriterTest.java
@@ -86,11 +86,11 @@ public class AndroidResourceClassWriterTest {
"package com.carroll.lewis;",
"public final class R {",
"public static final class id {",
- "public static int AdiosButton = 0x7f030000;",
- "public static int HelloView = 0x7f030001;",
+ "public static int AdiosButton = 0x7f020000;",
+ "public static int HelloView = 0x7f020001;",
"}",
"public static final class layout {",
- "public static int some_layout = 0x7f020000;",
+ "public static int some_layout = 0x7f030000;",
"}",
"}"
);
@@ -99,17 +99,17 @@ public class AndroidResourceClassWriterTest {
.withClass("com.carroll.lewis.R$id")
.classContentsIsEqualTo(
ImmutableMap.of(
- "AdiosButton", 0x7f030000,
- "HelloView", 0x7f030001),
- ImmutableMap.<String, List<Integer>>of(),
+ "AdiosButton", 0x7f020000,
+ "HelloView", 0x7f020001),
+ ImmutableMap.of(),
false
);
assertAbout(paths)
.that(target)
.withClass("com.carroll.lewis.R$layout")
.classContentsIsEqualTo(
- ImmutableMap.of("some_layout", 0x7f020000),
- ImmutableMap.<String, List<Integer>>of(),
+ ImmutableMap.of("some_layout", 0x7f030000),
+ ImmutableMap.of(),
false
);
}
diff --git a/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java b/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
index 0065f8fc15..1532c63574 100644
--- a/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
+++ b/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
@@ -44,58 +44,6 @@ import java.util.logging.Logger;
* building the android_binary.
*/
class PlaceholderIdFieldInitializerBuilder {
- /**
- * Determine the TT portion of the resource ID (PPTTEEEE) that aapt would have assigned. This not
- * at all alphabetical. It depends on the order in which the types are processed, and whether or
- * not previous types are present (compact). See the code in aapt Resource.cpp:buildResources().
- * There are several seemingly arbitrary and different processing orders in the function, but the
- * ordering is determined specifically by the portion at: <a
- * href="https://android.googlesource.com/platform/frameworks/base.git/+/marshmallow-release/tools/aapt/Resource.cpp#1254">
- * Resource.cpp:buildResources() </a>
- *
- * <p>where it does:
- *
- * <pre>
- * if (drawables != NULL) { ... }
- * if (mipmaps != NULL) { ... }
- * if (layouts != NULL) { ... }
- * </pre>
- *
- * Numbering starts at 1 instead of 0, and ResourceType.ATTR comes before the rest.
- * ResourceType.STYLEABLE doesn't actually need a resource ID, so that is skipped. We encode the
- * ordering in the following list.
- */
- private static final ImmutableList<ResourceType> AAPT_TYPE_ORDERING =
- ImmutableList.of(
- ResourceType.DRAWABLE,
- ResourceType.MIPMAP,
- ResourceType.LAYOUT,
- ResourceType.ANIM,
- ResourceType.ANIMATOR,
- ResourceType.TRANSITION,
- ResourceType.INTERPOLATOR,
- ResourceType.XML,
- ResourceType.RAW,
- // Begin VALUES portion
- // Technically, aapt just assigns according to declaration order in the source value.xml
- // files so it isn't really deterministic. However, the Gradle merger sorts the values.xml
- // file before invoking aapt, so assume that is also done.
- ResourceType.ARRAY,
- ResourceType.BOOL,
- ResourceType.COLOR,
- ResourceType.DIMEN,
- ResourceType.FRACTION,
- ResourceType.ID,
- ResourceType.INTEGER,
- ResourceType.PLURALS,
- ResourceType.STRING,
- ResourceType.STYLE,
- // End VALUES portion
- // Technically, file-based COLOR resources come next. If we care about complete
- // equivalence we should separate the file-based resources from value-based resources so
- // that we can number them the same way.
- ResourceType.MENU);
-
private static final int APP_PACKAGE_MASK = 0x7f000000;
private static final int ATTR_TYPE_ID = 1;
private static final Logger logger =
@@ -370,7 +318,12 @@ class PlaceholderIdFieldInitializerBuilder {
allocatedTypeIds.put(ResourceType.ATTR, ATTR_TYPE_ID);
// The rest are packed after that.
int nextTypeId = nextFreeId(ATTR_TYPE_ID + 1, reservedTypeSlots);
- for (ResourceType t : AAPT_TYPE_ORDERING) {
+ for (ResourceType t : ResourceType.values()) {
+ if (t == ResourceType.ATTR || t == ResourceType.STYLEABLE) {
+ // Styleable and Attr resources are handled specially
+ continue;
+ }
+
if (innerClasses.containsKey(t) && !allocatedTypeIds.containsKey(t)) {
allocatedTypeIds.put(t, nextTypeId);
nextTypeId = nextFreeId(nextTypeId + 1, reservedTypeSlots);