From 988be5d914334668ad25f8f993ec47442b3de33d Mon Sep 17 00:00:00 2001 From: Jeremy Meyer Date: Tue, 3 Sep 2024 16:31:54 -0700 Subject: 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 --- tools/aapt2/ResourceParser.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'tools/aapt2/ResourceParser.cpp') 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 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())) << " 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 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())) << " must have a 'type' attribute"); -- cgit v1.2.3-59-g8ed1b