diff options
author | 2021-04-23 07:47:38 -0700 | |
---|---|---|
committer | 2021-05-10 17:22:33 -0700 | |
commit | 2fedba9a32d9e92344eaf6e9faf5b43e1bc2ae70 (patch) | |
tree | 8d1e8882141341965e05c435230a3b6f0f3b15da /tools/aapt2/ResourceParser.cpp | |
parent | 969f4ec61b7f6d069726ffcc795d438af7d47f7d (diff) |
Add <staging-public-group-final> to aapt2
To allow apps that compiled against a pre-release SDK to continue
working for a period of time after API finalization, a new tag,
<staging-public-group-final>, has been added to aapt2.
When finalizing the framework resource API, converting
<staging-public-group> tags to <staging-public-group-final> will
cause aapt2 to generate the resource table so that there is a resource
entry for the old non-finalized (staged) resource ID and another entry
for the finalized resource ID of newly finalized resources. This allows
an application that compiled against the pre-release SDK to continue
resolving resources using pre-release resource IDs.
All references to pre-release resource IDs will be rewritten to their
finalized resource IDs through the information stored in the new staged
alias chunk. This allows applications compiled against
<staging-public-group> resources to use the newly finalized
resource ID without re-compilation.
When an application is re-compiled against the SDK with
<staging-public-group-final> tags, the application will use the
finalized resource IDs.
This change limits the use of the alias chunk to the framework for S.
Bug: 183411356
Test: aapt2_test
Change-Id: Iba1c3033c3c2f32de8e4a19b58d3921c971092c4
Diffstat (limited to 'tools/aapt2/ResourceParser.cpp')
-rw-r--r-- | tools/aapt2/ResourceParser.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index 1efabbb46fd5..f1e2da9f41e2 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -45,6 +45,7 @@ namespace aapt { namespace { constexpr const char* kPublicGroupTag = "public-group"; constexpr const char* kStagingPublicGroupTag = "staging-public-group"; +constexpr const char* kStagingPublicGroupFinalTag = "staging-public-group-final"; } // namespace constexpr const char* sXliffNamespaceUri = "urn:oasis:names:tc:xliff:document:1.2"; @@ -109,6 +110,7 @@ struct ParsedResource { bool staged_api = false; bool allow_new = false; Maybe<OverlayableItem> overlayable_item; + Maybe<StagedId> staged_alias; std::string comment; std::unique_ptr<Value> value; @@ -155,6 +157,10 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, Parsed res_builder.SetValue(std::move(res->value), res->config, res->product); } + if (res->staged_alias) { + res_builder.SetStagedId(res->staged_alias.value()); + } + bool error = false; if (!res->name.entry.empty()) { if (!table->AddResource(res_builder.Build(), diag)) { @@ -532,6 +538,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser, {"public", std::mem_fn(&ResourceParser::ParsePublic)}, {"public-group", std::mem_fn(&ResourceParser::ParsePublicGroup)}, {"staging-public-group", std::mem_fn(&ResourceParser::ParseStagingPublicGroup)}, + {"staging-public-group-final", std::mem_fn(&ResourceParser::ParseStagingPublicGroupFinal)}, {"string-array", std::mem_fn(&ResourceParser::ParseStringArray)}, {"style", std::bind(&ResourceParser::ParseStyle, std::placeholders::_1, ResourceType::kStyle, std::placeholders::_2, std::placeholders::_3)}, @@ -671,7 +678,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser, if (bag_iter != elToBagMap.end()) { // Ensure we have a name (unless this is a <public-group> or <overlayable>). if (resource_type != kPublicGroupTag && resource_type != kStagingPublicGroupTag && - resource_type != "overlayable") { + resource_type != kStagingPublicGroupFinalTag && resource_type != "overlayable") { if (!maybe_name) { diag_->Error(DiagMessage(out_resource->source) << "<" << parser->element_name() << "> missing 'name' attribute"); @@ -1034,7 +1041,6 @@ bool static ParseGroupImpl(xml::XmlPullParser* parser, ParsedResource* out_resou ParsedResource& entry_res = out_resource->child_resources.emplace_back(ParsedResource{ .name = ResourceName{{}, *parsed_type, maybe_name.value().to_string()}, .source = item_source, - .id = next_id, .comment = std::move(comment), }); @@ -1060,6 +1066,14 @@ bool ResourceParser::ParseStagingPublicGroup(xml::XmlPullParser* parser, }); } +bool ResourceParser::ParseStagingPublicGroupFinal(xml::XmlPullParser* parser, + ParsedResource* out_resource) { + return ParseGroupImpl(parser, out_resource, kStagingPublicGroupFinalTag, diag_, + [](ParsedResource& parsed_entry, ResourceId id) { + parsed_entry.staged_alias = StagedId{id, parsed_entry.source}; + }); +} + bool ResourceParser::ParsePublicGroup(xml::XmlPullParser* parser, ParsedResource* out_resource) { if (options_.visibility) { diag_->Error(DiagMessage(out_resource->source) |