Loading tools/aapt2/link/TableMerger.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -281,8 +281,17 @@ bool TableMerger::DoMerge(const Source& src, ResourceTable* src_table, dst_config_value->value = std::move(new_file_ref); } else { Maybe<std::string> original_comment = (dst_config_value->value) ? dst_config_value->value->GetComment() : Maybe<std::string>(); dst_config_value->value = std::unique_ptr<Value>( src_config_value->value->Clone(&master_table_->string_pool)); // Keep the comment from the original resource and ignore all comments from overlaying // resources if (overlay && original_comment) { dst_config_value->value->SetComment(original_comment.value()); } } } } Loading tools/aapt2/link/TableMerger_test.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,49 @@ TEST_F(TableMergerTest, OverrideResourceWithOverlay) { Pointee(Field(&BinaryPrimitive::value, Field(&android::Res_value::data, Eq(0u))))); } TEST_F(TableMergerTest, DoNotOverrideResourceComment) { std::unique_ptr<Value> foo_original = ResourceUtils::TryParseBool("true"); foo_original->SetComment(android::StringPiece("Original foo comment")); std::unique_ptr<Value> bar_original = ResourceUtils::TryParseBool("true"); std::unique_ptr<Value> foo_overlay = ResourceUtils::TryParseBool("false"); foo_overlay->SetComment(android::StringPiece("Overlay foo comment")); std::unique_ptr<Value> bar_overlay = ResourceUtils::TryParseBool("false"); bar_overlay->SetComment(android::StringPiece("Overlay bar comment")); std::unique_ptr<Value> baz_overlay = ResourceUtils::TryParseBool("false"); baz_overlay->SetComment(android::StringPiece("Overlay baz comment")); std::unique_ptr<ResourceTable> base = test::ResourceTableBuilder() .SetPackageId("", 0x00) .AddValue("bool/foo", std::move(foo_original)) .AddValue("bool/bar", std::move(bar_original)) .Build(); std::unique_ptr<ResourceTable> overlay = test::ResourceTableBuilder() .SetPackageId("", 0x00) .AddValue("bool/foo", std::move(foo_overlay)) .AddValue("bool/bar", std::move(bar_overlay)) .AddValue("bool/baz", std::move(baz_overlay)) .Build(); ResourceTable final_table; TableMergerOptions options; options.auto_add_overlay = true; TableMerger merger(context_.get(), &final_table, options); ASSERT_TRUE(merger.Merge({}, base.get(), false /*overlay*/)); ASSERT_TRUE(merger.Merge({}, overlay.get(), true /*overlay*/)); BinaryPrimitive* foo = test::GetValue<BinaryPrimitive>(&final_table, "com.app.a:bool/foo"); EXPECT_THAT(foo, Pointee(Property(&BinaryPrimitive::GetComment, StrEq("Original foo comment")))); BinaryPrimitive* bar = test::GetValue<BinaryPrimitive>(&final_table, "com.app.a:bool/bar"); EXPECT_THAT(bar, Pointee(Property(&BinaryPrimitive::GetComment, StrEq("")))); BinaryPrimitive* baz = test::GetValue<BinaryPrimitive>(&final_table, "com.app.a:bool/baz"); EXPECT_THAT(baz, Pointee(Property(&BinaryPrimitive::GetComment, StrEq("Overlay baz comment")))); } TEST_F(TableMergerTest, OverrideSameResourceIdsWithOverlay) { std::unique_ptr<ResourceTable> base = test::ResourceTableBuilder() Loading Loading
tools/aapt2/link/TableMerger.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -281,8 +281,17 @@ bool TableMerger::DoMerge(const Source& src, ResourceTable* src_table, dst_config_value->value = std::move(new_file_ref); } else { Maybe<std::string> original_comment = (dst_config_value->value) ? dst_config_value->value->GetComment() : Maybe<std::string>(); dst_config_value->value = std::unique_ptr<Value>( src_config_value->value->Clone(&master_table_->string_pool)); // Keep the comment from the original resource and ignore all comments from overlaying // resources if (overlay && original_comment) { dst_config_value->value->SetComment(original_comment.value()); } } } } Loading
tools/aapt2/link/TableMerger_test.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,49 @@ TEST_F(TableMergerTest, OverrideResourceWithOverlay) { Pointee(Field(&BinaryPrimitive::value, Field(&android::Res_value::data, Eq(0u))))); } TEST_F(TableMergerTest, DoNotOverrideResourceComment) { std::unique_ptr<Value> foo_original = ResourceUtils::TryParseBool("true"); foo_original->SetComment(android::StringPiece("Original foo comment")); std::unique_ptr<Value> bar_original = ResourceUtils::TryParseBool("true"); std::unique_ptr<Value> foo_overlay = ResourceUtils::TryParseBool("false"); foo_overlay->SetComment(android::StringPiece("Overlay foo comment")); std::unique_ptr<Value> bar_overlay = ResourceUtils::TryParseBool("false"); bar_overlay->SetComment(android::StringPiece("Overlay bar comment")); std::unique_ptr<Value> baz_overlay = ResourceUtils::TryParseBool("false"); baz_overlay->SetComment(android::StringPiece("Overlay baz comment")); std::unique_ptr<ResourceTable> base = test::ResourceTableBuilder() .SetPackageId("", 0x00) .AddValue("bool/foo", std::move(foo_original)) .AddValue("bool/bar", std::move(bar_original)) .Build(); std::unique_ptr<ResourceTable> overlay = test::ResourceTableBuilder() .SetPackageId("", 0x00) .AddValue("bool/foo", std::move(foo_overlay)) .AddValue("bool/bar", std::move(bar_overlay)) .AddValue("bool/baz", std::move(baz_overlay)) .Build(); ResourceTable final_table; TableMergerOptions options; options.auto_add_overlay = true; TableMerger merger(context_.get(), &final_table, options); ASSERT_TRUE(merger.Merge({}, base.get(), false /*overlay*/)); ASSERT_TRUE(merger.Merge({}, overlay.get(), true /*overlay*/)); BinaryPrimitive* foo = test::GetValue<BinaryPrimitive>(&final_table, "com.app.a:bool/foo"); EXPECT_THAT(foo, Pointee(Property(&BinaryPrimitive::GetComment, StrEq("Original foo comment")))); BinaryPrimitive* bar = test::GetValue<BinaryPrimitive>(&final_table, "com.app.a:bool/bar"); EXPECT_THAT(bar, Pointee(Property(&BinaryPrimitive::GetComment, StrEq("")))); BinaryPrimitive* baz = test::GetValue<BinaryPrimitive>(&final_table, "com.app.a:bool/baz"); EXPECT_THAT(baz, Pointee(Property(&BinaryPrimitive::GetComment, StrEq("Overlay baz comment")))); } TEST_F(TableMergerTest, OverrideSameResourceIdsWithOverlay) { std::unique_ptr<ResourceTable> base = test::ResourceTableBuilder() Loading