AAPT2: Allow compatible duplicate Attributes
If a resource XML file defines two compatible Attributes, they should
be merged without throwing an error. Ex:
<declare-styleable>
<attr name="conflict" format="string" />
</declare-styleable>
<declare-styleable>
<attr name="conflict" format="string|reference" />
</declare-styleable>
In this case, string|reference and string are the same, so these should
merge correctly.
Bug: 65699599
Test: make aapt2_tests
Test: make AaptBasicTest
Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95
diff --git a/tools/aapt2/ResourceTable_test.cpp b/tools/aapt2/ResourceTable_test.cpp
index eb75f94..7fa8ea2 100644
--- a/tools/aapt2/ResourceTable_test.cpp
+++ b/tools/aapt2/ResourceTable_test.cpp
@@ -102,23 +102,37 @@
TEST(ResourceTableTest, OverrideWeakResourceValue) {
ResourceTable table;
- ASSERT_TRUE(table.AddResource(
- test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "",
- util::make_unique<Attribute>(true), test::GetDiagnostics()));
+ ASSERT_TRUE(table.AddResource(test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "",
+ test::AttributeBuilder().SetWeak(true).Build(),
+ test::GetDiagnostics()));
Attribute* attr = test::GetValue<Attribute>(&table, "android:attr/foo");
ASSERT_THAT(attr, NotNull());
EXPECT_TRUE(attr->IsWeak());
- ASSERT_TRUE(table.AddResource(
- test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "",
- util::make_unique<Attribute>(false), test::GetDiagnostics()));
+ ASSERT_TRUE(table.AddResource(test::ParseNameOrDie("android:attr/foo"), ConfigDescription{}, "",
+ util::make_unique<Attribute>(), test::GetDiagnostics()));
attr = test::GetValue<Attribute>(&table, "android:attr/foo");
ASSERT_THAT(attr, NotNull());
EXPECT_FALSE(attr->IsWeak());
}
+TEST(ResourceTableTest, AllowCompatibleDuplicateAttributes) {
+ ResourceTable table;
+
+ const ResourceName name = test::ParseNameOrDie("android:attr/foo");
+ Attribute attr_one(android::ResTable_map::TYPE_STRING);
+ attr_one.SetWeak(true);
+ Attribute attr_two(android::ResTable_map::TYPE_STRING | android::ResTable_map::TYPE_REFERENCE);
+ attr_two.SetWeak(true);
+
+ ASSERT_TRUE(table.AddResource(name, ConfigDescription{}, "",
+ util::make_unique<Attribute>(attr_one), test::GetDiagnostics()));
+ ASSERT_TRUE(table.AddResource(name, ConfigDescription{}, "",
+ util::make_unique<Attribute>(attr_two), test::GetDiagnostics()));
+}
+
TEST(ResourceTableTest, ProductVaryingValues) {
ResourceTable table;