Loading tools/aapt2/Debug.cpp +15 −33 Original line number Diff line number Diff line Loading @@ -256,53 +256,35 @@ class ValueBodyPrinter : public ConstValueVisitor { void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions& options, Printer* printer) { for (const auto& package : table.packages) { ValueHeadlinePrinter headline_printer(package->name, printer); ValueBodyPrinter body_printer(package->name, printer); const auto table_view = table.GetPartitionedView(); for (const auto& package : table_view.packages) { ValueHeadlinePrinter headline_printer(package.name, printer); ValueBodyPrinter body_printer(package.name, printer); printer->Print("Package name="); printer->Print(package->name); if (package->id) { printer->Print(StringPrintf(" id=%02x", package->id.value())); printer->Print(package.name); if (package.id) { printer->Print(StringPrintf(" id=%02x", package.id.value())); } printer->Println(); printer->Indent(); for (const auto& type : package->types) { for (const auto& type : package.types) { printer->Print("type "); printer->Print(to_string(type->type)); if (type->id) { printer->Print(StringPrintf(" id=%02x", type->id.value())); } printer->Println(StringPrintf(" entryCount=%zd", type->entries.size())); std::vector<const ResourceEntry*> sorted_entries; for (const auto& entry : type->entries) { auto iter = std::lower_bound( sorted_entries.begin(), sorted_entries.end(), entry.get(), [](const ResourceEntry* a, const ResourceEntry* b) -> bool { if (a->id && b->id) { return a->id.value() < b->id.value(); } else if (a->id) { return true; } else { return false; } }); sorted_entries.insert(iter, entry.get()); printer->Print(to_string(type.type)); if (type.id) { printer->Print(StringPrintf(" id=%02x", type.id.value())); } printer->Println(StringPrintf(" entryCount=%zd", type.entries.size())); printer->Indent(); for (const ResourceEntry* entry : sorted_entries) { const ResourceId id(package->id.value_or_default(0), type->id.value_or_default(0), entry->id.value_or_default(0)); for (const ResourceEntry* entry : type.entries) { printer->Print("resource "); printer->Print(id.to_string()); printer->Print(entry->id.value_or_default(0).to_string()); printer->Print(" "); // Write the name without the package (this is obvious and too verbose). printer->Print(to_string(type->type)); printer->Print(to_string(type.type)); printer->Print("/"); printer->Print(entry->name); Loading tools/aapt2/LoadedApk.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection( } std::string error; table = util::make_unique<ResourceTable>(/** validate_resources **/ false); table = util::make_unique<ResourceTable>(ResourceTable::Validation::kDisabled); if (!DeserializeTableFromPb(pb_table, collection.get(), table.get(), &error)) { diag->Error(DiagMessage(source) << "failed to deserialize " << kProtoResourceTablePath << ": " << error); Loading Loading @@ -157,7 +157,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadBinaryApkFromFileCollection( io::IFile* table_file = collection->FindFile(kApkResourceTablePath); if (table_file != nullptr) { table = util::make_unique<ResourceTable>(/** validate_resources **/ false); table = util::make_unique<ResourceTable>(ResourceTable::Validation::kDisabled); std::unique_ptr<io::IData> data = table_file->OpenAsData(); if (data == nullptr) { diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath); Loading tools/aapt2/Resource.h +1 −3 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ struct ResourceId { uint32_t id; ResourceId(); ResourceId(const ResourceId& rhs); ResourceId(const ResourceId& rhs) = default; ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor) ResourceId(uint8_t p, uint8_t t, uint16_t e); Loading Loading @@ -222,8 +222,6 @@ bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b); inline ResourceId::ResourceId() : id(0) {} inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) {} inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {} inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e) Loading tools/aapt2/ResourceParser.cpp +14 −14 Original line number Diff line number Diff line Loading @@ -118,43 +118,43 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, Parsed res->comment = trimmed_comment.to_string(); } NewResourceBuilder res_builder(res->name); if (res->visibility_level != Visibility::Level::kUndefined) { Visibility visibility; visibility.level = res->visibility_level; visibility.source = res->source; visibility.comment = res->comment; if (!table->SetVisibilityWithId(res->name, visibility, res->id, diag)) { return false; res_builder.SetVisibility(visibility); } if (res->id.is_valid()) { res_builder.SetId(res->id); } if (res->allow_new) { AllowNew allow_new; allow_new.source = res->source; allow_new.comment = res->comment; if (!table->SetAllowNew(res->name, allow_new, diag)) { return false; } res_builder.SetAllowNew(allow_new); } if (res->overlayable_item) { if (!table->SetOverlayable(res->name, res->overlayable_item.value(), diag)) { return false; } res_builder.SetOverlayable(res->overlayable_item.value()); } if (res->value != nullptr) { // Attach the comment, source and config to the value. res->value->SetComment(std::move(res->comment)); res->value->SetSource(std::move(res->source)); res_builder.SetValue(std::move(res->value), res->config, res->product); } if (!table->AddResourceWithId(res->name, res->id, res->config, res->product, std::move(res->value), diag)) { bool error = false; if (!res->name.entry.empty()) { if (!table->AddResource(res_builder.Build(), diag)) { return false; } } bool error = false; for (ParsedResource& child : res->child_resources) { error |= !AddResourcesToTable(table, diag, &child); } Loading Loading @@ -751,7 +751,7 @@ std::unique_ptr<Item> ResourceParser::ParseXml(xml::XmlPullParser* parser, // table. std::unique_ptr<Id> id = util::make_unique<Id>(); id->SetSource(source_.WithLine(begin_xml_line)); table_->AddResource(name, {}, {}, std::move(id), diag_); table_->AddResource(NewResourceBuilder(name).SetValue(std::move(id)).Build(), diag_); }; // Process the raw value. Loading tools/aapt2/ResourceParser_test.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -831,25 +831,13 @@ TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) { Maybe<ResourceTable::SearchResult> result = table_.FindResource(test::ParseNameOrDie("attr/foo")); ASSERT_TRUE(result); ASSERT_TRUE(result.value().package->id); ASSERT_TRUE(result.value().type->id); ASSERT_TRUE(result.value().entry->id); ResourceId actual_id(result.value().package->id.value(), result.value().type->id.value(), result.value().entry->id.value()); EXPECT_THAT(actual_id, Eq(ResourceId(0x01010040))); EXPECT_THAT(result.value().entry->id.value(), Eq(ResourceId(0x01010040))); result = table_.FindResource(test::ParseNameOrDie("attr/bar")); ASSERT_TRUE(result); ASSERT_TRUE(result.value().package->id); ASSERT_TRUE(result.value().type->id); ASSERT_TRUE(result.value().entry->id); actual_id = ResourceId(result.value().package->id.value(), result.value().type->id.value(), result.value().entry->id.value()); EXPECT_THAT(actual_id, Eq(ResourceId(0x01010041))); EXPECT_THAT(result.value().entry->id.value(), Eq(ResourceId(0x01010041))); } TEST_F(ResourceParserTest, StrongestSymbolVisibilityWins) { Loading Loading
tools/aapt2/Debug.cpp +15 −33 Original line number Diff line number Diff line Loading @@ -256,53 +256,35 @@ class ValueBodyPrinter : public ConstValueVisitor { void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions& options, Printer* printer) { for (const auto& package : table.packages) { ValueHeadlinePrinter headline_printer(package->name, printer); ValueBodyPrinter body_printer(package->name, printer); const auto table_view = table.GetPartitionedView(); for (const auto& package : table_view.packages) { ValueHeadlinePrinter headline_printer(package.name, printer); ValueBodyPrinter body_printer(package.name, printer); printer->Print("Package name="); printer->Print(package->name); if (package->id) { printer->Print(StringPrintf(" id=%02x", package->id.value())); printer->Print(package.name); if (package.id) { printer->Print(StringPrintf(" id=%02x", package.id.value())); } printer->Println(); printer->Indent(); for (const auto& type : package->types) { for (const auto& type : package.types) { printer->Print("type "); printer->Print(to_string(type->type)); if (type->id) { printer->Print(StringPrintf(" id=%02x", type->id.value())); } printer->Println(StringPrintf(" entryCount=%zd", type->entries.size())); std::vector<const ResourceEntry*> sorted_entries; for (const auto& entry : type->entries) { auto iter = std::lower_bound( sorted_entries.begin(), sorted_entries.end(), entry.get(), [](const ResourceEntry* a, const ResourceEntry* b) -> bool { if (a->id && b->id) { return a->id.value() < b->id.value(); } else if (a->id) { return true; } else { return false; } }); sorted_entries.insert(iter, entry.get()); printer->Print(to_string(type.type)); if (type.id) { printer->Print(StringPrintf(" id=%02x", type.id.value())); } printer->Println(StringPrintf(" entryCount=%zd", type.entries.size())); printer->Indent(); for (const ResourceEntry* entry : sorted_entries) { const ResourceId id(package->id.value_or_default(0), type->id.value_or_default(0), entry->id.value_or_default(0)); for (const ResourceEntry* entry : type.entries) { printer->Print("resource "); printer->Print(id.to_string()); printer->Print(entry->id.value_or_default(0).to_string()); printer->Print(" "); // Write the name without the package (this is obvious and too verbose). printer->Print(to_string(type->type)); printer->Print(to_string(type.type)); printer->Print("/"); printer->Print(entry->name); Loading
tools/aapt2/LoadedApk.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection( } std::string error; table = util::make_unique<ResourceTable>(/** validate_resources **/ false); table = util::make_unique<ResourceTable>(ResourceTable::Validation::kDisabled); if (!DeserializeTableFromPb(pb_table, collection.get(), table.get(), &error)) { diag->Error(DiagMessage(source) << "failed to deserialize " << kProtoResourceTablePath << ": " << error); Loading Loading @@ -157,7 +157,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadBinaryApkFromFileCollection( io::IFile* table_file = collection->FindFile(kApkResourceTablePath); if (table_file != nullptr) { table = util::make_unique<ResourceTable>(/** validate_resources **/ false); table = util::make_unique<ResourceTable>(ResourceTable::Validation::kDisabled); std::unique_ptr<io::IData> data = table_file->OpenAsData(); if (data == nullptr) { diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath); Loading
tools/aapt2/Resource.h +1 −3 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ struct ResourceId { uint32_t id; ResourceId(); ResourceId(const ResourceId& rhs); ResourceId(const ResourceId& rhs) = default; ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor) ResourceId(uint8_t p, uint8_t t, uint16_t e); Loading Loading @@ -222,8 +222,6 @@ bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b); inline ResourceId::ResourceId() : id(0) {} inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) {} inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {} inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e) Loading
tools/aapt2/ResourceParser.cpp +14 −14 Original line number Diff line number Diff line Loading @@ -118,43 +118,43 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, Parsed res->comment = trimmed_comment.to_string(); } NewResourceBuilder res_builder(res->name); if (res->visibility_level != Visibility::Level::kUndefined) { Visibility visibility; visibility.level = res->visibility_level; visibility.source = res->source; visibility.comment = res->comment; if (!table->SetVisibilityWithId(res->name, visibility, res->id, diag)) { return false; res_builder.SetVisibility(visibility); } if (res->id.is_valid()) { res_builder.SetId(res->id); } if (res->allow_new) { AllowNew allow_new; allow_new.source = res->source; allow_new.comment = res->comment; if (!table->SetAllowNew(res->name, allow_new, diag)) { return false; } res_builder.SetAllowNew(allow_new); } if (res->overlayable_item) { if (!table->SetOverlayable(res->name, res->overlayable_item.value(), diag)) { return false; } res_builder.SetOverlayable(res->overlayable_item.value()); } if (res->value != nullptr) { // Attach the comment, source and config to the value. res->value->SetComment(std::move(res->comment)); res->value->SetSource(std::move(res->source)); res_builder.SetValue(std::move(res->value), res->config, res->product); } if (!table->AddResourceWithId(res->name, res->id, res->config, res->product, std::move(res->value), diag)) { bool error = false; if (!res->name.entry.empty()) { if (!table->AddResource(res_builder.Build(), diag)) { return false; } } bool error = false; for (ParsedResource& child : res->child_resources) { error |= !AddResourcesToTable(table, diag, &child); } Loading Loading @@ -751,7 +751,7 @@ std::unique_ptr<Item> ResourceParser::ParseXml(xml::XmlPullParser* parser, // table. std::unique_ptr<Id> id = util::make_unique<Id>(); id->SetSource(source_.WithLine(begin_xml_line)); table_->AddResource(name, {}, {}, std::move(id), diag_); table_->AddResource(NewResourceBuilder(name).SetValue(std::move(id)).Build(), diag_); }; // Process the raw value. Loading
tools/aapt2/ResourceParser_test.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -831,25 +831,13 @@ TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) { Maybe<ResourceTable::SearchResult> result = table_.FindResource(test::ParseNameOrDie("attr/foo")); ASSERT_TRUE(result); ASSERT_TRUE(result.value().package->id); ASSERT_TRUE(result.value().type->id); ASSERT_TRUE(result.value().entry->id); ResourceId actual_id(result.value().package->id.value(), result.value().type->id.value(), result.value().entry->id.value()); EXPECT_THAT(actual_id, Eq(ResourceId(0x01010040))); EXPECT_THAT(result.value().entry->id.value(), Eq(ResourceId(0x01010040))); result = table_.FindResource(test::ParseNameOrDie("attr/bar")); ASSERT_TRUE(result); ASSERT_TRUE(result.value().package->id); ASSERT_TRUE(result.value().type->id); ASSERT_TRUE(result.value().entry->id); actual_id = ResourceId(result.value().package->id.value(), result.value().type->id.value(), result.value().entry->id.value()); EXPECT_THAT(actual_id, Eq(ResourceId(0x01010041))); EXPECT_THAT(result.value().entry->id.value(), Eq(ResourceId(0x01010041))); } TEST_F(ResourceParserTest, StrongestSymbolVisibilityWins) { Loading