diff options
Diffstat (limited to 'tools/aapt/ResourceTable.cpp')
-rw-r--r-- | tools/aapt/ResourceTable.cpp | 310 |
1 files changed, 172 insertions, 138 deletions
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index 6d03311..e91a376 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -18,7 +18,24 @@ #include <utils/TypeHelpers.h> #include <stdarg.h> -#define NOISY(x) //x +// SSIZE: mingw does not have signed size_t == ssize_t. +// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary. +#if HAVE_PRINTF_ZD +# define SSIZE(x) x +# define STATUST(x) x +#else +# define SSIZE(x) (signed size_t)x +# define STATUST(x) (status_t)x +#endif + +// Set to true for noisy debug output. +static const bool kIsDebug = false; + +#if PRINT_STRING_METRICS +static const bool kPrintStringMetrics = true; +#else +static const bool kPrintStringMetrics = false; +#endif static const char* kAttrPrivateType = "^attr-private"; @@ -92,9 +109,11 @@ status_t compileXmlFile(const Bundle* bundle, if (table->modifyForCompat(bundle, resourceName, target, root) != NO_ERROR) { return UNKNOWN_ERROR; } - - NOISY(printf("Input XML Resource:\n")); - NOISY(root->print()); + + if (kIsDebug) { + printf("Input XML Resource:\n"); + root->print(); + } err = root->flatten(target, (options&XML_COMPILE_STRIP_COMMENTS) != 0, (options&XML_COMPILE_STRIP_RAW_VALUES) != 0); @@ -102,19 +121,18 @@ status_t compileXmlFile(const Bundle* bundle, return err; } - NOISY(printf("Output XML Resource:\n")); - NOISY(ResXMLTree tree; + if (kIsDebug) { + printf("Output XML Resource:\n"); + ResXMLTree tree; tree.setTo(target->getData(), target->getSize()); - printXMLBlock(&tree)); + printXMLBlock(&tree); + } target->setCompressionMethod(ZipEntry::kCompressDeflated); return err; } -#undef NOISY -#define NOISY(x) //x - struct flag_entry { const char16_t* name; @@ -583,7 +601,7 @@ status_t parseAndAddBag(Bundle* bundle, const String16& itemIdent, int32_t curFormat, bool isFormatted, - const String16& product, + const String16& /* product */, PseudolocalizationMethod pseudolocalize, const bool overwrite, ResourceTable* outTable) @@ -599,16 +617,18 @@ status_t parseAndAddBag(Bundle* bundle, if (err != NO_ERROR) { return err; } - - NOISY(printf("Adding resource bag entry l=%c%c c=%c%c orien=%d d=%d " - " pid=%s, bag=%s, id=%s: %s\n", - config.language[0], config.language[1], - config.country[0], config.country[1], - config.orientation, config.density, - String8(parentIdent).string(), - String8(ident).string(), - String8(itemIdent).string(), - String8(str).string())); + + if (kIsDebug) { + printf("Adding resource bag entry l=%c%c c=%c%c orien=%d d=%d " + " pid=%s, bag=%s, id=%s: %s\n", + config.language[0], config.language[1], + config.country[0], config.country[1], + config.orientation, config.density, + String8(parentIdent).string(), + String8(ident).string(), + String8(itemIdent).string(), + String8(str).string()); + } err = outTable->addBag(SourcePos(in->getPrintableSource(), block->getLineNumber()), myPackage, curType, ident, parentIdent, itemIdent, str, @@ -744,11 +764,13 @@ status_t parseAndAddEntry(Bundle* bundle, } } - NOISY(printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n", - config.language[0], config.language[1], - config.country[0], config.country[1], - config.orientation, config.density, - String8(ident).string(), String8(str).string())); + if (kIsDebug) { + printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n", + config.language[0], config.language[1], + config.country[0], config.country[1], + config.orientation, config.density, + String8(ident).string(), String8(str).string()); + } err = outTable->addEntry(SourcePos(in->getPrintableSource(), block->getLineNumber()), myPackage, curType, ident, str, &spans, &config, @@ -1717,7 +1739,7 @@ status_t compileResourceFile(Bundle* bundle, } } - return hasErrors ? UNKNOWN_ERROR : NO_ERROR; + return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR; } ResourceTable::ResourceTable(Bundle* bundle, const String16& assetsPackage, ResourceTable::PackageType type) @@ -1856,7 +1878,7 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos, const String16& bagParent, const ResTable_config* params, bool overlay, - bool replace, bool isId) + bool replace, bool /* isId */) { status_t result = NO_ERROR; @@ -2163,22 +2185,25 @@ uint32_t ResourceTable::getResId(const String16& ref, ref.string(), ref.size(), &package, &type, &name, defType, defPackage ? defPackage:&mAssetsPackage, outErrorMsg, &refOnlyPublic)) { - NOISY(printf("Expanding resource: ref=%s\n", - String8(ref).string())); - NOISY(printf("Expanding resource: defType=%s\n", - defType ? String8(*defType).string() : "NULL")); - NOISY(printf("Expanding resource: defPackage=%s\n", - defPackage ? String8(*defPackage).string() : "NULL")); - NOISY(printf("Expanding resource: ref=%s\n", String8(ref).string())); - NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=0\n", - String8(package).string(), String8(type).string(), - String8(name).string())); + if (kIsDebug) { + printf("Expanding resource: ref=%s\n", String8(ref).string()); + printf("Expanding resource: defType=%s\n", + defType ? String8(*defType).string() : "NULL"); + printf("Expanding resource: defPackage=%s\n", + defPackage ? String8(*defPackage).string() : "NULL"); + printf("Expanding resource: ref=%s\n", String8(ref).string()); + printf("Expanded resource: p=%s, t=%s, n=%s, res=0\n", + String8(package).string(), String8(type).string(), + String8(name).string()); + } return 0; } uint32_t res = getResId(package, type, name, onlyPublic && refOnlyPublic); - NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n", - String8(package).string(), String8(type).string(), - String8(name).string(), res)); + if (kIsDebug) { + printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n", + String8(package).string(), String8(type).string(), + String8(name).string(), res); + } if (res == 0) { if (outErrorMsg) *outErrorMsg = "No resource found that matches the given name"; @@ -2245,9 +2270,11 @@ bool ResourceTable::stringToValue(Res_value* outValue, StringPool* pool, } else { configStr = "(null)"; } - NOISY(printf("Adding to pool string style #%d config %s: %s\n", - style != NULL ? style->size() : 0, - configStr.string(), String8(finalStr).string())); + if (kIsDebug) { + printf("Adding to pool string style #%zu config %s: %s\n", + style != NULL ? style->size() : 0U, + configStr.string(), String8(finalStr).string()); + } if (style != NULL && style->size() > 0) { outValue->data = pool->add(finalStr, *style, configTypeName, config); } else { @@ -2914,9 +2941,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& const size_t typeStringsStart = data->getSize(); sp<AaptFile> strFile = p->getTypeStringsData(); ssize_t amt = data->writeData(strFile->getData(), strFile->getSize()); - #if PRINT_STRING_METRICS - fprintf(stderr, "**** type strings: %d\n", amt); - #endif + if (kPrintStringMetrics) { + fprintf(stderr, "**** type strings: %zd\n", SSIZE(amt)); + } strAmt += amt; if (amt < 0) { return amt; @@ -2924,9 +2951,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& const size_t keyStringsStart = data->getSize(); strFile = p->getKeyStringsData(); amt = data->writeData(strFile->getData(), strFile->getSize()); - #if PRINT_STRING_METRICS - fprintf(stderr, "**** key strings: %d\n", amt); - #endif + if (kPrintStringMetrics) { + fprintf(stderr, "**** key strings: %zd\n", SSIZE(amt)); + } strAmt += amt; if (amt < 0) { return amt; @@ -3022,36 +3049,41 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& // We need to write one type chunk for each configuration for // which we have entries in this type. - const SortedVector<ConfigDescription> uniqueConfigs(t->getUniqueConfigs()); - const size_t NC = uniqueConfigs.size(); + SortedVector<ConfigDescription> uniqueConfigs; + if (t != NULL) { + uniqueConfigs = t->getUniqueConfigs(); + } const size_t typeSize = sizeof(ResTable_type) + sizeof(uint32_t)*N; + const size_t NC = uniqueConfigs.size(); for (size_t ci=0; ci<NC; ci++) { const ConfigDescription& config = uniqueConfigs[ci]; - NOISY(printf("Writing config %d config: imsi:%d/%d lang:%c%c cnt:%c%c " - "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d " - "sw%ddp w%ddp h%ddp dir:%d\n", - ti+1, - config.mcc, config.mnc, - config.language[0] ? config.language[0] : '-', - config.language[1] ? config.language[1] : '-', - config.country[0] ? config.country[0] : '-', - config.country[1] ? config.country[1] : '-', - config.orientation, - config.uiMode, - config.touchscreen, - config.density, - config.keyboard, - config.inputFlags, - config.navigation, - config.screenWidth, - config.screenHeight, - config.smallestScreenWidthDp, - config.screenWidthDp, - config.screenHeightDp, - config.layoutDirection)); + if (kIsDebug) { + printf("Writing config %zu config: imsi:%d/%d lang:%c%c cnt:%c%c " + "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d " + "sw%ddp w%ddp h%ddp layout:%d\n", + ti + 1, + config.mcc, config.mnc, + config.language[0] ? config.language[0] : '-', + config.language[1] ? config.language[1] : '-', + config.country[0] ? config.country[0] : '-', + config.country[1] ? config.country[1] : '-', + config.orientation, + config.uiMode, + config.touchscreen, + config.density, + config.keyboard, + config.inputFlags, + config.navigation, + config.screenWidth, + config.screenHeight, + config.smallestScreenWidthDp, + config.screenWidthDp, + config.screenHeightDp, + config.screenLayout); + } if (filterable && !filter->match(config)) { continue; @@ -3073,28 +3105,30 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& tHeader->entryCount = htodl(N); tHeader->entriesStart = htodl(typeSize); tHeader->config = config; - NOISY(printf("Writing type %d config: imsi:%d/%d lang:%c%c cnt:%c%c " - "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d " - "sw%ddp w%ddp h%ddp dir:%d\n", - ti+1, - tHeader->config.mcc, tHeader->config.mnc, - tHeader->config.language[0] ? tHeader->config.language[0] : '-', - tHeader->config.language[1] ? tHeader->config.language[1] : '-', - tHeader->config.country[0] ? tHeader->config.country[0] : '-', - tHeader->config.country[1] ? tHeader->config.country[1] : '-', - tHeader->config.orientation, - tHeader->config.uiMode, - tHeader->config.touchscreen, - tHeader->config.density, - tHeader->config.keyboard, - tHeader->config.inputFlags, - tHeader->config.navigation, - tHeader->config.screenWidth, - tHeader->config.screenHeight, - tHeader->config.smallestScreenWidthDp, - tHeader->config.screenWidthDp, - tHeader->config.screenHeightDp, - tHeader->config.layoutDirection)); + if (kIsDebug) { + printf("Writing type %zu config: imsi:%d/%d lang:%c%c cnt:%c%c " + "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d " + "sw%ddp w%ddp h%ddp layout:%d\n", + ti + 1, + tHeader->config.mcc, tHeader->config.mnc, + tHeader->config.language[0] ? tHeader->config.language[0] : '-', + tHeader->config.language[1] ? tHeader->config.language[1] : '-', + tHeader->config.country[0] ? tHeader->config.country[0] : '-', + tHeader->config.country[1] ? tHeader->config.country[1] : '-', + tHeader->config.orientation, + tHeader->config.uiMode, + tHeader->config.touchscreen, + tHeader->config.density, + tHeader->config.keyboard, + tHeader->config.inputFlags, + tHeader->config.navigation, + tHeader->config.screenWidth, + tHeader->config.screenHeight, + tHeader->config.smallestScreenWidthDp, + tHeader->config.screenWidthDp, + tHeader->config.screenHeightDp, + tHeader->config.screenLayout); + } tHeader->config.swapHtoD(); // Build the entries inside of this type. @@ -3189,10 +3223,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& ssize_t amt = (dest->getSize()-strStart); strAmt += amt; - #if PRINT_STRING_METRICS - fprintf(stderr, "**** value strings: %d\n", amt); - fprintf(stderr, "**** total strings: %d\n", strAmt); - #endif + if (kPrintStringMetrics) { + fprintf(stderr, "**** value strings: %zd\n", SSIZE(amt)); + fprintf(stderr, "**** total strings: %zd\n", SSIZE(strAmt)); + } for (pi=0; pi<flatPackages.size(); pi++) { err = dest->writeData(flatPackages[pi]->getData(), @@ -3207,13 +3241,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& (((uint8_t*)dest->getData()) + dataStart); header->header.size = htodl(dest->getSize() - dataStart); - NOISY(aout << "Resource table:" - << HexDump(dest->getData(), dest->getSize()) << endl); - - #if PRINT_STRING_METRICS - fprintf(stderr, "**** total resource table size: %d / %d%% strings\n", - dest->getSize(), (strAmt*100)/dest->getSize()); - #endif + if (kPrintStringMetrics) { + fprintf(stderr, "**** total resource table size: %zu / %zu%% strings\n", + dest->getSize(), (size_t)(strAmt*100)/dest->getSize()); + } return NO_ERROR; } @@ -3221,7 +3252,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& status_t ResourceTable::flattenLibraryTable(const sp<AaptFile>& dest, const Vector<sp<Package> >& libs) { // Write out the library table if necessary if (libs.size() > 0) { - NOISY(fprintf(stderr, "Writing library reference table\n")); + if (kIsDebug) { + fprintf(stderr, "Writing library reference table\n"); + } const size_t libStart = dest->getSize(); const size_t count = libs.size(); @@ -3238,9 +3271,11 @@ status_t ResourceTable::flattenLibraryTable(const sp<AaptFile>& dest, const Vect for (size_t i = 0; i < count; i++) { const size_t entryStart = dest->getSize(); sp<Package> libPackage = libs[i]; - NOISY(fprintf(stderr, " Entry %s -> 0x%02x\n", + if (kIsDebug) { + fprintf(stderr, " Entry %s -> 0x%02x\n", String8(libPackage->getName()).string(), - (uint8_t)libPackage->getAssignedId())); + (uint8_t)libPackage->getAssignedId()); + } ResTable_lib_entry* entry = (ResTable_lib_entry*) dest->editDataInRange( entryStart, sizeof(ResTable_lib_entry)); @@ -3488,9 +3523,11 @@ status_t ResourceTable::Entry::generateAttributes(ResourceTable* table, if (it.isId) { if (!table->hasBagOrEntry(key, &id16, &package)) { String16 value("false"); - NOISY(fprintf(stderr, "Generating %s:id/%s\n", - String8(package).string(), - String8(key).string())); + if (kIsDebug) { + fprintf(stderr, "Generating %s:id/%s\n", + String8(package).string(), + String8(key).string()); + } status_t err = table->addEntry(SourcePos(String8("<generated>"), 0), package, id16, key, value); if (err != NO_ERROR) { @@ -3523,7 +3560,7 @@ status_t ResourceTable::Entry::generateAttributes(ResourceTable* table, } status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table, - const String16& package) + const String16& /* package */) { bool hasErrors = false; @@ -3556,7 +3593,7 @@ status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table, } } } - return hasErrors ? UNKNOWN_ERROR : NO_ERROR; + return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR; } status_t ResourceTable::Entry::prepareFlatten(StringPool* strings, ResourceTable* table, @@ -3615,22 +3652,20 @@ status_t ResourceTable::Entry::remapStringValue(StringPool* strings) return NO_ERROR; } -ssize_t ResourceTable::Entry::flatten(Bundle* bundle, const sp<AaptFile>& data, bool isPublic) +ssize_t ResourceTable::Entry::flatten(Bundle* /* bundle */, const sp<AaptFile>& data, bool isPublic) { size_t amt = 0; ResTable_entry header; memset(&header, 0, sizeof(header)); header.size = htods(sizeof(header)); - const type ty = this != NULL ? mType : TYPE_ITEM; - if (this != NULL) { - if (ty == TYPE_BAG) { - header.flags |= htods(header.FLAG_COMPLEX); - } - if (isPublic) { - header.flags |= htods(header.FLAG_PUBLIC); - } - header.key.index = htodl(mNameIndex); + const type ty = mType; + if (ty == TYPE_BAG) { + header.flags |= htods(header.FLAG_COMPLEX); + } + if (isPublic) { + header.flags |= htods(header.FLAG_PUBLIC); } + header.key.index = htodl(mNameIndex); if (ty != TYPE_BAG) { status_t err = data->writeData(&header, sizeof(header)); if (err != NO_ERROR) { @@ -3805,10 +3840,11 @@ sp<ResourceTable::Entry> ResourceTable::Type::getEntry(const String16& entry, sp<Entry> e = c->getEntries().valueFor(cdesc); if (e == NULL) { - if (config != NULL) { - NOISY(printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c " + if (kIsDebug) { + if (config != NULL) { + printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c " "orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d " - "sw%ddp w%ddp h%ddp dir:%d\n", + "sw%ddp w%ddp h%ddp layout:%d\n", sourcePos.file.string(), sourcePos.line, config->mcc, config->mnc, config->language[0] ? config->language[0] : '-', @@ -3826,10 +3862,11 @@ sp<ResourceTable::Entry> ResourceTable::Type::getEntry(const String16& entry, config->smallestScreenWidthDp, config->screenWidthDp, config->screenHeightDp, - config->layoutDirection)); - } else { - NOISY(printf("New entry at %s:%d: NULL config\n", - sourcePos.file.string(), sourcePos.line)); + config->screenLayout); + } else { + printf("New entry at %s:%d: NULL config\n", + sourcePos.file.string(), sourcePos.line); + } } e = new Entry(entry, sourcePos); c->addEntry(cdesc, e); @@ -3968,7 +4005,7 @@ status_t ResourceTable::Type::applyPublicEntryOrder() j++; } - return hasError ? UNKNOWN_ERROR : NO_ERROR; + return hasError ? STATUST(UNKNOWN_ERROR) : NO_ERROR; } ResourceTable::Package::Package(const String16& name, size_t packageId) @@ -4032,9 +4069,6 @@ status_t ResourceTable::Package::setStrings(const sp<AaptFile>& data, return UNKNOWN_ERROR; } - NOISY(aout << "Setting restable string pool: " - << HexDump(data->getData(), data->getSize()) << endl); - status_t err = strings->setTo(data->getData(), data->getSize()); if (err == NO_ERROR) { const size_t N = strings->size(); @@ -4313,7 +4347,7 @@ bool ResourceTable::getItemValue( } item->evaluating = true; res = stringToValue(outValue, NULL, item->value, false, false, item->bagKeyId); - NOISY( + if (kIsDebug) { if (res) { printf("getItemValue of #%08x[#%08x] (%s): type=#%08x, data=#%08x\n", resID, attrID, String8(getEntry(resID)->getName()).string(), @@ -4322,7 +4356,7 @@ bool ResourceTable::getItemValue( printf("getItemValue of #%08x[#%08x]: failed\n", resID, attrID); } - ); + } item->evaluating = false; } return res; |