Add support for DynamicRefTable when serializing/deserializing proto

Test: make aapt2_tests
Bug: 239390219
Bug: 237783271
Change-Id: I768f9167117c3a85c4dcabf2ece8a31e277c1e98
This commit is contained in:
Rico Wind
2022-11-11 09:37:54 +01:00
parent 18d0460514
commit e70bbb1ecf
4 changed files with 43 additions and 1 deletions

View File

@@ -46,6 +46,13 @@ message ToolFingerprint {
string version = 2;
}
// References to non local resources
message DynamicRefTable {
PackageId package_id = 1;
string package_name = 2;
}
// Top level message representing a resource table.
message ResourceTable {
// The string pool containing source paths referenced throughout the resource table. This does
@@ -60,6 +67,8 @@ message ResourceTable {
// The version fingerprints of the tools that built the resource table.
repeated ToolFingerprint tool_fingerprint = 4;
repeated DynamicRefTable dynamic_ref_table = 5;
}
// A package ID in the range [0x00, 0xff].

View File

@@ -562,6 +562,11 @@ bool DeserializeTableFromPb(const pb::ResourceTable& pb_table, io::IFileCollecti
}
}
for (const pb::DynamicRefTable& dynamic_ref : pb_table.dynamic_ref_table()) {
out_table->included_packages_.insert(
{dynamic_ref.package_id().id(), dynamic_ref.package_name()});
}
// Deserialize the overlayable groups of the table
std::vector<std::shared_ptr<Overlayable>> overlayables;
for (const pb::Overlayable& pb_overlayable : pb_table.overlayable()) {

View File

@@ -345,7 +345,11 @@ void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table
pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint();
pb_fingerprint->set_tool(util::GetToolName());
pb_fingerprint->set_version(util::GetToolFingerprint());
for (auto it = table.included_packages_.begin(); it != table.included_packages_.end(); ++it) {
pb::DynamicRefTable* pb_dynamic_ref = out_table->add_dynamic_ref_table();
pb_dynamic_ref->mutable_package_id()->set_id(it->first);
pb_dynamic_ref->set_package_name(it->second);
}
std::vector<Overlayable*> overlayables;
auto table_view = table.GetPartitionedView();
for (const auto& package : table_view.packages) {

View File

@@ -1024,4 +1024,28 @@ TEST(ProtoSerializeTest, CustomResourceTypes) {
EXPECT_THAT(*(custom_layout->path), Eq("res/layout/bar.xml"));
}
TEST(ProtoSerializeTest, SerializeDynamicRef) {
std::unique_ptr<IAaptContext> context =
test::ContextBuilder().SetCompilationPackage("app").SetPackageId(0x7f).Build();
std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder().Build();
table->included_packages_.insert({20, "foobar"});
table->included_packages_.insert({30, "barfoo"});
ResourceTable new_table;
pb::ResourceTable pb_table;
MockFileCollection files;
std::string error;
SerializeTableToPb(*table, &pb_table, context->GetDiagnostics());
ASSERT_TRUE(DeserializeTableFromPb(pb_table, &files, &new_table, &error));
EXPECT_THAT(error, IsEmpty());
int result = new_table.included_packages_.size();
EXPECT_THAT(result, Eq(2));
auto it = new_table.included_packages_.begin();
EXPECT_THAT(it->first, Eq(20));
EXPECT_THAT(it->second, Eq("foobar"));
it++;
EXPECT_THAT(it->first, Eq(30));
EXPECT_THAT(it->second, Eq("barfoo"));
}
} // namespace aapt