diff options
author | 2024-09-03 16:31:54 -0700 | |
---|---|---|
committer | 2024-09-25 15:07:42 -0700 | |
commit | 988be5d914334668ad25f8f993ec47442b3de33d (patch) | |
tree | 20e5f269b4f0eabc7938feaccc7a1fe85980ec5b /tools/aapt2/ResourceParser.cpp | |
parent | 3d8d4a18c2bd4d697692ea30471852c90e7a3775 (diff) |
Add support for flag in resource directory names
This only applies it to the xml files with the top level element of
resources. Other file support will be in a later CL.
Test: Automated
Bug: 329436914
Flag: EXEMPT Aconfig not supported on host tools
Change-Id: I5e1e341e9de61073d05d9098b1b8b836025910b3
Diffstat (limited to 'tools/aapt2/ResourceParser.cpp')
-rw-r--r-- | tools/aapt2/ResourceParser.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index 773edc3e3c22..a2383ac0285f 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -546,15 +546,25 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser, {"symbol", std::mem_fn(&ResourceParser::ParseSymbol)}, }); - std::string resource_type = parser->element_name(); - out_resource->flag = GetFlag(parser); - std::string error; - auto flag_status = GetFlagStatus(out_resource->flag, options_.feature_flag_values, &error); - if (flag_status) { - out_resource->flag_status = flag_status.value(); - } else { - diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) << error); - return false; + std::string_view resource_type = parser->element_name(); + if (auto flag = GetFlag(parser)) { + if (options_.flag) { + diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) + << "Resource flag are not allowed both in the path and in the file"); + return false; + } + out_resource->flag = std::move(flag); + std::string error; + auto flag_status = GetFlagStatus(out_resource->flag, options_.feature_flag_values, &error); + if (flag_status) { + out_resource->flag_status = flag_status.value(); + } else { + diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) << error); + return false; + } + } else if (options_.flag) { + out_resource->flag = options_.flag; + out_resource->flag_status = options_.flag_status; } // The value format accepted for this resource. @@ -571,7 +581,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser, // Items have their type encoded in the type attribute. if (std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) { - resource_type = std::string(maybe_type.value()); + resource_type = maybe_type.value(); } else { diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) << "<item> must have a 'type' attribute"); @@ -594,7 +604,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser, // Bags have their type encoded in the type attribute. if (std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) { - resource_type = std::string(maybe_type.value()); + resource_type = maybe_type.value(); } else { diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) << "<bag> must have a 'type' attribute"); |