Loading tools/aapt2/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ sources := \ flatten/Archive.cpp \ flatten/TableFlattener.cpp \ flatten/XmlFlattener.cpp \ io/FileSystem.cpp \ io/ZipArchive.cpp \ link/AutoVersioner.cpp \ link/ManifestFixer.cpp \ link/PrivateAttributeMover.cpp \ Loading tools/aapt2/NameMangler.h +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public: }; } bool shouldMangle(const std::u16string& package) { bool shouldMangle(const std::u16string& package) const { if (package.empty() || mPolicy.targetPackageName == package) { return false; } Loading tools/aapt2/Resource.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -85,4 +85,12 @@ const ResourceType* parseResourceType(const StringPiece16& str) { return &iter->second; } bool operator<(const ResourceKey& a, const ResourceKey& b) { return std::tie(a.name, a.config) < std::tie(b.name, b.config); } bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b) { return std::tie(a.name, a.config) < std::tie(b.name, b.config); } } // namespace aapt tools/aapt2/Resource.h +30 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,36 @@ struct ResourceFile { std::vector<SourcedResourceName> exportedSymbols; }; /** * Useful struct used as a key to represent a unique resource in associative containers. */ struct ResourceKey { ResourceName name; ConfigDescription config; }; bool operator<(const ResourceKey& a, const ResourceKey& b); /** * Useful struct used as a key to represent a unique resource in associative containers. * Holds a reference to the name, so that name better live longer than this key! */ struct ResourceKeyRef { ResourceNameRef name; ConfigDescription config; ResourceKeyRef() = default; ResourceKeyRef(const ResourceNameRef& n, const ConfigDescription& c) : name(n), config(c) { } /** * Prevent taking a reference to a temporary. This is bad. */ ResourceKeyRef(ResourceName&& n, const ConfigDescription& c) = delete; }; bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b); // // ResourceId implementation. // Loading tools/aapt2/ResourceParser.cpp +23 −6 Original line number Diff line number Diff line Loading @@ -173,7 +173,7 @@ struct ParsedResource { ResourceName name; Source source; ResourceId id; SymbolState symbolState = SymbolState::kUndefined; Maybe<SymbolState> symbolState; std::u16string comment; std::unique_ptr<Value> value; std::list<ParsedResource> childResources; Loading @@ -182,9 +182,9 @@ struct ParsedResource { // Recursively adds resources to the ResourceTable. static bool addResourcesToTable(ResourceTable* table, const ConfigDescription& config, IDiagnostics* diag, ParsedResource* res) { if (res->symbolState != SymbolState::kUndefined) { if (res->symbolState) { Symbol symbol; symbol.state = res->symbolState; symbol.state = res->symbolState.value(); symbol.source = res->source; symbol.comment = res->comment; if (!table->setSymbolState(res->name, res->id, symbol, diag)) { Loading Loading @@ -325,6 +325,8 @@ bool ResourceParser::parseResources(xml::XmlPullParser* parser) { result = parseSymbol(parser, &parsedResource); } else if (elementName == u"public-group") { result = parsePublicGroup(parser, &parsedResource); } else if (elementName == u"add-resource") { result = parseAddResource(parser, &parsedResource); } else { // Try parsing the elementName (or type) as a resource. These shall only be // resources like 'layout' or 'xml' and they can only be references. Loading Loading @@ -643,7 +645,7 @@ bool ResourceParser::parsePublicGroup(xml::XmlPullParser* parser, ParsedResource return !error; } bool ResourceParser::parseSymbol(xml::XmlPullParser* parser, ParsedResource* outResource) { bool ResourceParser::parseSymbolImpl(xml::XmlPullParser* parser, ParsedResource* outResource) { const Source source = mSource.withLine(parser->getLineNumber()); Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type"); Loading @@ -661,9 +663,24 @@ bool ResourceParser::parseSymbol(xml::XmlPullParser* parser, ParsedResource* out } outResource->name.type = *parsedType; return true; } bool ResourceParser::parseSymbol(xml::XmlPullParser* parser, ParsedResource* outResource) { if (parseSymbolImpl(parser, outResource)) { outResource->symbolState = SymbolState::kPrivate; return true; } return false; } bool ResourceParser::parseAddResource(xml::XmlPullParser* parser, ParsedResource* outResource) { if (parseSymbolImpl(parser, outResource)) { outResource->symbolState = SymbolState::kUndefined; return true; } return false; } static uint32_t parseFormatType(const StringPiece16& piece) { if (piece == u"reference") return android::ResTable_map::TYPE_REFERENCE; Loading Loading @@ -870,7 +887,7 @@ Maybe<Attribute::Symbol> ResourceParser::parseEnumOrFlagItem(xml::XmlPullParser* } return Attribute::Symbol{ Reference(ResourceName({}, ResourceType::kId, maybeName.value().toString())), Reference(ResourceNameRef({}, ResourceType::kId, maybeName.value())), val.data }; } Loading Loading
tools/aapt2/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ sources := \ flatten/Archive.cpp \ flatten/TableFlattener.cpp \ flatten/XmlFlattener.cpp \ io/FileSystem.cpp \ io/ZipArchive.cpp \ link/AutoVersioner.cpp \ link/ManifestFixer.cpp \ link/PrivateAttributeMover.cpp \ Loading
tools/aapt2/NameMangler.h +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public: }; } bool shouldMangle(const std::u16string& package) { bool shouldMangle(const std::u16string& package) const { if (package.empty() || mPolicy.targetPackageName == package) { return false; } Loading
tools/aapt2/Resource.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -85,4 +85,12 @@ const ResourceType* parseResourceType(const StringPiece16& str) { return &iter->second; } bool operator<(const ResourceKey& a, const ResourceKey& b) { return std::tie(a.name, a.config) < std::tie(b.name, b.config); } bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b) { return std::tie(a.name, a.config) < std::tie(b.name, b.config); } } // namespace aapt
tools/aapt2/Resource.h +30 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,36 @@ struct ResourceFile { std::vector<SourcedResourceName> exportedSymbols; }; /** * Useful struct used as a key to represent a unique resource in associative containers. */ struct ResourceKey { ResourceName name; ConfigDescription config; }; bool operator<(const ResourceKey& a, const ResourceKey& b); /** * Useful struct used as a key to represent a unique resource in associative containers. * Holds a reference to the name, so that name better live longer than this key! */ struct ResourceKeyRef { ResourceNameRef name; ConfigDescription config; ResourceKeyRef() = default; ResourceKeyRef(const ResourceNameRef& n, const ConfigDescription& c) : name(n), config(c) { } /** * Prevent taking a reference to a temporary. This is bad. */ ResourceKeyRef(ResourceName&& n, const ConfigDescription& c) = delete; }; bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b); // // ResourceId implementation. // Loading
tools/aapt2/ResourceParser.cpp +23 −6 Original line number Diff line number Diff line Loading @@ -173,7 +173,7 @@ struct ParsedResource { ResourceName name; Source source; ResourceId id; SymbolState symbolState = SymbolState::kUndefined; Maybe<SymbolState> symbolState; std::u16string comment; std::unique_ptr<Value> value; std::list<ParsedResource> childResources; Loading @@ -182,9 +182,9 @@ struct ParsedResource { // Recursively adds resources to the ResourceTable. static bool addResourcesToTable(ResourceTable* table, const ConfigDescription& config, IDiagnostics* diag, ParsedResource* res) { if (res->symbolState != SymbolState::kUndefined) { if (res->symbolState) { Symbol symbol; symbol.state = res->symbolState; symbol.state = res->symbolState.value(); symbol.source = res->source; symbol.comment = res->comment; if (!table->setSymbolState(res->name, res->id, symbol, diag)) { Loading Loading @@ -325,6 +325,8 @@ bool ResourceParser::parseResources(xml::XmlPullParser* parser) { result = parseSymbol(parser, &parsedResource); } else if (elementName == u"public-group") { result = parsePublicGroup(parser, &parsedResource); } else if (elementName == u"add-resource") { result = parseAddResource(parser, &parsedResource); } else { // Try parsing the elementName (or type) as a resource. These shall only be // resources like 'layout' or 'xml' and they can only be references. Loading Loading @@ -643,7 +645,7 @@ bool ResourceParser::parsePublicGroup(xml::XmlPullParser* parser, ParsedResource return !error; } bool ResourceParser::parseSymbol(xml::XmlPullParser* parser, ParsedResource* outResource) { bool ResourceParser::parseSymbolImpl(xml::XmlPullParser* parser, ParsedResource* outResource) { const Source source = mSource.withLine(parser->getLineNumber()); Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type"); Loading @@ -661,9 +663,24 @@ bool ResourceParser::parseSymbol(xml::XmlPullParser* parser, ParsedResource* out } outResource->name.type = *parsedType; return true; } bool ResourceParser::parseSymbol(xml::XmlPullParser* parser, ParsedResource* outResource) { if (parseSymbolImpl(parser, outResource)) { outResource->symbolState = SymbolState::kPrivate; return true; } return false; } bool ResourceParser::parseAddResource(xml::XmlPullParser* parser, ParsedResource* outResource) { if (parseSymbolImpl(parser, outResource)) { outResource->symbolState = SymbolState::kUndefined; return true; } return false; } static uint32_t parseFormatType(const StringPiece16& piece) { if (piece == u"reference") return android::ResTable_map::TYPE_REFERENCE; Loading Loading @@ -870,7 +887,7 @@ Maybe<Attribute::Symbol> ResourceParser::parseEnumOrFlagItem(xml::XmlPullParser* } return Attribute::Symbol{ Reference(ResourceName({}, ResourceType::kId, maybeName.value().toString())), Reference(ResourceNameRef({}, ResourceType::kId, maybeName.value())), val.data }; } Loading