AAPT2: Introduce notion of 'product' to ResourceTable

This allows us to preserve the various product definitions during the compile
phase, and allows us to select the product in the link phase.

This allows compiled files to remain product-independent, so that they do not need
to be recompiled when switching targets.

Bug:25958912
Change-Id: Iaa7eed25c834b67a39cdc9be43613e8b5ab6cdd7
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index cf0fcd1..3450de9 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -48,24 +48,13 @@
     }
 
     ::testing::AssertionResult testParse(const StringPiece& str) {
-        return testParse(str, ConfigDescription{}, {});
+        return testParse(str, ConfigDescription{});
     }
 
     ::testing::AssertionResult testParse(const StringPiece& str, const ConfigDescription& config) {
-        return testParse(str, config, {});
-    }
-
-    ::testing::AssertionResult testParse(const StringPiece& str,
-                                         std::initializer_list<std::u16string> products) {
-        return testParse(str, {}, std::move(products));
-    }
-
-    ::testing::AssertionResult testParse(const StringPiece& str, const ConfigDescription& config,
-                                         std::initializer_list<std::u16string> products) {
         std::stringstream input(kXmlPreamble);
         input << "<resources>\n" << str << "\n</resources>" << std::endl;
         ResourceParserOptions parserOptions;
-        parserOptions.products = products;
         ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{ "test" }, config,
                               parserOptions);
         xml::XmlPullParser xmlParser(input);
@@ -546,7 +535,7 @@
     ASSERT_NE(nullptr, id);
 }
 
-TEST_F(ResourceParserTest, FilterProductsThatDontMatch) {
+TEST_F(ResourceParserTest, KeepAllProducts) {
     std::string input = R"EOF(
         <string name="foo" product="phone">hi</string>
         <string name="foo" product="no-sdcard">ho</string>
@@ -555,33 +544,26 @@
         <string name="bit" product="phablet">hoot</string>
         <string name="bot" product="default">yes</string>
     )EOF";
-    ASSERT_TRUE(testParse(input, { std::u16string(u"no-sdcard"), std::u16string(u"phablet") }));
+    ASSERT_TRUE(testParse(input));
 
-    String* fooStr = test::getValue<String>(&mTable, u"@string/foo");
-    ASSERT_NE(nullptr, fooStr);
-    EXPECT_EQ(StringPiece16(u"ho"), *fooStr->value);
-
-    EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bar"));
-    EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/baz"));
-    EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bit"));
-    EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bot"));
-}
-
-TEST_F(ResourceParserTest, FilterProductsThatBothMatchInOrder) {
-    std::string input = R"EOF(
-        <string name="foo" product="phone">phone</string>
-        <string name="foo" product="default">default</string>
-    )EOF";
-    ASSERT_TRUE(testParse(input, { std::u16string(u"phone") }));
-
-    String* foo = test::getValue<String>(&mTable, u"@string/foo");
-    ASSERT_NE(nullptr, foo);
-    EXPECT_EQ(std::u16string(u"phone"), *foo->value);
-}
-
-TEST_F(ResourceParserTest, FailWhenProductFilterStripsOutAllVersionsOfResource) {
-    std::string input = "<string name=\"foo\" product=\"tablet\">hello</string>\n";
-    ASSERT_FALSE(testParse(input, { std::u16string(u"phone") }));
+    EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, u"@string/foo",
+                                                                 ConfigDescription::defaultConfig(),
+                                                                 "phone"));
+    EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, u"@string/foo",
+                                                                 ConfigDescription::defaultConfig(),
+                                                                 "no-sdcard"));
+    EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, u"@string/bar",
+                                                                 ConfigDescription::defaultConfig(),
+                                                                 ""));
+    EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, u"@string/baz",
+                                                                 ConfigDescription::defaultConfig(),
+                                                                 ""));
+    EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, u"@string/bit",
+                                                                 ConfigDescription::defaultConfig(),
+                                                                 "phablet"));
+    EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, u"@string/bot",
+                                                                 ConfigDescription::defaultConfig(),
+                                                                 "default"));
 }
 
 TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) {