X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/dadd9c1fc18bd05c84a357b56e945b5829b3bd95..6e5d020e2e2975ebe0ebad5caf8047acfca8b6c4:/Package.cpp diff --git a/Package.cpp b/Package.cpp index 23f641a..3930117 100644 --- a/Package.cpp +++ b/Package.cpp @@ -5,9 +5,13 @@ // #include "Main.h" #include "AaptAssets.h" +#include "ResourceTable.h" +#include "ResourceFilter.h" -#include -#include +#include +#include +#include +#include #include #include @@ -22,7 +26,7 @@ static const char* kExcludeExtension = ".EXCLUDE"; static const char* kNoCompressExt[] = { ".jpg", ".jpeg", ".png", ".gif", ".wav", ".mp2", ".mp3", ".ogg", ".aac", - ".mpg", ".mpeg", ".mid", ".midi", ".smf", + ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet", ".rtttl", ".imy", ".xmf", ".mp4", ".m4a", ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2", ".amr", ".awb", ".wma", ".wmv" @@ -30,11 +34,11 @@ 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(const String8& pathName); +bool okayToCompress(Bundle* bundle, const String8& pathName); ssize_t processJarFiles(Bundle* bundle, ZipFile* zip); /* @@ -47,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; @@ -165,10 +174,25 @@ status_t writeAPK(Bundle* bundle, const sp& assets, delete zip; // close the file so we can remove it in Win32 zip = NULL; if (unlink(outputFile.string()) != 0) { - fprintf(stderr, "WARNING: could not unlink '%s'\n", outputFile.string()); + fprintf(stderr, "warning: could not unlink '%s'\n", outputFile.string()); } } + // 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: @@ -178,48 +202,72 @@ bail: printf("Removing %s due to earlier failures\n", outputFile.string()); } if (unlink(outputFile.string()) != 0) { - fprintf(stderr, "WARNING: could not unlink '%s'\n", outputFile.string()); + fprintf(stderr, "warning: could not unlink '%s'\n", outputFile.string()); } } 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; } ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& assets) { + ResourceFilter filter; + status_t status = filter.parse(bundle->getConfigurations()); + if (status != NO_ERROR) { + return -1; + } + ssize_t count = 0; const size_t N = assets->getGroupEntries().size(); for (size_t i=0; igetGroupEntries()[i]; - 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); @@ -271,7 +319,7 @@ bool processFile(Bundle* bundle, ZipFile* zip, if (fileNameLen > excludeExtensionLen && (0 == strcmp(storageName.string() + (fileNameLen - excludeExtensionLen), kExcludeExtension))) { - fprintf(stderr, "WARNING: '%s' not added to Zip\n", storageName.string()); + fprintf(stderr, "warning: '%s' not added to Zip\n", storageName.string()); return true; } @@ -327,7 +375,7 @@ bool processFile(Bundle* bundle, ZipFile* zip, } else if (!hasData) { /* don't compress certain files, e.g. PNGs */ int compressionMethod = bundle->getCompressionMethod(); - if (!okayToCompress(storageName)) { + if (!okayToCompress(bundle, storageName)) { compressionMethod = ZipEntry::kCompressStored; } result = zip->add(file->getSourceFile().string(), storageName.string(), compressionMethod, @@ -365,7 +413,7 @@ bool processFile(Bundle* bundle, ZipFile* zip, * Determine whether or not we want to try to compress this file based * on the file extension. */ -bool okayToCompress(const String8& pathName) +bool okayToCompress(Bundle* bundle, const String8& pathName) { String8 ext = pathName.getPathExtension(); int i; @@ -378,6 +426,19 @@ bool okayToCompress(const String8& pathName) return false; } + const android::Vector& others(bundle->getNoCompressExtensions()); + for (i = 0; i < (int)others.size(); i++) { + const char* str = others[i]; + int pos = pathName.length() - strlen(str); + if (pos < 0) { + continue; + } + const char* path = pathName.string(); + if (strcasecmp(path + pos, str) == 0) { + return false; + } + } + return true; } @@ -416,7 +477,7 @@ ssize_t processJarFile(ZipFile* jar, ZipFile* out) ssize_t processJarFiles(Bundle* bundle, ZipFile* zip) { - ssize_t err; + status_t err; ssize_t count = 0; const android::Vector& jars = bundle->getJarFiles(); @@ -425,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; }