Loading tools/aapt2/Format.proto +1 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ message SymbolStatus { optional Visibility visibility = 1; optional Source source = 2; optional string comment = 3; optional bool allow_new = 4; } message Entry { Loading tools/aapt2/ResourceParser.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -92,14 +92,14 @@ struct ParsedResource { Source source; ResourceId id; Maybe<SymbolState> symbol_state; bool allow_new = false; std::string comment; std::unique_ptr<Value> value; std::list<ParsedResource> child_resources; }; // Recursively adds resources to the ResourceTable. static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, ParsedResource* res) { static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, ParsedResource* res) { StringPiece trimmed_comment = util::TrimWhitespace(res->comment); if (trimmed_comment.size() != res->comment.size()) { // Only if there was a change do we re-assign. Loading @@ -111,6 +111,7 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, symbol.state = res->symbol_state.value(); symbol.source = res->source; symbol.comment = res->comment; symbol.allow_new = res->allow_new; if (!table->SetSymbolState(res->name, res->id, symbol, diag)) { return false; } Loading @@ -121,8 +122,8 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, res->value->SetComment(std::move(res->comment)); res->value->SetSource(std::move(res->source)); if (!table->AddResource(res->name, res->id, res->config, res->product, std::move(res->value), diag)) { if (!table->AddResource(res->name, res->id, res->config, res->product, std::move(res->value), diag)) { return false; } } Loading Loading @@ -849,6 +850,7 @@ bool ResourceParser::ParseAddResource(xml::XmlPullParser* parser, ParsedResource* out_resource) { if (ParseSymbolImpl(parser, out_resource)) { out_resource->symbol_state = SymbolState::kUndefined; out_resource->allow_new = true; return true; } return false; Loading tools/aapt2/ResourceParser_test.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -777,8 +777,7 @@ TEST_F(ResourceParserTest, ExternalTypesShouldOnlyBeReferences) { ASSERT_FALSE(TestParse(input)); } TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) { TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) { std::string input = R"EOF(<add-resource name="bar" type="string" />)EOF"; ASSERT_TRUE(TestParse(input)); Loading @@ -788,6 +787,7 @@ TEST_F(ResourceParserTest, const ResourceEntry* entry = result.value().entry; ASSERT_NE(nullptr, entry); EXPECT_EQ(SymbolState::kUndefined, entry->symbol_status.state); EXPECT_TRUE(entry->symbol_status.allow_new); } TEST_F(ResourceParserTest, ParseItemElementWithFormat) { Loading tools/aapt2/ResourceTable.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -440,8 +440,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI return true; } bool ResourceTable::SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id, bool ResourceTable::SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id, const Symbol& symbol, IDiagnostics* diag) { return SetSymbolStateImpl(name, res_id, symbol, ValidateName, diag); } Loading Loading @@ -489,8 +488,7 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour diag->Error(DiagMessage(symbol.source) << "trying to add resource '" << name << "' with ID " << res_id << " but resource already has ID " << ResourceId(package->id.value(), type->id.value(), entry->id.value())); << ResourceId(package->id.value(), type->id.value(), entry->id.value())); return false; } Loading @@ -505,6 +503,11 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour type->symbol_status.state = SymbolState::kPublic; } if (symbol.allow_new) { // This symbol can be added as a new resource when merging (if it belongs to an overlay). entry->symbol_status.allow_new = true; } if (symbol.state == SymbolState::kUndefined && entry->symbol_status.state != SymbolState::kUndefined) { // We can't undefine a symbol (remove its visibility). Ignore. Loading @@ -517,7 +520,10 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour return true; } entry->symbol_status = std::move(symbol); // This symbol definition takes precedence, replace. entry->symbol_status.state = symbol.state; entry->symbol_status.source = symbol.source; entry->symbol_status.comment = symbol.comment; return true; } Loading tools/aapt2/ResourceTable.h +5 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ enum class SymbolState { struct Symbol { SymbolState state = SymbolState::kUndefined; Source source; // Whether this entry (originating from an overlay) can be added as a new resource. bool allow_new = false; std::string comment; }; Loading Loading @@ -223,8 +227,7 @@ class ResourceTable { bool SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id, const Symbol& symbol, IDiagnostics* diag); bool SetSymbolStateAllowMangled(const ResourceNameRef& name, const ResourceId& res_id, bool SetSymbolStateAllowMangled(const ResourceNameRef& name, const ResourceId& res_id, const Symbol& symbol, IDiagnostics* diag); struct SearchResult { Loading Loading
tools/aapt2/Format.proto +1 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ message SymbolStatus { optional Visibility visibility = 1; optional Source source = 2; optional string comment = 3; optional bool allow_new = 4; } message Entry { Loading
tools/aapt2/ResourceParser.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -92,14 +92,14 @@ struct ParsedResource { Source source; ResourceId id; Maybe<SymbolState> symbol_state; bool allow_new = false; std::string comment; std::unique_ptr<Value> value; std::list<ParsedResource> child_resources; }; // Recursively adds resources to the ResourceTable. static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, ParsedResource* res) { static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, ParsedResource* res) { StringPiece trimmed_comment = util::TrimWhitespace(res->comment); if (trimmed_comment.size() != res->comment.size()) { // Only if there was a change do we re-assign. Loading @@ -111,6 +111,7 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, symbol.state = res->symbol_state.value(); symbol.source = res->source; symbol.comment = res->comment; symbol.allow_new = res->allow_new; if (!table->SetSymbolState(res->name, res->id, symbol, diag)) { return false; } Loading @@ -121,8 +122,8 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, res->value->SetComment(std::move(res->comment)); res->value->SetSource(std::move(res->source)); if (!table->AddResource(res->name, res->id, res->config, res->product, std::move(res->value), diag)) { if (!table->AddResource(res->name, res->id, res->config, res->product, std::move(res->value), diag)) { return false; } } Loading Loading @@ -849,6 +850,7 @@ bool ResourceParser::ParseAddResource(xml::XmlPullParser* parser, ParsedResource* out_resource) { if (ParseSymbolImpl(parser, out_resource)) { out_resource->symbol_state = SymbolState::kUndefined; out_resource->allow_new = true; return true; } return false; Loading
tools/aapt2/ResourceParser_test.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -777,8 +777,7 @@ TEST_F(ResourceParserTest, ExternalTypesShouldOnlyBeReferences) { ASSERT_FALSE(TestParse(input)); } TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) { TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) { std::string input = R"EOF(<add-resource name="bar" type="string" />)EOF"; ASSERT_TRUE(TestParse(input)); Loading @@ -788,6 +787,7 @@ TEST_F(ResourceParserTest, const ResourceEntry* entry = result.value().entry; ASSERT_NE(nullptr, entry); EXPECT_EQ(SymbolState::kUndefined, entry->symbol_status.state); EXPECT_TRUE(entry->symbol_status.allow_new); } TEST_F(ResourceParserTest, ParseItemElementWithFormat) { Loading
tools/aapt2/ResourceTable.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -440,8 +440,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI return true; } bool ResourceTable::SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id, bool ResourceTable::SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id, const Symbol& symbol, IDiagnostics* diag) { return SetSymbolStateImpl(name, res_id, symbol, ValidateName, diag); } Loading Loading @@ -489,8 +488,7 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour diag->Error(DiagMessage(symbol.source) << "trying to add resource '" << name << "' with ID " << res_id << " but resource already has ID " << ResourceId(package->id.value(), type->id.value(), entry->id.value())); << ResourceId(package->id.value(), type->id.value(), entry->id.value())); return false; } Loading @@ -505,6 +503,11 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour type->symbol_status.state = SymbolState::kPublic; } if (symbol.allow_new) { // This symbol can be added as a new resource when merging (if it belongs to an overlay). entry->symbol_status.allow_new = true; } if (symbol.state == SymbolState::kUndefined && entry->symbol_status.state != SymbolState::kUndefined) { // We can't undefine a symbol (remove its visibility). Ignore. Loading @@ -517,7 +520,10 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour return true; } entry->symbol_status = std::move(symbol); // This symbol definition takes precedence, replace. entry->symbol_status.state = symbol.state; entry->symbol_status.source = symbol.source; entry->symbol_status.comment = symbol.comment; return true; } Loading
tools/aapt2/ResourceTable.h +5 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ enum class SymbolState { struct Symbol { SymbolState state = SymbolState::kUndefined; Source source; // Whether this entry (originating from an overlay) can be added as a new resource. bool allow_new = false; std::string comment; }; Loading Loading @@ -223,8 +227,7 @@ class ResourceTable { bool SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id, const Symbol& symbol, IDiagnostics* diag); bool SetSymbolStateAllowMangled(const ResourceNameRef& name, const ResourceId& res_id, bool SetSymbolStateAllowMangled(const ResourceNameRef& name, const ResourceId& res_id, const Symbol& symbol, IDiagnostics* diag); struct SearchResult { Loading