Loading tools/aapt2/cmd/Link.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -1084,7 +1084,8 @@ class Linker { case OutputFormat::kProto: { case OutputFormat::kProto: { pb::ResourceTable pb_table; pb::ResourceTable pb_table; SerializeTableToPb(*table, &pb_table, context_->GetDiagnostics()); SerializeTableToPb(*table, &pb_table, context_->GetDiagnostics(), options_.proto_table_flattener_options); return io::CopyProtoToArchive(context_, &pb_table, kProtoResourceTablePath, return io::CopyProtoToArchive(context_, &pb_table, kProtoResourceTablePath, ArchiveEntry::kCompress, writer); ArchiveEntry::kCompress, writer); } break; } break; Loading tools/aapt2/cmd/Link.h +16 −9 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "Resource.h" #include "Resource.h" #include "split/TableSplitter.h" #include "split/TableSplitter.h" #include "format/binary/TableFlattener.h" #include "format/binary/TableFlattener.h" #include "format/proto/ProtoSerialize.h" #include "link/ManifestFixer.h" #include "link/ManifestFixer.h" #include "trace/TraceBuffer.h" #include "trace/TraceBuffer.h" Loading Loading @@ -81,6 +82,7 @@ struct LinkOptions { // Flattening options. // Flattening options. TableFlattenerOptions table_flattener_options; TableFlattenerOptions table_flattener_options; SerializeTableOptions proto_table_flattener_options; bool keep_raw_values = false; bool keep_raw_values = false; // Split APK options. // Split APK options. Loading Loading @@ -283,13 +285,18 @@ class LinkCommand : public Command { AddOptionalSwitch("--strict-visibility", AddOptionalSwitch("--strict-visibility", "Do not allow overlays with different visibility levels.", "Do not allow overlays with different visibility levels.", &options_.strict_visibility); &options_.strict_visibility); AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); AddOptionalSwitch("--exclude-sources", AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", "Do not serialize source file information when generating resources in\n" "Protobuf format.", &options_.proto_table_flattener_options.exclude_sources); AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", &trace_folder_); &trace_folder_); AddOptionalSwitch("--merge-only", AddOptionalSwitch("--merge-only", "Only merge the resources, without verifying resource references. This flag\n" "Only merge the resources, without verifying resource references. This flag\n" "should only be used together with the --static-lib flag.", "should only be used together with the --static-lib flag.", &options_.merge_only); &options_.merge_only); AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); } } int Action(const std::vector<std::string>& args) override; int Action(const std::vector<std::string>& args) override; Loading tools/aapt2/format/proto/ProtoSerialize.cpp +27 −14 Original line number Original line Diff line number Diff line Loading @@ -290,9 +290,11 @@ static void SerializeOverlayableItemToPb(const OverlayableItem& overlayable_item pb::Overlayable* pb_overlayable = pb_table->add_overlayable(); pb::Overlayable* pb_overlayable = pb_table->add_overlayable(); pb_overlayable->set_name(overlayable_item.overlayable->name); pb_overlayable->set_name(overlayable_item.overlayable->name); pb_overlayable->set_actor(overlayable_item.overlayable->actor); pb_overlayable->set_actor(overlayable_item.overlayable->actor); if (source_pool != nullptr) { SerializeSourceToPb(overlayable_item.overlayable->source, source_pool, SerializeSourceToPb(overlayable_item.overlayable->source, source_pool, pb_overlayable->mutable_source()); pb_overlayable->mutable_source()); } } } pb::OverlayableItem* pb_overlayable_item = pb_entry->mutable_overlayable_item(); pb::OverlayableItem* pb_overlayable_item = pb_entry->mutable_overlayable_item(); pb_overlayable_item->set_overlayable_idx(i); pb_overlayable_item->set_overlayable_idx(i); Loading @@ -319,14 +321,17 @@ static void SerializeOverlayableItemToPb(const OverlayableItem& overlayable_item pb_overlayable_item->add_policy(pb::OverlayableItem::OEM); pb_overlayable_item->add_policy(pb::OverlayableItem::OEM); } } if (source_pool != nullptr) { SerializeSourceToPb(overlayable_item.source, source_pool, SerializeSourceToPb(overlayable_item.source, source_pool, pb_overlayable_item->mutable_source()); pb_overlayable_item->mutable_source()); } pb_overlayable_item->set_comment(overlayable_item.comment); pb_overlayable_item->set_comment(overlayable_item.comment); } } void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, IDiagnostics* diag) { IDiagnostics* diag, SerializeTableOptions options) { StringPool source_pool; auto source_pool = (options.exclude_sources) ? nullptr : util::make_unique<StringPool>(); pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint(); pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint(); pb_fingerprint->set_tool(util::GetToolName()); pb_fingerprint->set_tool(util::GetToolName()); pb_fingerprint->set_version(util::GetToolFingerprint()); pb_fingerprint->set_version(util::GetToolFingerprint()); Loading Loading @@ -356,32 +361,40 @@ void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table // Write the Visibility struct. // Write the Visibility struct. pb::Visibility* pb_visibility = pb_entry->mutable_visibility(); pb::Visibility* pb_visibility = pb_entry->mutable_visibility(); pb_visibility->set_level(SerializeVisibilityToPb(entry->visibility.level)); pb_visibility->set_level(SerializeVisibilityToPb(entry->visibility.level)); SerializeSourceToPb(entry->visibility.source, &source_pool, if (source_pool != nullptr) { SerializeSourceToPb(entry->visibility.source, source_pool.get(), pb_visibility->mutable_source()); pb_visibility->mutable_source()); } pb_visibility->set_comment(entry->visibility.comment); pb_visibility->set_comment(entry->visibility.comment); if (entry->allow_new) { if (entry->allow_new) { pb::AllowNew* pb_allow_new = pb_entry->mutable_allow_new(); pb::AllowNew* pb_allow_new = pb_entry->mutable_allow_new(); SerializeSourceToPb(entry->allow_new.value().source, &source_pool, if (source_pool != nullptr) { SerializeSourceToPb(entry->allow_new.value().source, source_pool.get(), pb_allow_new->mutable_source()); pb_allow_new->mutable_source()); } pb_allow_new->set_comment(entry->allow_new.value().comment); pb_allow_new->set_comment(entry->allow_new.value().comment); } } if (entry->overlayable_item) { if (entry->overlayable_item) { SerializeOverlayableItemToPb(entry->overlayable_item.value(), overlayables, &source_pool, SerializeOverlayableItemToPb(entry->overlayable_item.value(), overlayables, pb_entry, out_table); source_pool.get(), pb_entry, out_table); } } for (const std::unique_ptr<ResourceConfigValue>& config_value : entry->values) { for (const std::unique_ptr<ResourceConfigValue>& config_value : entry->values) { pb::ConfigValue* pb_config_value = pb_entry->add_config_value(); pb::ConfigValue* pb_config_value = pb_entry->add_config_value(); SerializeConfig(config_value->config, pb_config_value->mutable_config()); SerializeConfig(config_value->config, pb_config_value->mutable_config()); pb_config_value->mutable_config()->set_product(config_value->product); pb_config_value->mutable_config()->set_product(config_value->product); SerializeValueToPb(*config_value->value, pb_config_value->mutable_value(), &source_pool); SerializeValueToPb(*config_value->value, pb_config_value->mutable_value(), source_pool.get()); } } } } } } } if (source_pool != nullptr) { SerializeStringPoolToPb(*source_pool, out_table->mutable_source_pool(), diag); } } SerializeStringPoolToPb(source_pool, out_table->mutable_source_pool(), diag); } } static pb::Reference_Type SerializeReferenceTypeToPb(Reference::Type type) { static pb::Reference_Type SerializeReferenceTypeToPb(Reference::Type type) { Loading tools/aapt2/format/proto/ProtoSerialize.h +7 −1 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,11 @@ struct SerializeXmlOptions { bool remove_empty_text_nodes = false; bool remove_empty_text_nodes = false; }; }; struct SerializeTableOptions { /** Prevent serializing the source pool and source protos. */ bool exclude_sources = false; }; // Serializes a Value to its protobuf representation. An optional StringPool will hold the // Serializes a Value to its protobuf representation. An optional StringPool will hold the // source path string. // source path string. void SerializeValueToPb(const Value& value, pb::Value* out_value, StringPool* src_pool = nullptr); void SerializeValueToPb(const Value& value, pb::Value* out_value, StringPool* src_pool = nullptr); Loading @@ -59,7 +64,8 @@ void SerializeStringPoolToPb(const StringPool& pool, pb::StringPool* out_pb_pool void SerializeConfig(const android::ConfigDescription& config, pb::Configuration* out_pb_config); void SerializeConfig(const android::ConfigDescription& config, pb::Configuration* out_pb_config); // Serializes a ResourceTable into its protobuf representation. // Serializes a ResourceTable into its protobuf representation. void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, IDiagnostics* diag); void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, IDiagnostics* diag, SerializeTableOptions options = {}); // Serializes a ResourceFile into its protobuf representation. // Serializes a ResourceFile into its protobuf representation. void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledFile* out_file); void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledFile* out_file); Loading Loading
tools/aapt2/cmd/Link.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -1084,7 +1084,8 @@ class Linker { case OutputFormat::kProto: { case OutputFormat::kProto: { pb::ResourceTable pb_table; pb::ResourceTable pb_table; SerializeTableToPb(*table, &pb_table, context_->GetDiagnostics()); SerializeTableToPb(*table, &pb_table, context_->GetDiagnostics(), options_.proto_table_flattener_options); return io::CopyProtoToArchive(context_, &pb_table, kProtoResourceTablePath, return io::CopyProtoToArchive(context_, &pb_table, kProtoResourceTablePath, ArchiveEntry::kCompress, writer); ArchiveEntry::kCompress, writer); } break; } break; Loading
tools/aapt2/cmd/Link.h +16 −9 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "Resource.h" #include "Resource.h" #include "split/TableSplitter.h" #include "split/TableSplitter.h" #include "format/binary/TableFlattener.h" #include "format/binary/TableFlattener.h" #include "format/proto/ProtoSerialize.h" #include "link/ManifestFixer.h" #include "link/ManifestFixer.h" #include "trace/TraceBuffer.h" #include "trace/TraceBuffer.h" Loading Loading @@ -81,6 +82,7 @@ struct LinkOptions { // Flattening options. // Flattening options. TableFlattenerOptions table_flattener_options; TableFlattenerOptions table_flattener_options; SerializeTableOptions proto_table_flattener_options; bool keep_raw_values = false; bool keep_raw_values = false; // Split APK options. // Split APK options. Loading Loading @@ -283,13 +285,18 @@ class LinkCommand : public Command { AddOptionalSwitch("--strict-visibility", AddOptionalSwitch("--strict-visibility", "Do not allow overlays with different visibility levels.", "Do not allow overlays with different visibility levels.", &options_.strict_visibility); &options_.strict_visibility); AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); AddOptionalSwitch("--exclude-sources", AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", "Do not serialize source file information when generating resources in\n" "Protobuf format.", &options_.proto_table_flattener_options.exclude_sources); AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", &trace_folder_); &trace_folder_); AddOptionalSwitch("--merge-only", AddOptionalSwitch("--merge-only", "Only merge the resources, without verifying resource references. This flag\n" "Only merge the resources, without verifying resource references. This flag\n" "should only be used together with the --static-lib flag.", "should only be used together with the --static-lib flag.", &options_.merge_only); &options_.merge_only); AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); } } int Action(const std::vector<std::string>& args) override; int Action(const std::vector<std::string>& args) override; Loading
tools/aapt2/format/proto/ProtoSerialize.cpp +27 −14 Original line number Original line Diff line number Diff line Loading @@ -290,9 +290,11 @@ static void SerializeOverlayableItemToPb(const OverlayableItem& overlayable_item pb::Overlayable* pb_overlayable = pb_table->add_overlayable(); pb::Overlayable* pb_overlayable = pb_table->add_overlayable(); pb_overlayable->set_name(overlayable_item.overlayable->name); pb_overlayable->set_name(overlayable_item.overlayable->name); pb_overlayable->set_actor(overlayable_item.overlayable->actor); pb_overlayable->set_actor(overlayable_item.overlayable->actor); if (source_pool != nullptr) { SerializeSourceToPb(overlayable_item.overlayable->source, source_pool, SerializeSourceToPb(overlayable_item.overlayable->source, source_pool, pb_overlayable->mutable_source()); pb_overlayable->mutable_source()); } } } pb::OverlayableItem* pb_overlayable_item = pb_entry->mutable_overlayable_item(); pb::OverlayableItem* pb_overlayable_item = pb_entry->mutable_overlayable_item(); pb_overlayable_item->set_overlayable_idx(i); pb_overlayable_item->set_overlayable_idx(i); Loading @@ -319,14 +321,17 @@ static void SerializeOverlayableItemToPb(const OverlayableItem& overlayable_item pb_overlayable_item->add_policy(pb::OverlayableItem::OEM); pb_overlayable_item->add_policy(pb::OverlayableItem::OEM); } } if (source_pool != nullptr) { SerializeSourceToPb(overlayable_item.source, source_pool, SerializeSourceToPb(overlayable_item.source, source_pool, pb_overlayable_item->mutable_source()); pb_overlayable_item->mutable_source()); } pb_overlayable_item->set_comment(overlayable_item.comment); pb_overlayable_item->set_comment(overlayable_item.comment); } } void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, IDiagnostics* diag) { IDiagnostics* diag, SerializeTableOptions options) { StringPool source_pool; auto source_pool = (options.exclude_sources) ? nullptr : util::make_unique<StringPool>(); pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint(); pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint(); pb_fingerprint->set_tool(util::GetToolName()); pb_fingerprint->set_tool(util::GetToolName()); pb_fingerprint->set_version(util::GetToolFingerprint()); pb_fingerprint->set_version(util::GetToolFingerprint()); Loading Loading @@ -356,32 +361,40 @@ void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table // Write the Visibility struct. // Write the Visibility struct. pb::Visibility* pb_visibility = pb_entry->mutable_visibility(); pb::Visibility* pb_visibility = pb_entry->mutable_visibility(); pb_visibility->set_level(SerializeVisibilityToPb(entry->visibility.level)); pb_visibility->set_level(SerializeVisibilityToPb(entry->visibility.level)); SerializeSourceToPb(entry->visibility.source, &source_pool, if (source_pool != nullptr) { SerializeSourceToPb(entry->visibility.source, source_pool.get(), pb_visibility->mutable_source()); pb_visibility->mutable_source()); } pb_visibility->set_comment(entry->visibility.comment); pb_visibility->set_comment(entry->visibility.comment); if (entry->allow_new) { if (entry->allow_new) { pb::AllowNew* pb_allow_new = pb_entry->mutable_allow_new(); pb::AllowNew* pb_allow_new = pb_entry->mutable_allow_new(); SerializeSourceToPb(entry->allow_new.value().source, &source_pool, if (source_pool != nullptr) { SerializeSourceToPb(entry->allow_new.value().source, source_pool.get(), pb_allow_new->mutable_source()); pb_allow_new->mutable_source()); } pb_allow_new->set_comment(entry->allow_new.value().comment); pb_allow_new->set_comment(entry->allow_new.value().comment); } } if (entry->overlayable_item) { if (entry->overlayable_item) { SerializeOverlayableItemToPb(entry->overlayable_item.value(), overlayables, &source_pool, SerializeOverlayableItemToPb(entry->overlayable_item.value(), overlayables, pb_entry, out_table); source_pool.get(), pb_entry, out_table); } } for (const std::unique_ptr<ResourceConfigValue>& config_value : entry->values) { for (const std::unique_ptr<ResourceConfigValue>& config_value : entry->values) { pb::ConfigValue* pb_config_value = pb_entry->add_config_value(); pb::ConfigValue* pb_config_value = pb_entry->add_config_value(); SerializeConfig(config_value->config, pb_config_value->mutable_config()); SerializeConfig(config_value->config, pb_config_value->mutable_config()); pb_config_value->mutable_config()->set_product(config_value->product); pb_config_value->mutable_config()->set_product(config_value->product); SerializeValueToPb(*config_value->value, pb_config_value->mutable_value(), &source_pool); SerializeValueToPb(*config_value->value, pb_config_value->mutable_value(), source_pool.get()); } } } } } } } if (source_pool != nullptr) { SerializeStringPoolToPb(*source_pool, out_table->mutable_source_pool(), diag); } } SerializeStringPoolToPb(source_pool, out_table->mutable_source_pool(), diag); } } static pb::Reference_Type SerializeReferenceTypeToPb(Reference::Type type) { static pb::Reference_Type SerializeReferenceTypeToPb(Reference::Type type) { Loading
tools/aapt2/format/proto/ProtoSerialize.h +7 −1 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,11 @@ struct SerializeXmlOptions { bool remove_empty_text_nodes = false; bool remove_empty_text_nodes = false; }; }; struct SerializeTableOptions { /** Prevent serializing the source pool and source protos. */ bool exclude_sources = false; }; // Serializes a Value to its protobuf representation. An optional StringPool will hold the // Serializes a Value to its protobuf representation. An optional StringPool will hold the // source path string. // source path string. void SerializeValueToPb(const Value& value, pb::Value* out_value, StringPool* src_pool = nullptr); void SerializeValueToPb(const Value& value, pb::Value* out_value, StringPool* src_pool = nullptr); Loading @@ -59,7 +64,8 @@ void SerializeStringPoolToPb(const StringPool& pool, pb::StringPool* out_pb_pool void SerializeConfig(const android::ConfigDescription& config, pb::Configuration* out_pb_config); void SerializeConfig(const android::ConfigDescription& config, pb::Configuration* out_pb_config); // Serializes a ResourceTable into its protobuf representation. // Serializes a ResourceTable into its protobuf representation. void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, IDiagnostics* diag); void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table, IDiagnostics* diag, SerializeTableOptions options = {}); // Serializes a ResourceFile into its protobuf representation. // Serializes a ResourceFile into its protobuf representation. void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledFile* out_file); void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledFile* out_file); Loading