From c1f842c00125cbf42e1f3ff67df0da65868794ce Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 11 Aug 2017 17:49:45 +0200 Subject: Use all resource types in PlaceholderIdFieldInitializerBuilder All resource types should be supported by PlaceholderIdFieldInitializerBuilder. Will keeping the ordering from the previous scheme, ensure that all of the contents of ResourceType.values() are considered. This means that, when adding new resource types, only updating the ResourceType enum is needed. A previous attempt at this change tried eliminating the special ordering of resource types entirely, on the grounds that it shouldn't be needed. However, strange build failures mean we're keeping it there for now. RELNOTES: none PiperOrigin-RevId: 164983075 --- .../PlaceholderIdFieldInitializerBuilder.java | 61 +++++++++++++--------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java') 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..12b7abe4ae 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 @@ -27,6 +27,7 @@ import com.google.devtools.build.android.resources.FieldInitializers; import com.google.devtools.build.android.resources.IntArrayFieldInitializer; import com.google.devtools.build.android.resources.IntFieldInitializer; import java.nio.file.Path; +import java.util.Arrays; import java.util.Collection; import java.util.EnumMap; import java.util.HashMap; @@ -44,6 +45,31 @@ import java.util.logging.Logger; * building the android_binary. */ class PlaceholderIdFieldInitializerBuilder { + + private static final ImmutableList INITIAL_TYPES = + ImmutableList.of( + ResourceType.DRAWABLE, + ResourceType.MIPMAP, + ResourceType.LAYOUT, + ResourceType.ANIM, + ResourceType.ANIMATOR, + ResourceType.TRANSITION, + ResourceType.INTERPOLATOR, + ResourceType.XML, + ResourceType.RAW); + + private static final ImmutableSet SPECIALLY_HANDLED_TYPES = + ImmutableSet.builder() + // These types should always be handled first + .addAll(INITIAL_TYPES) + // The ATTR and STYLEABLE types are handled by completely separate code and should not be + // included in the ordered list of types + .add(ResourceType.ATTR) + .add(ResourceType.STYLEABLE) + // The MENU type should always go last + .add(ResourceType.MENU) + .build(); + /** * 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 @@ -66,35 +92,22 @@ class PlaceholderIdFieldInitializerBuilder { * ordering in the following list. */ private static final ImmutableList 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 + ImmutableList.builder() + .addAll(INITIAL_TYPES) + // The 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 + // file before invoking aapt, so use the alphabetically sorted values defined in + // ResourceType here as well. + .addAll( + Arrays.stream(ResourceType.values()) + .filter((x) -> !SPECIALLY_HANDLED_TYPES.contains(x)) + .collect(ImmutableList.toImmutableList())) // 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); + .add(ResourceType.MENU) + .build(); private static final int APP_PACKAGE_MASK = 0x7f000000; private static final int ATTR_TYPE_ID = 1; -- cgit v1.2.3