am 203356a3
: Merge "Add support for multiple asset dirs (-A)" into klp-modular-dev
* commit '203356a34a82bfc759be02dfa1caa4529dce0732': Add support for multiple asset dirs (-A)
This commit is contained in:
@ -1631,9 +1631,18 @@ String8 AaptFile::getPrintableSource() const
|
||||
// =========================================================================
|
||||
// =========================================================================
|
||||
|
||||
status_t AaptGroup::addFile(const sp<AaptFile>& file)
|
||||
status_t AaptGroup::addFile(const sp<AaptFile>& file, const bool overwriteDuplicate)
|
||||
{
|
||||
if (mFiles.indexOfKey(file->getGroupEntry()) < 0) {
|
||||
ssize_t index = mFiles.indexOfKey(file->getGroupEntry());
|
||||
if (index >= 0 && overwriteDuplicate) {
|
||||
fprintf(stderr, "warning: overwriting '%s' with '%s'\n",
|
||||
mFiles[index]->getSourceFile().string(),
|
||||
file->getSourceFile().string());
|
||||
removeFile(index);
|
||||
index = -1;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
file->mPath = mPath;
|
||||
mFiles.add(file->getGroupEntry(), file);
|
||||
return NO_ERROR;
|
||||
@ -1739,7 +1748,8 @@ void AaptDir::removeDir(const String8& name)
|
||||
mDirs.removeItem(name);
|
||||
}
|
||||
|
||||
status_t AaptDir::addLeafFile(const String8& leafName, const sp<AaptFile>& file)
|
||||
status_t AaptDir::addLeafFile(const String8& leafName, const sp<AaptFile>& file,
|
||||
const bool overwrite)
|
||||
{
|
||||
sp<AaptGroup> group;
|
||||
if (mFiles.indexOfKey(leafName) >= 0) {
|
||||
@ -1749,12 +1759,12 @@ status_t AaptDir::addLeafFile(const String8& leafName, const sp<AaptFile>& file)
|
||||
mFiles.add(leafName, group);
|
||||
}
|
||||
|
||||
return group->addFile(file);
|
||||
return group->addFile(file, overwrite);
|
||||
}
|
||||
|
||||
ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
||||
const AaptGroupEntry& kind, const String8& resType,
|
||||
sp<FilePathStore>& fullResPaths)
|
||||
sp<FilePathStore>& fullResPaths, const bool overwrite)
|
||||
{
|
||||
Vector<String8> fileNames;
|
||||
{
|
||||
@ -1813,7 +1823,7 @@ ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
||||
notAdded = true;
|
||||
}
|
||||
ssize_t res = subdir->slurpFullTree(bundle, pathName, kind,
|
||||
resType, fullResPaths);
|
||||
resType, fullResPaths, overwrite);
|
||||
if (res < NO_ERROR) {
|
||||
return res;
|
||||
}
|
||||
@ -1823,7 +1833,7 @@ ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
||||
count += res;
|
||||
} else if (type == kFileTypeRegular) {
|
||||
sp<AaptFile> file = new AaptFile(pathName, kind, resType);
|
||||
status_t err = addLeafFile(fileNames[i], file);
|
||||
status_t err = addLeafFile(fileNames[i], file, overwrite);
|
||||
if (err != NO_ERROR) {
|
||||
return err;
|
||||
}
|
||||
@ -2089,24 +2099,24 @@ ssize_t AaptAssets::slurpFromArgs(Bundle* bundle)
|
||||
/*
|
||||
* If a directory of custom assets was supplied, slurp 'em up.
|
||||
*/
|
||||
if (bundle->getAssetSourceDir()) {
|
||||
const char* assetDir = bundle->getAssetSourceDir();
|
||||
|
||||
FileType type = getFileType(assetDir);
|
||||
const Vector<const char*>& assetDirs = bundle->getAssetSourceDirs();
|
||||
const int AN = assetDirs.size();
|
||||
for (int i = 0; i < AN; i++) {
|
||||
FileType type = getFileType(assetDirs[i]);
|
||||
if (type == kFileTypeNonexistent) {
|
||||
fprintf(stderr, "ERROR: asset directory '%s' does not exist\n", assetDir);
|
||||
fprintf(stderr, "ERROR: asset directory '%s' does not exist\n", assetDirs[i]);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
if (type != kFileTypeDirectory) {
|
||||
fprintf(stderr, "ERROR: '%s' is not a directory\n", assetDir);
|
||||
fprintf(stderr, "ERROR: '%s' is not a directory\n", assetDirs[i]);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
String8 assetRoot(assetDir);
|
||||
String8 assetRoot(assetDirs[i]);
|
||||
sp<AaptDir> assetAaptDir = makeDir(String8(kAssetDir));
|
||||
AaptGroupEntry group;
|
||||
count = assetAaptDir->slurpFullTree(bundle, assetRoot, group,
|
||||
String8(), mFullAssetPaths);
|
||||
String8(), mFullAssetPaths, true);
|
||||
if (count < 0) {
|
||||
totalCount = count;
|
||||
goto bail;
|
||||
@ -2116,9 +2126,10 @@ ssize_t AaptAssets::slurpFromArgs(Bundle* bundle)
|
||||
}
|
||||
totalCount += count;
|
||||
|
||||
if (bundle->getVerbose())
|
||||
if (bundle->getVerbose()) {
|
||||
printf("Found %d custom asset file%s in %s\n",
|
||||
count, (count==1) ? "" : "s", assetDir);
|
||||
count, (count==1) ? "" : "s", assetDirs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -235,7 +235,7 @@ public:
|
||||
const DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> >& getFiles() const
|
||||
{ return mFiles; }
|
||||
|
||||
status_t addFile(const sp<AaptFile>& file);
|
||||
status_t addFile(const sp<AaptFile>& file, const bool overwriteDuplicate=false);
|
||||
void removeFile(size_t index);
|
||||
|
||||
void print(const String8& prefix) const;
|
||||
@ -301,12 +301,14 @@ private:
|
||||
status_t addDir(const String8& name, const sp<AaptDir>& dir);
|
||||
sp<AaptDir> makeDir(const String8& name);
|
||||
status_t addLeafFile(const String8& leafName,
|
||||
const sp<AaptFile>& file);
|
||||
const sp<AaptFile>& file,
|
||||
const bool overwrite=false);
|
||||
virtual ssize_t slurpFullTree(Bundle* bundle,
|
||||
const String8& srcDir,
|
||||
const AaptGroupEntry& kind,
|
||||
const String8& resType,
|
||||
sp<FilePathStore>& fullResPaths);
|
||||
sp<FilePathStore>& fullResPaths,
|
||||
const bool overwrite=false);
|
||||
|
||||
String8 mLeaf;
|
||||
String8 mPath;
|
||||
|
@ -55,7 +55,6 @@ public:
|
||||
mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
|
||||
mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
|
||||
mAutoAddOverlay(false), mGenDependencies(false),
|
||||
mAssetSourceDir(NULL),
|
||||
mCrunchedOutputDir(NULL), mProguardFile(NULL),
|
||||
mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
|
||||
mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
|
||||
@ -123,8 +122,8 @@ public:
|
||||
/*
|
||||
* Input options.
|
||||
*/
|
||||
const char* getAssetSourceDir() const { return mAssetSourceDir; }
|
||||
void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
|
||||
const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; }
|
||||
void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); }
|
||||
const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
|
||||
void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
|
||||
const char* getProguardFile() const { return mProguardFile; }
|
||||
@ -272,6 +271,7 @@ private:
|
||||
android::Vector<const char*> mPackageIncludes;
|
||||
android::Vector<const char*> mJarFiles;
|
||||
android::Vector<const char*> mNoCompressExtensions;
|
||||
android::Vector<const char*> mAssetSourceDirs;
|
||||
android::Vector<const char*> mResourceSourceDirs;
|
||||
|
||||
const char* mManifestMinSdkVersion;
|
||||
|
@ -1896,7 +1896,7 @@ int doPackage(Bundle* bundle)
|
||||
|
||||
N = bundle->getFileSpecCount();
|
||||
if (N < 1 && bundle->getResourceSourceDirs().size() == 0 && bundle->getJarFiles().size() == 0
|
||||
&& bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDir() == NULL) {
|
||||
&& bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDirs().size() == 0) {
|
||||
fprintf(stderr, "ERROR: no input files\n");
|
||||
goto bail;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ int main(int argc, char* const argv[])
|
||||
goto bail;
|
||||
}
|
||||
convertPath(argv[0]);
|
||||
bundle.setAssetSourceDir(argv[0]);
|
||||
bundle.addAssetSourceDir(argv[0]);
|
||||
break;
|
||||
case 'G':
|
||||
argc--;
|
||||
|
Reference in New Issue
Block a user