AAPT2: Allow undefined resources (placeholders)
A resource defined like so:
<item type="drawable" name="foo" />
should be assigned the value @null.
The only exception is for <string> resources, which are given the
empty string value (since <string></string> is ambiguous). The decision
to use "" is based off the fact that old AAPT used to assign "" to all
undefined resources, even non-string ones.
Bug: 38425050
Test: make aapt2_tests
Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9
diff --git a/tools/aapt2/test/Common.h b/tools/aapt2/test/Common.h
index a937de8..0585148 100644
--- a/tools/aapt2/test/Common.h
+++ b/tools/aapt2/test/Common.h
@@ -46,27 +46,7 @@
namespace aapt {
namespace test {
-struct DummyDiagnosticsImpl : public IDiagnostics {
- void Log(Level level, DiagMessageActual& actual_msg) override {
- switch (level) {
- case Level::Note:
- return;
-
- case Level::Warn:
- std::cerr << actual_msg.source << ": warn: " << actual_msg.message << "." << std::endl;
- break;
-
- case Level::Error:
- std::cerr << actual_msg.source << ": error: " << actual_msg.message << "." << std::endl;
- break;
- }
- }
-};
-
-inline IDiagnostics* GetDiagnostics() {
- static DummyDiagnosticsImpl diag;
- return &diag;
-}
+IDiagnostics* GetDiagnostics();
inline ResourceName ParseNameOrDie(const android::StringPiece& str) {
ResourceNameRef ref;
@@ -80,7 +60,7 @@
return config;
}
-template <typename T>
+template <typename T = Value>
T* GetValueForConfigAndProduct(ResourceTable* table, const android::StringPiece& res_name,
const ConfigDescription& config,
const android::StringPiece& product) {
@@ -94,13 +74,19 @@
return nullptr;
}
-template <typename T>
+template <>
+Value* GetValueForConfigAndProduct<Value>(ResourceTable* table,
+ const android::StringPiece& res_name,
+ const ConfigDescription& config,
+ const android::StringPiece& product);
+
+template <typename T = Value>
T* GetValueForConfig(ResourceTable* table, const android::StringPiece& res_name,
const ConfigDescription& config) {
return GetValueForConfigAndProduct<T>(table, res_name, config, {});
}
-template <typename T>
+template <typename T = Value>
T* GetValue(ResourceTable* table, const android::StringPiece& res_name) {
return GetValueForConfig<T>(table, res_name, {});
}