X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/838914df8530468f5ce5e011a7049a9c48c81e54..640c141b2e6c59c7b9876c27ab7abadec7723c45:/Resource.cpp diff --git a/Resource.cpp b/Resource.cpp index 730bd71..1ecf7da 100644 --- a/Resource.cpp +++ b/Resource.cpp @@ -10,6 +10,18 @@ #include "ResourceTable.h" #include "Images.h" +#include "CrunchCache.h" +#include "FileFinder.h" +#include "CacheUpdater.h" + +#if HAVE_PRINTF_ZD +# define ZD "%zd" +# define ZD_TYPE ssize_t +#else +# define ZD "%ld" +# define ZD_TYPE long +#endif + #define NOISY(x) // x // ========================================================================== @@ -51,6 +63,12 @@ ResourceTypeSet::ResourceTypeSet() { } +FilePathStore::FilePathStore() + :RefBase(), + Vector() +{ +} + class ResourceDirIterator { public: @@ -287,18 +305,19 @@ static status_t makeFileResources(Bundle* bundle, const sp& assets, static status_t preProcessImages(Bundle* bundle, const sp& assets, const sp& set, const char* type) { - ResourceDirIterator it(set, String8(type)); - Vector > newNameFiles; - Vector newNamePaths; bool hasErrors = false; - ssize_t res; - while ((res=it.next()) == NO_ERROR) { - res = preProcessImage(bundle, assets, it.getFile(), NULL); - if (res < NO_ERROR) { - hasErrors = true; + ssize_t res = NO_ERROR; + if (bundle->getUseCrunchCache() == false) { + ResourceDirIterator it(set, String8(type)); + Vector > newNameFiles; + Vector newNamePaths; + while ((res=it.next()) == NO_ERROR) { + res = preProcessImage(bundle, assets, it.getFile(), NULL); + if (res < NO_ERROR) { + hasErrors = true; + } } } - return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR; } @@ -341,18 +360,27 @@ static void collect_files(const sp& dir, if (index < 0) { sp set = new ResourceTypeSet(); + NOISY(printf("Creating new resource type set for leaf %s with group %s (%p)\n", + leafName.string(), group->getPath().string(), group.get())); set->add(leafName, group); resources->add(resType, set); } else { sp set = resources->valueAt(index); index = set->indexOfKey(leafName); if (index < 0) { + NOISY(printf("Adding to resource type set for leaf %s group %s (%p)\n", + leafName.string(), group->getPath().string(), group.get())); set->add(leafName, group); } else { sp existingGroup = set->valueAt(index); - int M = files.size(); - for (int j=0; jaddFile(files.valueAt(j)); + NOISY(printf("Extending to resource type set for leaf %s group %s (%p)\n", + leafName.string(), group->getPath().string(), group.get())); + for (size_t j=0; jgetSourceFile().string(), + files.keyAt(j).toDirName(String8()).string(), + resType.string())); + status_t err = existingGroup->addFile(files.valueAt(j)); } } } @@ -367,9 +395,12 @@ static void collect_files(const sp& ass, for (int i=0; i d = dirs.itemAt(i); + NOISY(printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(), + d->getLeaf().string())); collect_files(d, resources); // don't try to include the res dir + NOISY(printf("Removing dir leaf %s\n", d->getLeaf().string())); ass->removeDir(d->getLeaf()); } } @@ -543,11 +574,11 @@ static bool applyFileOverlay(Bundle *bundle, DefaultKeyedVector > baseFiles = baseGroup->getFiles(); for (size_t i=0; i < baseFiles.size(); i++) { - printf("baseFile %zd has flavor %s\n", i, + printf("baseFile " ZD " has flavor %s\n", (ZD_TYPE) i, baseFiles.keyAt(i).toString().string()); } for (size_t i=0; i < overlayFiles.size(); i++) { - printf("overlayFile %zd has flavor %s\n", i, + printf("overlayFile " ZD " has flavor %s\n", (ZD_TYPE) i, overlayFiles.keyAt(i).toString().string()); } } @@ -559,16 +590,21 @@ static bool applyFileOverlay(Bundle *bundle, size_t baseFileIndex = baseGroup->getFiles().indexOfKey(overlayFiles. keyAt(overlayGroupIndex)); - if(baseFileIndex < UNKNOWN_ERROR) { + if (baseFileIndex < UNKNOWN_ERROR) { if (bundle->getVerbose()) { - printf("found a match (%zd) for overlay file %s, for flavor %s\n", - baseFileIndex, + printf("found a match (" ZD ") for overlay file %s, for flavor %s\n", + (ZD_TYPE) baseFileIndex, overlayGroup->getLeaf().string(), overlayFiles.keyAt(overlayGroupIndex).toString().string()); } baseGroup->removeFile(baseFileIndex); } else { // didn't find a match fall through and add it.. + if (true || bundle->getVerbose()) { + printf("nothing matches overlay file %s, for flavor %s\n", + overlayGroup->getLeaf().string(), + overlayFiles.keyAt(overlayGroupIndex).toString().string()); + } } baseGroup->addFile(overlayFiles.valueAt(overlayGroupIndex)); assets->addGroupEntry(overlayFiles.keyAt(overlayGroupIndex)); @@ -748,6 +784,35 @@ status_t massageManifest(Bundle* bundle, sp root) } \ } while (0) +status_t updatePreProcessedCache(Bundle* bundle) +{ + #if BENCHMARK + fprintf(stdout, "BENCHMARK: Starting PNG PreProcessing \n"); + long startPNGTime = clock(); + #endif /* BENCHMARK */ + + String8 source(bundle->getResourceSourceDirs()[0]); + String8 dest(bundle->getCrunchedOutputDir()); + + FileFinder* ff = new SystemFileFinder(); + CrunchCache cc(source,dest,ff); + + CacheUpdater* cu = new SystemCacheUpdater(bundle); + size_t numFiles = cc.crunch(cu); + + if (bundle->getVerbose()) + fprintf(stdout, "Crunched %d PNG files to update cache\n", (int)numFiles); + + delete ff; + delete cu; + + #if BENCHMARK + fprintf(stdout, "BENCHMARK: End PNG PreProcessing. Time Elapsed: %f ms \n" + ,(clock() - startPNGTime)/1000.0); + #endif /* BENCHMARK */ + return 0; +} + status_t buildResources(Bundle* bundle, const sp& assets) { // First, look for a package file to parse. This is required to @@ -1917,6 +1982,18 @@ status_t writeResourceSymbols(Bundle* bundle, const sp& assets, return err; } fclose(fp); + + // If we were asked to generate a dependency file, we'll go ahead and add this R.java + // as a target in the dependency file right next to it. + if (bundle->getGenDependencies()) { + // Add this R.java to the dependency file + String8 dependencyFile(bundle->getRClassDir()); + dependencyFile.appendPath("R.java.d"); + + fp = fopen(dependencyFile.string(), "a"); + fprintf(fp,"%s \\\n", dest.string()); + fclose(fp); + } } return NO_ERROR; @@ -2194,6 +2271,11 @@ writeProguardForLayouts(ProguardKeepSet* keep, const sp& assets) } } } + // Handle the overlays + sp overlay = assets->getOverlay(); + if (overlay.get()) { + return writeProguardForLayouts(keep, overlay); + } return NO_ERROR; } @@ -2239,3 +2321,27 @@ writeProguardFile(Bundle* bundle, const sp& assets) return err; } + +// Loops through the string paths and writes them to the file pointer +// Each file path is written on its own line with a terminating backslash. +status_t writePathsToFile(const sp& files, FILE* fp) +{ + status_t deps = -1; + for (size_t file_i = 0; file_i < files->size(); ++file_i) { + // Add the full file path to the dependency file + fprintf(fp, "%s \\\n", files->itemAt(file_i).string()); + deps++; + } + return deps; +} + +status_t +writeDependencyPreReqs(Bundle* bundle, const sp& assets, FILE* fp, bool includeRaw) +{ + status_t deps = -1; + deps += writePathsToFile(assets->getFullResPaths(), fp); + if (includeRaw) { + deps += writePathsToFile(assets->getFullAssetPaths(), fp); + } + return deps; +}