diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/aapt/SdkConstants.h | 1 | ||||
| -rw-r--r-- | tools/aapt2/OWNERS | 1 | ||||
| -rw-r--r-- | tools/aapt2/SdkConstants.cpp | 3 | ||||
| -rw-r--r-- | tools/aapt2/SdkConstants.h | 1 | ||||
| -rw-r--r-- | tools/aapt2/format/binary/BinaryResourceParser.cpp | 18 | ||||
| -rw-r--r-- | tools/aapt2/format/binary/BinaryResourceParser.h | 4 | ||||
| -rwxr-xr-x | tools/finalize_res/finalize_res.py | 35 |
7 files changed, 53 insertions, 10 deletions
diff --git a/tools/aapt/SdkConstants.h b/tools/aapt/SdkConstants.h index 955581cf8655..daf91b032638 100644 --- a/tools/aapt/SdkConstants.h +++ b/tools/aapt/SdkConstants.h @@ -47,6 +47,7 @@ enum { SDK_Q = 29, SDK_R = 30, SDK_S = 31, + SDK_S_V2 = 32, }; #endif // H_AAPT_SDK_CONSTANTS diff --git a/tools/aapt2/OWNERS b/tools/aapt2/OWNERS index a96d15ea8233..4f655e54a7c2 100644 --- a/tools/aapt2/OWNERS +++ b/tools/aapt2/OWNERS @@ -1,3 +1,4 @@ set noparent +toddke@google.com zyy@google.com patb@google.com
\ No newline at end of file diff --git a/tools/aapt2/SdkConstants.cpp b/tools/aapt2/SdkConstants.cpp index bfb7ce48c4aa..7ea4ab13961d 100644 --- a/tools/aapt2/SdkConstants.cpp +++ b/tools/aapt2/SdkConstants.cpp @@ -27,7 +27,7 @@ namespace aapt { static ApiVersion sDevelopmentSdkLevel = 10000; static const auto sDevelopmentSdkCodeNames = - std::unordered_set<StringPiece>({"Q", "R", "S", "Tiramisu"}); + std::unordered_set<StringPiece>({"Q", "R", "S", "Sv2", "Tiramisu"}); static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = { {0x021c, 1}, @@ -59,6 +59,7 @@ static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = { {0x0606, SDK_Q}, {0x0616, SDK_R}, {0x064b, SDK_S}, + {0x064c, SDK_S_V2}, }; static bool less_entry_id(const std::pair<uint16_t, ApiVersion>& p, uint16_t entryId) { diff --git a/tools/aapt2/SdkConstants.h b/tools/aapt2/SdkConstants.h index 6bb6ddb13bdb..0f27ac50b3bf 100644 --- a/tools/aapt2/SdkConstants.h +++ b/tools/aapt2/SdkConstants.h @@ -57,6 +57,7 @@ enum : ApiVersion { SDK_Q = 29, SDK_R = 30, SDK_S = 31, + SDK_S_V2 = 32, }; ApiVersion FindAttributeSdkLevel(const ResourceId& id); diff --git a/tools/aapt2/format/binary/BinaryResourceParser.cpp b/tools/aapt2/format/binary/BinaryResourceParser.cpp index 72eaa3561a02..a8845ef96bc3 100644 --- a/tools/aapt2/format/binary/BinaryResourceParser.cpp +++ b/tools/aapt2/format/binary/BinaryResourceParser.cpp @@ -120,6 +120,13 @@ bool BinaryResourceParser::Parse() { static_cast<int>(parser.chunk()->type))); } } + + if (!staged_entries_to_remove_.empty()) { + diag_->Error(DiagMessage(source_) << "didn't find " << staged_entries_to_remove_.size() + << " original staged resources"); + return false; + } + return true; } @@ -393,6 +400,12 @@ bool BinaryResourceParser::ParseType(const ResourceTablePackage* package, return false; } + if (const auto to_remove_it = staged_entries_to_remove_.find({name, res_id}); + to_remove_it != staged_entries_to_remove_.end()) { + staged_entries_to_remove_.erase(to_remove_it); + continue; + } + NewResourceBuilder res_builder(name); res_builder.SetValue(std::move(resource_value), config) .SetId(res_id, OnIdConflict::CREATE_ENTRY) @@ -533,9 +546,8 @@ bool BinaryResourceParser::ParseStagedAliases(const ResChunk_header* chunk) { // Since a the finalized resource entry is cloned and added to the resource table under the // staged resource id, remove the cloned resource entry from the table. if (!table_->RemoveResource(resource_name, staged_id)) { - diag_->Error(DiagMessage(source_) << "failed to find resource entry for staged " - << " resource ID " << staged_id); - return false; + // If we haven't seen this resource yet let's add a record to skip it when parsing. + staged_entries_to_remove_.insert({resource_name, staged_id}); } } return true; diff --git a/tools/aapt2/format/binary/BinaryResourceParser.h b/tools/aapt2/format/binary/BinaryResourceParser.h index cd71d160703a..1c83166c5cce 100644 --- a/tools/aapt2/format/binary/BinaryResourceParser.h +++ b/tools/aapt2/format/binary/BinaryResourceParser.h @@ -119,6 +119,10 @@ class BinaryResourceParser { // A mapping of resource ID to type spec flags. std::unordered_map<ResourceId, uint32_t> entry_type_spec_flags_; + + // A collection of staged resources that got finalized already and we're supposed to prune - + // but the original staged resource record hasn't been parsed yet. + std::set<std::pair<ResourceName, ResourceId>> staged_entries_to_remove_; }; } // namespace aapt diff --git a/tools/finalize_res/finalize_res.py b/tools/finalize_res/finalize_res.py index aaf01875024e..724443c01852 100755 --- a/tools/finalize_res/finalize_res.py +++ b/tools/finalize_res/finalize_res.py @@ -17,6 +17,7 @@ """ Finalize resource values in <staging-public-group> tags +and convert those to <staging-public-group-final> Usage: finalize_res.py core/res/res/values/public.xml public_finalized.xml """ @@ -24,18 +25,40 @@ Usage: finalize_res.py core/res/res/values/public.xml public_finalized.xml import re, sys, codecs def finalize_item(raw): - global _type, _id - _id += 1 - return '<public type="%s" name="%s" id="%s" />' % (_type, raw.group(1), '0x{0:0{1}x}'.format(_id-1,8)) + global _type_ids, _type + id = _type_ids[_type] + _type_ids[_type] += 1 + name = raw.group(1) + val = '<public type="%s" name="%s" id="%s" />' % (_type, name, '0x{0:0{1}x}'.format(id,8)) + if re.match(r'_*removed.+', name): + val = '<!-- ' + val.replace('<public', '< public') + ' -->' + return val def finalize_group(raw): - global _type, _id + global _type_ids, _type _type = raw.group(1) - _id = int(raw.group(2), 16) - return re.sub(r'<public name="(.+?)" */>', finalize_item, raw.group(3)) + id = int(raw.group(2), 16) + _type_ids[_type] = _type_ids.get(_type, id) + (res, count) = re.subn(r' {0,2}<public name="(.+?)" */>', finalize_item, raw.group(3)) + if count > 0: + res = raw.group(0).replace("staging-public-group", "staging-public-group-final") + '\n' + res + return res + +def collect_ids(raw): + global _type_ids + for m in re.finditer(r'<public type="(.+?)" name=".+?" id="(.+?)" />', raw): + type = m.group(1) + id = int(m.group(2), 16) + _type_ids[type] = max(id + 1, _type_ids.get(type, 0)) with open(sys.argv[1]) as f: + global _type_ids, _type + _type_ids = {} raw = f.read() + collect_ids(raw) raw = re.sub(r'<staging-public-group type="(.+?)" first-id="(.+?)">(.+?)</staging-public-group>', finalize_group, raw, flags=re.DOTALL) + raw = re.sub(r' *\n', '\n', raw) + raw = re.sub(r'\n{3,}', '\n\n', raw) with open(sys.argv[2], "w") as f: f.write(raw) + |