AAPT2: Support static lib referencing static lib

When a static library A references static library B,
and app C references both A and B, we get the following symbol merging,
symbols from library B get imported twice.

We must only check that symbol references to library B are valid
when building library A. We should only merge all the symbols
when building final app C.

Change-Id: I23cba33b0901dcbb5328d9c9dfaa6a979c073c36
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp
index 2bf38e4..be0c3f3 100644
--- a/tools/aapt2/ResourceValues.cpp
+++ b/tools/aapt2/ResourceValues.cpp
@@ -101,8 +101,8 @@
 }
 
 bool Id::flatten(android::Res_value& out) const {
-    out.dataType = android::Res_value::TYPE_NULL;
-    out.data = android::Res_value::DATA_NULL_UNDEFINED;
+    out.dataType = android::Res_value::TYPE_INT_BOOLEAN;
+    out.data = 0;
     return true;
 }
 
@@ -231,17 +231,15 @@
     return attr;
 }
 
-void Attribute::print(std::ostream& out) const {
-    out << "(attr)";
+void Attribute::printMask(std::ostream& out) const {
     if (typeMask == android::ResTable_map::TYPE_ANY) {
-        out << " any";
+        out << "any";
         return;
     }
 
     bool set = false;
     if ((typeMask & android::ResTable_map::TYPE_REFERENCE) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -251,7 +249,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_STRING) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -261,7 +258,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_INTEGER) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -271,7 +267,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_BOOLEAN) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -281,7 +276,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_COLOR) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -291,7 +285,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_FLOAT) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -301,7 +294,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_DIMENSION) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -311,7 +303,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_FRACTION) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -321,7 +312,6 @@
 
     if ((typeMask & android::ResTable_map::TYPE_ENUM) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
@@ -331,13 +321,17 @@
 
     if ((typeMask & android::ResTable_map::TYPE_FLAGS) != 0) {
         if (!set) {
-            out << " ";
             set = true;
         } else {
             out << "|";
         }
         out << "flags";
     }
+}
+
+void Attribute::print(std::ostream& out) const {
+    out << "(attr) ";
+    printMask(out);
 
     out << " ["
         << util::joiner(symbols.begin(), symbols.end(), ", ")
@@ -348,10 +342,6 @@
     }
 }
 
-static ::std::ostream& operator<<(::std::ostream& out, const Attribute::Symbol& s) {
-    return out << s.symbol.name.entry << "=" << s.value;
-}
-
 Style::Style(bool weak) : weak(weak) {
 }