diff options
author | 2015-06-12 15:45:48 -0700 | |
---|---|---|
committer | 2015-06-12 17:12:04 -0700 | |
commit | 6cc479b76e9e2e8858434302e1ef2d514ed1b0ec (patch) | |
tree | 3bc2ca1ed297786809dac34b9e0c067586636d8b /tools/aapt2/BinaryResourceParser.cpp | |
parent | 6cb8e30bb7e79cb694bf44d185da201e9deb9363 (diff) |
AAPT2: Remove the need for specifying package name in compile phase
The compile phase doesn't use the AndroidManifest, so we had to specify the
package name on the command line.
We can omit the package name, since we don't resolve external references
in the compile phase. Packages that reference the current package will be encoded
with no package name. When loaded by the link phase, the package name will be supplied
and all the references with no package name will use that one.
Change-Id: I9fe4902b747b06899b45c968f30ba1aa05c5cd69
Diffstat (limited to 'tools/aapt2/BinaryResourceParser.cpp')
-rw-r--r-- | tools/aapt2/BinaryResourceParser.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tools/aapt2/BinaryResourceParser.cpp b/tools/aapt2/BinaryResourceParser.cpp index 3559f435329b..4f1947ab8364 100644 --- a/tools/aapt2/BinaryResourceParser.cpp +++ b/tools/aapt2/BinaryResourceParser.cpp @@ -116,9 +116,11 @@ private: BinaryResourceParser::BinaryResourceParser(const std::shared_ptr<ResourceTable>& table, const std::shared_ptr<IResolver>& resolver, const Source& source, + const std::u16string& defaultPackage, const void* data, size_t len) : - mTable(table), mResolver(resolver), mSource(source), mData(data), mDataLen(len) { + mTable(table), mResolver(resolver), mSource(source), mDefaultPackage(defaultPackage), + mData(data), mDataLen(len) { } bool BinaryResourceParser::parse() { @@ -177,6 +179,9 @@ bool BinaryResourceParser::getSymbol(const void* data, ResourceNameRef* outSymbo if (!type) { return false; } + if (outSymbol->package.empty()) { + outSymbol->package = mTable->getPackage(); + } outSymbol->type = *type; // Since we scan the symbol table in order, we can start looking for the @@ -350,7 +355,22 @@ bool BinaryResourceParser::parsePackage(const ResChunk_header* chunk) { size_t len = strnlen16(reinterpret_cast<const char16_t*>(packageHeader->name), sizeof(packageHeader->name) / sizeof(packageHeader->name[0])); - mTable->setPackage(StringPiece16(reinterpret_cast<const char16_t*>(packageHeader->name), len)); + if (mTable->getPackage().empty() && len == 0) { + mTable->setPackage(mDefaultPackage); + } else if (len > 0) { + StringPiece16 thisPackage(reinterpret_cast<const char16_t*>(packageHeader->name), len); + if (mTable->getPackage().empty()) { + mTable->setPackage(thisPackage); + } else if (thisPackage != mTable->getPackage()) { + Logger::error(mSource) + << "incompatible packages: " + << mTable->getPackage() + << " vs. " + << thisPackage + << std::endl; + return false; + } + } ResChunkPullParser parser(getChunkData(packageHeader->header), getChunkDataLen(packageHeader->header)); |