Permalink
Browse files

aapt: allow toggling "errors instead of warnings"

* This patch makes the default behaviour same as AOSP,
  treating untranslatable strings in any but the default
  locale as warnings.
* Setting the environment variable AAPT_ERROR_ON_WARNING to
  anything will make those warnings, errors.

Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
Change-Id: I7da98d277495a7646ad64ba2f7e6a6bf14290f98
  • Loading branch information...
1 parent 923546d commit e1e339e4a47658920c7e575ee0b618b0ab116cb0 @chirayudesai chirayudesai committed with cyanogen May 6, 2013
Showing with 17 additions and 8 deletions.
  1. +17 −8 tools/aapt/ResourceTable.cpp
@@ -14,6 +14,7 @@
#include <androidfw/ResourceTypes.h>
#include <utils/ByteOrder.h>
#include <stdarg.h>
+#include <stdlib.h>
#define NOISY(x) //x
@@ -790,6 +791,7 @@ status_t compileResourceFile(Bundle* bundle,
const String16 myPackage(assets->getPackage());
bool hasErrors = false;
+ bool errorOnWarning = getenv("AAPT_ERROR_ON_WARNING") != NULL ? true : false;
bool fileIsTranslatable = true;
if (strstr(in->getPrintableSource().string(), "donottranslate") != NULL) {
@@ -1281,11 +1283,13 @@ status_t compileResourceFile(Bundle* bundle,
curIsFormatted = false;
// Untranslatable strings must only exist in the default [empty] locale
if (locale.size() > 0) {
- fprintf(stderr, "aapt: error: string '%s' in %s marked untranslatable but exists"
+ fprintf(stderr, "aapt: warning: string '%s' in %s marked untranslatable but exists"
" in locale '%s'\n", String8(name).string(),
bundle->getResourceSourceDirs()[0],
locale.string());
- hasErrors = localHasErrors = true;
+ if (errorOnWarning) {
+ hasErrors = localHasErrors = true;
+ }
} else {
// Intentionally empty block:
//
@@ -1389,11 +1393,13 @@ status_t compileResourceFile(Bundle* bundle,
curIsFormatted = false;
// Untranslatable strings must only exist in the default [empty] locale
if (locale.size() > 0) {
- fprintf(stderr, "aapt: error: string-array '%s' in %s marked untranslatable but exists"
+ fprintf(stderr, "aapt: warning: string-array '%s' in %s marked untranslatable but exists"
" in locale '%s'\n", String8(name).string(),
bundle->getResourceSourceDirs()[0],
locale.string());
- hasErrors = localHasErrors = true;
+ if (errorOnWarning) {
+ hasErrors = localHasErrors = true;
+ }
}
break;
}
@@ -2527,16 +2533,17 @@ ResourceTable::addLocalization(const String16& name, const String8& locale)
* Flag various sorts of localization problems. '+' indicates checks already implemented;
* '-' indicates checks that will be implemented in the future.
*
- * + A localized string for which no default-locale version exists => error
+ * + A localized string for which no default-locale version exists => warning or error
* + A string for which no version in an explicitly-requested locale exists => warning
- * + A localized translation of an translateable="false" string => error
+ * + A localized translation of an translateable="false" string => warning or error
* - A localized string not provided in every locale used by the table
*/
status_t
ResourceTable::validateLocalizations(void)
{
status_t err = NO_ERROR;
const String8 defaultLocale;
+ bool errorOnWarning = getenv("AAPT_ERROR_ON_WARNING") != NULL ? true : false;
// For all strings...
for (map<String16, set<String8> >::iterator nameIter = mLocalizations.begin();
@@ -2546,15 +2553,17 @@ ResourceTable::validateLocalizations(void)
// Look for strings with no default localization
if (configSet.count(defaultLocale) == 0) {
- fprintf(stderr, "aapt: error: string '%s' has no default translation in %s; found:",
+ fprintf(stderr, "aapt: warning: string '%s' has no default translation in %s; found:",
String8(nameIter->first).string(), mBundle->getResourceSourceDirs()[0]);
for (set<String8>::const_iterator locales = configSet.begin();
locales != configSet.end();
locales++) {
fprintf(stderr, " %s", (*locales).string());
}
fprintf(stderr, "\n");
- err = BAD_VALUE;
+ if (errorOnWarning) {
+ err = BAD_VALUE;
+ }
}
// Check that all requested localizations are present for this string

0 comments on commit e1e339e

Please sign in to comment.