AAPT2: Merge Styleables instead of overriding them
Styleables merge in AAPT. Preserve this behavior.
Bug:30970091
Change-Id: Ie68ca675aeecd873c0648682182e2fc574e329a0
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp
index 73682ab..321f776 100644
--- a/tools/aapt2/ResourceValues.cpp
+++ b/tools/aapt2/ResourceValues.cpp
@@ -24,6 +24,7 @@
#include <algorithm>
#include <androidfw/ResourceTypes.h>
#include <limits>
+#include <set>
namespace aapt {
@@ -732,4 +733,27 @@
<< "]";
}
+bool operator<(const Reference& a, const Reference& b) {
+ int cmp = a.name.valueOrDefault({}).compare(b.name.valueOrDefault({}));
+ if (cmp != 0) return cmp < 0;
+ return a.id < b.id;
+}
+
+bool operator==(const Reference& a, const Reference& b) {
+ return a.name == b.name && a.id == b.id;
+}
+
+bool operator!=(const Reference& a, const Reference& b) {
+ return a.name != b.name || a.id != b.id;
+}
+
+void Styleable::mergeWith(Styleable* other) {
+ std::set<Reference> references;
+ references.insert(entries.begin(), entries.end());
+ references.insert(other->entries.begin(), other->entries.end());
+ entries.clear();
+ entries.reserve(references.size());
+ entries.insert(entries.end(), references.begin(), references.end());
+}
+
} // namespace aapt