am c93f1154: Merge "AAPT2: Remove the need for specifying package name in compile phase" into mnc-dev
* commit 'c93f115486dfb3e4ec8b7b634e0297024deac5c0': AAPT2: Remove the need for specifying package name in compile phase
This commit is contained in:
@@ -116,9 +116,11 @@ private:
|
|||||||
BinaryResourceParser::BinaryResourceParser(const std::shared_ptr<ResourceTable>& table,
|
BinaryResourceParser::BinaryResourceParser(const std::shared_ptr<ResourceTable>& table,
|
||||||
const std::shared_ptr<IResolver>& resolver,
|
const std::shared_ptr<IResolver>& resolver,
|
||||||
const Source& source,
|
const Source& source,
|
||||||
|
const std::u16string& defaultPackage,
|
||||||
const void* data,
|
const void* data,
|
||||||
size_t len) :
|
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() {
|
bool BinaryResourceParser::parse() {
|
||||||
@@ -177,6 +179,9 @@ bool BinaryResourceParser::getSymbol(const void* data, ResourceNameRef* outSymbo
|
|||||||
if (!type) {
|
if (!type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (outSymbol->package.empty()) {
|
||||||
|
outSymbol->package = mTable->getPackage();
|
||||||
|
}
|
||||||
outSymbol->type = *type;
|
outSymbol->type = *type;
|
||||||
|
|
||||||
// Since we scan the symbol table in order, we can start looking for the
|
// 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),
|
size_t len = strnlen16(reinterpret_cast<const char16_t*>(packageHeader->name),
|
||||||
sizeof(packageHeader->name) / sizeof(packageHeader->name[0]));
|
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),
|
ResChunkPullParser parser(getChunkData(packageHeader->header),
|
||||||
getChunkDataLen(packageHeader->header));
|
getChunkDataLen(packageHeader->header));
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
BinaryResourceParser(const std::shared_ptr<ResourceTable>& table,
|
BinaryResourceParser(const std::shared_ptr<ResourceTable>& table,
|
||||||
const std::shared_ptr<IResolver>& resolver,
|
const std::shared_ptr<IResolver>& resolver,
|
||||||
const Source& source,
|
const Source& source,
|
||||||
|
const std::u16string& defaultPackage,
|
||||||
const void* data, size_t len);
|
const void* data, size_t len);
|
||||||
|
|
||||||
BinaryResourceParser(const BinaryResourceParser&) = delete; // No copy.
|
BinaryResourceParser(const BinaryResourceParser&) = delete; // No copy.
|
||||||
@@ -97,12 +98,12 @@ private:
|
|||||||
|
|
||||||
const Source mSource;
|
const Source mSource;
|
||||||
|
|
||||||
|
// The package name of the resource table.
|
||||||
|
std::u16string mDefaultPackage;
|
||||||
|
|
||||||
const void* mData;
|
const void* mData;
|
||||||
const size_t mDataLen;
|
const size_t mDataLen;
|
||||||
|
|
||||||
// The package name of the resource table.
|
|
||||||
std::u16string mPackage;
|
|
||||||
|
|
||||||
// The array of symbol entries. Each element points to an offset
|
// The array of symbol entries. Each element points to an offset
|
||||||
// in the table and an index into the symbol table string pool.
|
// in the table and an index into the symbol table string pool.
|
||||||
const SymbolTable_entry* mSymbolEntries = nullptr;
|
const SymbolTable_entry* mSymbolEntries = nullptr;
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ const Attribute* Linker::doResolveAttribute(Reference& attribute, const SourceLi
|
|||||||
void Linker::visit(Reference& reference, ValueVisitorArgs& a) {
|
void Linker::visit(Reference& reference, ValueVisitorArgs& a) {
|
||||||
Args& args = static_cast<Args&>(a);
|
Args& args = static_cast<Args&>(a);
|
||||||
|
|
||||||
if (!reference.name.isValid()) {
|
if (reference.name.entry.empty()) {
|
||||||
// We can't have a completely bad reference.
|
// We can't have a completely bad reference.
|
||||||
if (!reference.id.isValid()) {
|
if (!reference.id.isValid()) {
|
||||||
Logger::error() << "srsly? " << args.referrer << std::endl;
|
Logger::error() << "srsly? " << args.referrer << std::endl;
|
||||||
|
|||||||
@@ -756,8 +756,8 @@ bool link(const AaptOptions& options, const std::shared_ptr<ResourceTable>& outT
|
|||||||
zipFile->uncompress(entry));
|
zipFile->uncompress(entry));
|
||||||
assert(uncompressedData);
|
assert(uncompressedData);
|
||||||
|
|
||||||
BinaryResourceParser parser(table, resolver, source, uncompressedData.get(),
|
BinaryResourceParser parser(table, resolver, source, options.appInfo.package,
|
||||||
entry->getUncompressedLen());
|
uncompressedData.get(), entry->getUncompressedLen());
|
||||||
if (!parser.parse()) {
|
if (!parser.parse()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1085,50 +1085,47 @@ static AaptOptions prepareArgs(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isStaticLib = false;
|
bool isStaticLib = false;
|
||||||
|
if (options.phase == AaptOptions::Phase::Link) {
|
||||||
|
flag::requiredFlag("--manifest", "AndroidManifest.xml of your app",
|
||||||
|
[&options](const StringPiece& arg) {
|
||||||
|
options.manifest = Source{ arg.toString() };
|
||||||
|
});
|
||||||
|
|
||||||
|
flag::optionalFlag("-I", "add an Android APK to link against",
|
||||||
|
[&options](const StringPiece& arg) {
|
||||||
|
options.libraries.push_back(Source{ arg.toString() });
|
||||||
|
});
|
||||||
|
|
||||||
|
flag::optionalFlag("--java", "directory in which to generate R.java",
|
||||||
|
[&options](const StringPiece& arg) {
|
||||||
|
options.generateJavaClass = Source{ arg.toString() };
|
||||||
|
});
|
||||||
|
|
||||||
|
flag::optionalFlag("--proguard", "file in which to output proguard rules",
|
||||||
|
[&options](const StringPiece& arg) {
|
||||||
|
options.generateProguardRules = Source{ arg.toString() };
|
||||||
|
});
|
||||||
|
|
||||||
|
flag::optionalSwitch("--static-lib", "generate a static Android library", true,
|
||||||
|
&isStaticLib);
|
||||||
|
|
||||||
|
flag::optionalFlag("--binding", "Output directory for binding XML files",
|
||||||
|
[&options](const StringPiece& arg) {
|
||||||
|
options.bindingOutput = Source{ arg.toString() };
|
||||||
|
});
|
||||||
|
flag::optionalSwitch("--no-version", "Disables automatic style and layout versioning",
|
||||||
|
false, &options.versionStylesAndLayouts);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.phase == AaptOptions::Phase::Compile ||
|
if (options.phase == AaptOptions::Phase::Compile ||
|
||||||
options.phase == AaptOptions::Phase::Link) {
|
options.phase == AaptOptions::Phase::Link) {
|
||||||
if (options.phase == AaptOptions::Phase::Compile) {
|
|
||||||
flag::requiredFlag("--package", "Android package name",
|
|
||||||
[&options](const StringPiece& arg) {
|
|
||||||
options.appInfo.package = util::utf8ToUtf16(arg);
|
|
||||||
});
|
|
||||||
} else if (options.phase == AaptOptions::Phase::Link) {
|
|
||||||
flag::requiredFlag("--manifest", "AndroidManifest.xml of your app",
|
|
||||||
[&options](const StringPiece& arg) {
|
|
||||||
options.manifest = Source{ arg.toString() };
|
|
||||||
});
|
|
||||||
|
|
||||||
flag::optionalFlag("-I", "add an Android APK to link against",
|
|
||||||
[&options](const StringPiece& arg) {
|
|
||||||
options.libraries.push_back(Source{ arg.toString() });
|
|
||||||
});
|
|
||||||
|
|
||||||
flag::optionalFlag("--java", "directory in which to generate R.java",
|
|
||||||
[&options](const StringPiece& arg) {
|
|
||||||
options.generateJavaClass = Source{ arg.toString() };
|
|
||||||
});
|
|
||||||
|
|
||||||
flag::optionalFlag("--proguard", "file in which to output proguard rules",
|
|
||||||
[&options](const StringPiece& arg) {
|
|
||||||
options.generateProguardRules = Source{ arg.toString() };
|
|
||||||
});
|
|
||||||
|
|
||||||
flag::optionalSwitch("--static-lib", "generate a static Android library", true,
|
|
||||||
&isStaticLib);
|
|
||||||
|
|
||||||
flag::optionalFlag("--binding", "Output directory for binding XML files",
|
|
||||||
[&options](const StringPiece& arg) {
|
|
||||||
options.bindingOutput = Source{ arg.toString() };
|
|
||||||
});
|
|
||||||
flag::optionalSwitch("--no-version", "Disables automatic style and layout versioning",
|
|
||||||
false, &options.versionStylesAndLayouts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common flags for all steps.
|
// Common flags for all steps.
|
||||||
flag::requiredFlag("-o", "Output path", [&options](const StringPiece& arg) {
|
flag::requiredFlag("-o", "Output path", [&options](const StringPiece& arg) {
|
||||||
options.output = Source{ arg.toString() };
|
options.output = Source{ arg.toString() };
|
||||||
});
|
});
|
||||||
} else if (options.phase == AaptOptions::Phase::DumpStyleGraph) {
|
}
|
||||||
|
|
||||||
|
if (options.phase == AaptOptions::Phase::DumpStyleGraph) {
|
||||||
flag::requiredFlag("--style", "Name of the style to dump",
|
flag::requiredFlag("--style", "Name of the style to dump",
|
||||||
[&options](const StringPiece& arg, std::string* outError) -> bool {
|
[&options](const StringPiece& arg, std::string* outError) -> bool {
|
||||||
Reference styleReference;
|
Reference styleReference;
|
||||||
@@ -1191,7 +1188,7 @@ static bool doDump(const AaptOptions& options) {
|
|||||||
zipFile->uncompress(entry));
|
zipFile->uncompress(entry));
|
||||||
assert(uncompressedData);
|
assert(uncompressedData);
|
||||||
|
|
||||||
BinaryResourceParser parser(table, resolver, source, uncompressedData.get(),
|
BinaryResourceParser parser(table, resolver, source, {}, uncompressedData.get(),
|
||||||
entry->getUncompressedLen());
|
entry->getUncompressedLen());
|
||||||
if (!parser.parse()) {
|
if (!parser.parse()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1223,16 +1220,17 @@ int main(int argc, char** argv) {
|
|||||||
if (!loadAppInfo(options.manifest, &options.appInfo)) {
|
if (!loadAppInfo(options.manifest, &options.appInfo)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Verify we have some common options set.
|
if (options.appInfo.package.empty()) {
|
||||||
if (options.appInfo.package.empty()) {
|
Logger::error() << "no package name specified." << std::endl;
|
||||||
Logger::error() << "no package name specified." << std::endl;
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every phase needs a resource table.
|
// Every phase needs a resource table.
|
||||||
std::shared_ptr<ResourceTable> table = std::make_shared<ResourceTable>();
|
std::shared_ptr<ResourceTable> table = std::make_shared<ResourceTable>();
|
||||||
|
|
||||||
|
// The package name is empty when in the compile phase.
|
||||||
table->setPackage(options.appInfo.package);
|
table->setPackage(options.appInfo.package);
|
||||||
if (options.appInfo.package == u"android") {
|
if (options.appInfo.package == u"android") {
|
||||||
table->setPackageId(0x01);
|
table->setPackageId(0x01);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
|
|
||||||
// Write the key.
|
// Write the key.
|
||||||
if (!Res_INTERNALID(key.id.id) && !key.id.isValid()) {
|
if (!Res_INTERNALID(key.id.id) && !key.id.isValid()) {
|
||||||
assert(key.name.isValid());
|
assert(!key.name.entry.empty());
|
||||||
mSymbols->push_back(std::make_pair(ResourceNameRef(key.name),
|
mSymbols->push_back(std::make_pair(ResourceNameRef(key.name),
|
||||||
mOut->size() - sizeof(*outMapEntry)));
|
mOut->size() - sizeof(*outMapEntry)));
|
||||||
}
|
}
|
||||||
@@ -284,13 +284,6 @@ bool TableFlattener::flattenValue(BigBuffer* out, const FlatEntry& flatEntry,
|
|||||||
bool TableFlattener::flatten(BigBuffer* out, const ResourceTable& table) {
|
bool TableFlattener::flatten(BigBuffer* out, const ResourceTable& table) {
|
||||||
const size_t beginning = out->size();
|
const size_t beginning = out->size();
|
||||||
|
|
||||||
if (table.getPackage().size() == 0) {
|
|
||||||
Logger::error()
|
|
||||||
<< "ResourceTable has no package name."
|
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (table.getPackageId() == ResourceTable::kUnsetPackageId) {
|
if (table.getPackageId() == ResourceTable::kUnsetPackageId) {
|
||||||
Logger::error()
|
Logger::error()
|
||||||
<< "ResourceTable has no package ID set."
|
<< "ResourceTable has no package ID set."
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ $(info PRIVATE_INTERMEDIATE_TABLES = $(PRIVATE_INTERMEDIATE_TABLES))
|
|||||||
# returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
|
# returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
|
||||||
define make-collect-rule
|
define make-collect-rule
|
||||||
$(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
|
$(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
|
||||||
$(AAPT) compile --package $(LOCAL_PACKAGE) -o $$@ $$^
|
$(AAPT) compile -o $$@ $$^
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml
|
# Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ $(info PRIVATE_INTERMEDIATE_TABLES = $(PRIVATE_INTERMEDIATE_TABLES))
|
|||||||
# returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
|
# returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
|
||||||
define make-collect-rule
|
define make-collect-rule
|
||||||
$(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
|
$(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
|
||||||
$(AAPT) compile --package $(LOCAL_PACKAGE) -o $$@ $$^
|
$(AAPT) compile -o $$@ $$^
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml
|
# Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml
|
||||||
|
|||||||
Reference in New Issue
Block a user