X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/c70f9935358d885d063ed0112827c5d8506d1f9d..4bc0f49c625c59047a4ae1bfbb9a14f0c017a341:/Package.cpp diff --git a/Package.cpp b/Package.cpp index 3cb614f..3930117 100644 --- a/Package.cpp +++ b/Package.cpp @@ -6,6 +6,7 @@ #include "Main.h" #include "AaptAssets.h" #include "ResourceTable.h" +#include "ResourceFilter.h" #include #include @@ -33,8 +34,8 @@ static const char* kNoCompressExt[] = { /* fwd decls, so I can write this downward */ ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& assets); -ssize_t processAssets(Bundle* bundle, ZipFile* zip, - const sp& dir, const AaptGroupEntry& ge); +ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& dir, + const AaptGroupEntry& ge, const ResourceFilter* filter); bool processFile(Bundle* bundle, ZipFile* zip, const sp& group, const sp& file); bool okayToCompress(Bundle* bundle, const String8& pathName); @@ -50,6 +51,11 @@ ssize_t processJarFiles(Bundle* bundle, ZipFile* zip); status_t writeAPK(Bundle* bundle, const sp& assets, const String8& outputFile) { + #if BENCHMARK + fprintf(stdout, "BENCHMARK: Starting APK Bundling \n"); + long startAPKTime = clock(); + #endif /* BENCHMARK */ + status_t result = NO_ERROR; ZipFile* zip = NULL; int count; @@ -172,6 +178,21 @@ status_t writeAPK(Bundle* bundle, const sp& assets, } } + // If we've been asked to generate a dependency file for the .ap_ package, + // do so here + if (bundle->getGenDependencies()) { + // The dependency file gets output to the same directory + // as the specified output file with an additional .d extension. + // e.g. bin/resources.ap_.d + String8 dependencyFile = outputFile; + dependencyFile.append(".d"); + + FILE* fp = fopen(dependencyFile.string(), "a"); + // Add this file to the dependency file + fprintf(fp, "%s \\\n", outputFile.string()); + fclose(fp); + } + assert(result == NO_ERROR); bail: @@ -187,6 +208,10 @@ bail: if (result == NO_ERROR && bundle->getVerbose()) printf("Done!\n"); + + #if BENCHMARK + fprintf(stdout, "BENCHMARK: End APK Bundling. Time Elapsed: %f ms \n",(clock() - startAPKTime)/1000.0); + #endif /* BENCHMARK */ return result; } @@ -204,34 +229,45 @@ ssize_t processAssets(Bundle* bundle, ZipFile* zip, const size_t N = assets->getGroupEntries().size(); for (size_t i=0; igetGroupEntries()[i]; - if (!filter.match(ge.toParams())) { - continue; - } - ssize_t res = processAssets(bundle, zip, assets, ge); + + ssize_t res = processAssets(bundle, zip, assets, ge, &filter); if (res < 0) { return res; } + count += res; } return count; } -ssize_t processAssets(Bundle* bundle, ZipFile* zip, - const sp& dir, const AaptGroupEntry& ge) +ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& dir, + const AaptGroupEntry& ge, const ResourceFilter* filter) { ssize_t count = 0; const size_t ND = dir->getDirs().size(); size_t i; for (i=0; igetDirs().valueAt(i), ge); + const sp& subDir = dir->getDirs().valueAt(i); + + const bool filterable = filter != NULL && subDir->getLeaf().find("mipmap-") != 0; + + if (filterable && subDir->getLeaf() != subDir->getPath() && !filter->match(ge.toParams())) { + continue; + } + + ssize_t res = processAssets(bundle, zip, subDir, ge, filterable ? filter : NULL); if (res < 0) { return res; } count += res; } + if (filter != NULL && !filter->match(ge.toParams())) { + return count; + } + const size_t NF = dir->getFiles().size(); for (i=0; i gp = dir->getFiles().valueAt(i); @@ -450,7 +486,7 @@ ssize_t processJarFiles(Bundle* bundle, ZipFile* zip) ZipFile jar; err = jar.open(jars[i], ZipFile::kOpenReadOnly); if (err != 0) { - fprintf(stderr, "ERROR: unable to open '%s' as a zip file: %zd\n", + fprintf(stderr, "ERROR: unable to open '%s' as a zip file: %d\n", jars[i], err); return err; }