summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2012-05-07 16:16:46 -0700
committerRaphael Moll <raphael@google.com>2012-05-18 20:34:44 -0700
commit6c255a3a378143af59021d29b4980b28f1ab4544 (patch)
tree145d2632678e6227c664a046de8930ff2e3873be /tools
parent43a760ba84a5357bae792a33ad4a0e946f02679c (diff)
downloadframeworks_base-6c255a3a378143af59021d29b4980b28f1ab4544.zip
frameworks_base-6c255a3a378143af59021d29b4980b28f1ab4544.tar.gz
frameworks_base-6c255a3a378143af59021d29b4980b28f1ab4544.tar.bz2
Merge "AAPT: support a new --ignore-assets flag."
AAPT has a fixed built-in list of files and directories to ignore when parsing resource files. Over the years we always had developers requiring specific patterns. Added a command-line option for it: aapt di --ignore-assets "foo*:*.blah" If the env var ANDROID_AAPT_IGNORE is set, it is parsed to find which file/directory patterns to ignore. Otherwise a default is used that matches the current behavior. SDK Bug: 5343 24067 (cherry-pick from AOSP 90897ed87bce639bf6bb2ccf15fbabb59b131bab) Change-Id: Ia4caa2a8188c8c1df143f884e459b8182645995f
Diffstat (limited to 'tools')
-rw-r--r--tools/aapt/AaptAssets.cpp123
-rw-r--r--tools/aapt/AaptAssets.h4
-rw-r--r--tools/aapt/Main.cpp17
3 files changed, 99 insertions, 45 deletions
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index ec61403..73705ae 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -56,55 +56,92 @@ static bool validateFileName(const char* fileName)
return true;
}
+// The default to use if no other ignore pattern is defined.
+const char * const gDefaultIgnoreAssets =
+ "!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~";
+// The ignore pattern that can be passed via --ignore-assets in Main.cpp
+const char * gUserIgnoreAssets = NULL;
+
static bool isHidden(const char *root, const char *path)
{
- const char *ext = NULL;
- const char *type = NULL;
-
- // Skip all hidden files.
- if (path[0] == '.') {
- // Skip ., .. and .svn but don't chatter about it.
- if (strcmp(path, ".") == 0
- || strcmp(path, "..") == 0
- || strcmp(path, ".svn") == 0) {
- return true;
- }
- type = "hidden";
- } else if (path[0] == '_') {
- // skip directories starting with _ (don't chatter about it)
- String8 subdirName(root);
- subdirName.appendPath(path);
- if (getFileType(subdirName.string()) == kFileTypeDirectory) {
- return true;
- }
- } else if (strcmp(path, "CVS") == 0) {
- // Skip CVS but don't chatter about it.
- return true;
- } else if (strcasecmp(path, "thumbs.db") == 0
- || strcasecmp(path, "picasa.ini") == 0) {
- // Skip suspected image indexes files.
- type = "index";
- } else if (path[strlen(path)-1] == '~') {
- // Skip suspected emacs backup files.
- type = "backup";
- } else if ((ext = strrchr(path, '.')) != NULL && strcmp(ext, ".scc") == 0) {
- // Skip VisualSourceSafe files and don't chatter about it
+ // Patterns syntax:
+ // - Delimiter is :
+ // - Entry can start with the flag ! to avoid printing a warning
+ // about the file being ignored.
+ // - Entry can have the flag "<dir>" to match only directories
+ // or <file> to match only files. Default is to match both.
+ // - Entry can be a simplified glob "<prefix>*" or "*<suffix>"
+ // where prefix/suffix must have at least 1 character (so that
+ // we don't match a '*' catch-all pattern.)
+ // - The special filenames "." and ".." are always ignored.
+ // - Otherwise the full string is matched.
+ // - match is not case-sensitive.
+
+ if (strcmp(path, ".") == 0 || strcmp(path, "..") == 0) {
return true;
- } else {
- // Let everything else through.
- return false;
}
- /* If we get this far, "type" should be set and the file
- * should be skipped.
- */
- String8 subdirName(root);
- subdirName.appendPath(path);
- fprintf(stderr, " (skipping %s %s '%s')\n", type,
- getFileType(subdirName.string())==kFileTypeDirectory ? "dir":"file",
- subdirName.string());
+ const char *delim = ":";
+ const char *p = gUserIgnoreAssets;
+ if (!p || !p[0]) {
+ p = getenv("ANDROID_AAPT_IGNORE");
+ }
+ if (!p || !p[0]) {
+ p = gDefaultIgnoreAssets;
+ }
+ char *patterns = strdup(p);
- return true;
+ bool ignore = false;
+ bool chatty = true;
+ char *matchedPattern = NULL;
+
+ String8 fullPath(root);
+ fullPath.appendPath(path);
+ FileType type = getFileType(fullPath);
+
+ int plen = strlen(path);
+
+ // Note: we don't have strtok_r under mingw.
+ for(char *token = strtok(patterns, delim);
+ !ignore && token != NULL;
+ token = strtok(NULL, delim)) {
+ chatty = token[0] != '!';
+ if (!chatty) token++; // skip !
+ if (strncasecmp(token, "<dir>" , 5) == 0) {
+ if (type != kFileTypeDirectory) continue;
+ token += 5;
+ }
+ if (strncasecmp(token, "<file>", 6) == 0) {
+ if (type != kFileTypeRegular) continue;
+ token += 6;
+ }
+
+ matchedPattern = token;
+ int n = strlen(token);
+
+ if (token[0] == '*') {
+ // Match *suffix
+ token++;
+ if (n <= plen) {
+ ignore = strncasecmp(token, path + plen - n, n) == 0;
+ }
+ } else if (n > 1 && token[n - 1] == '*') {
+ // Match prefix*
+ ignore = strncasecmp(token, path, n - 1) == 0;
+ } else {
+ ignore = strcasecmp(token, path) == 0;
+ }
+ }
+
+ if (ignore && chatty) {
+ fprintf(stderr, " (skipping %s '%s' due to ANDROID_AAPT_IGNORE pattern '%s')\n",
+ type == kFileTypeDirectory ? "dir" : "file",
+ path,
+ matchedPattern ? matchedPattern : "");
+ }
+
+ free(patterns);
+ return ignore;
}
// =========================================================================
diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h
index 5924952..d5f296c 100644
--- a/tools/aapt/AaptAssets.h
+++ b/tools/aapt/AaptAssets.h
@@ -22,6 +22,10 @@
using namespace android;
+
+extern const char * const gDefaultIgnoreAssets;
+extern const char * gUserIgnoreAssets;
+
bool valid_symbol_name(const String8& str);
class AaptAssets;
diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp
index 50c828d..9f05c6a 100644
--- a/tools/aapt/Main.cpp
+++ b/tools/aapt/Main.cpp
@@ -178,7 +178,11 @@ void usage(void)
" --non-constant-id\n"
" Make the resources ID non constant. This is required to make an R java class\n"
" that does not contain the final value but is used to make reusable compiled\n"
- " libraries that need to access resources.\n");
+ " libraries that need to access resources.\n"
+ " --ignore-assets\n"
+ " Assets to be ignored. Default pattern is:\n"
+ " %s\n",
+ gDefaultIgnoreAssets);
}
/*
@@ -556,7 +560,16 @@ int main(int argc, char* const argv[])
bundle.setNonConstantId(true);
} else if (strcmp(cp, "-no-crunch") == 0) {
bundle.setUseCrunchCache(true);
- }else {
+ } else if (strcmp(cp, "-ignore-assets") == 0) {
+ argc--;
+ argv++;
+ if (!argc) {
+ fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n");
+ wantUsage = true;
+ goto bail;
+ }
+ gUserIgnoreAssets = argv[0];
+ } else {
fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
wantUsage = true;
goto bail;