Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1e339e4 authored by Chirayu Desai's avatar Chirayu Desai Committed by Steve Kondik
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: default avatarChirayu Desai <cdesai@cyanogenmod.org>
Change-Id: I7da98d277495a7646ad64ba2f7e6a6bf14290f98
parent 923546df
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -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());
                            if (errorOnWarning) {
                                hasErrors = localHasErrors = true;
                            }
                        } else {
                            // Intentionally empty block:
                            //
@@ -1389,12 +1393,14 @@ 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());
                                if (errorOnWarning) {
                                    hasErrors = localHasErrors = true;
                                }
                            }
                            break;
                        }
                    }
@@ -2527,9 +2533,9 @@ 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
@@ -2537,6 +2543,7 @@ 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,7 +2553,7 @@ 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();
@@ -2554,8 +2561,10 @@ ResourceTable::validateLocalizations(void)
                fprintf(stderr, " %s", (*locales).string());
            }
            fprintf(stderr, "\n");
            if (errorOnWarning) {
                err = BAD_VALUE;
            }
        }

        // Check that all requested localizations are present for this string
        if (mBundle->getConfigurations() != NULL && mBundle->getRequireLocalization()) {