From 6cc479b76e9e2e8858434302e1ef2d514ed1b0ec Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 12 Jun 2015 15:45:48 -0700 Subject: 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 --- tools/aapt2/BinaryResourceParser.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'tools/aapt2/BinaryResourceParser.cpp') 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& table, const std::shared_ptr& 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(packageHeader->name), sizeof(packageHeader->name) / sizeof(packageHeader->name[0])); - mTable->setPackage(StringPiece16(reinterpret_cast(packageHeader->name), len)); + if (mTable->getPackage().empty() && len == 0) { + mTable->setPackage(mDefaultPackage); + } else if (len > 0) { + StringPiece16 thisPackage(reinterpret_cast(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)); -- cgit v1.2.3-59-g8ed1b