Merge "Add dependency generation to Aapt for R.java"
This commit is contained in:
@ -1393,10 +1393,10 @@ status_t AaptDir::addLeafFile(const String8& leafName, const sp<AaptFile>& file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
||||||
const AaptGroupEntry& kind, const String8& resType)
|
const AaptGroupEntry& kind, const String8& resType,
|
||||||
|
sp<FilePathStore>& fullResPaths)
|
||||||
{
|
{
|
||||||
Vector<String8> fileNames;
|
Vector<String8> fileNames;
|
||||||
|
|
||||||
{
|
{
|
||||||
DIR* dir = NULL;
|
DIR* dir = NULL;
|
||||||
|
|
||||||
@ -1419,9 +1419,14 @@ ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
|||||||
if (isHidden(srcDir.string(), entry->d_name))
|
if (isHidden(srcDir.string(), entry->d_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fileNames.add(String8(entry->d_name));
|
String8 name(entry->d_name);
|
||||||
|
fileNames.add(name);
|
||||||
|
// Add fully qualified path for dependency purposes
|
||||||
|
// if we're collecting them
|
||||||
|
if (fullResPaths != NULL) {
|
||||||
|
fullResPaths->add(srcDir.appendPathCopy(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1448,7 +1453,7 @@ ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
|||||||
notAdded = true;
|
notAdded = true;
|
||||||
}
|
}
|
||||||
ssize_t res = subdir->slurpFullTree(bundle, pathName, kind,
|
ssize_t res = subdir->slurpFullTree(bundle, pathName, kind,
|
||||||
resType);
|
resType, fullResPaths);
|
||||||
if (res < NO_ERROR) {
|
if (res < NO_ERROR) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -1680,7 +1685,7 @@ ssize_t AaptAssets::slurpFromArgs(Bundle* bundle)
|
|||||||
sp<AaptDir> assetAaptDir = makeDir(String8(kAssetDir));
|
sp<AaptDir> assetAaptDir = makeDir(String8(kAssetDir));
|
||||||
AaptGroupEntry group;
|
AaptGroupEntry group;
|
||||||
count = assetAaptDir->slurpFullTree(bundle, assetRoot, group,
|
count = assetAaptDir->slurpFullTree(bundle, assetRoot, group,
|
||||||
String8());
|
String8(), mFullResPaths);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
totalCount = count;
|
totalCount = count;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1711,6 +1716,7 @@ ssize_t AaptAssets::slurpFromArgs(Bundle* bundle)
|
|||||||
sp<AaptAssets> nextOverlay = new AaptAssets();
|
sp<AaptAssets> nextOverlay = new AaptAssets();
|
||||||
current->setOverlay(nextOverlay);
|
current->setOverlay(nextOverlay);
|
||||||
current = nextOverlay;
|
current = nextOverlay;
|
||||||
|
current->setFullResPaths(mFullResPaths);
|
||||||
}
|
}
|
||||||
count = current->slurpResourceTree(bundle, String8(res));
|
count = current->slurpResourceTree(bundle, String8(res));
|
||||||
|
|
||||||
@ -1753,7 +1759,7 @@ ssize_t AaptAssets::slurpFromArgs(Bundle* bundle)
|
|||||||
* guarantees about ordering, so we're okay with an inorder search
|
* guarantees about ordering, so we're okay with an inorder search
|
||||||
* using whatever order the OS happens to hand back to us.
|
* using whatever order the OS happens to hand back to us.
|
||||||
*/
|
*/
|
||||||
count = slurpFullTree(bundle, assetRoot, AaptGroupEntry(), String8());
|
count = slurpFullTree(bundle, assetRoot, AaptGroupEntry(), String8(), mFullResPaths);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
/* failure; report error and remove archive */
|
/* failure; report error and remove archive */
|
||||||
totalCount = count;
|
totalCount = count;
|
||||||
@ -1779,9 +1785,10 @@ bail:
|
|||||||
|
|
||||||
ssize_t AaptAssets::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
ssize_t AaptAssets::slurpFullTree(Bundle* bundle, const String8& srcDir,
|
||||||
const AaptGroupEntry& kind,
|
const AaptGroupEntry& kind,
|
||||||
const String8& resType)
|
const String8& resType,
|
||||||
|
sp<FilePathStore>& fullResPaths)
|
||||||
{
|
{
|
||||||
ssize_t res = AaptDir::slurpFullTree(bundle, srcDir, kind, resType);
|
ssize_t res = AaptDir::slurpFullTree(bundle, srcDir, kind, resType, fullResPaths);
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
mGroupEntries.add(kind);
|
mGroupEntries.add(kind);
|
||||||
}
|
}
|
||||||
@ -1843,7 +1850,7 @@ ssize_t AaptAssets::slurpResourceTree(Bundle* bundle, const String8& srcDir)
|
|||||||
if (type == kFileTypeDirectory) {
|
if (type == kFileTypeDirectory) {
|
||||||
sp<AaptDir> dir = makeDir(String8(entry->d_name));
|
sp<AaptDir> dir = makeDir(String8(entry->d_name));
|
||||||
ssize_t res = dir->slurpFullTree(bundle, subdirName, group,
|
ssize_t res = dir->slurpFullTree(bundle, subdirName, group,
|
||||||
resType);
|
resType, mFullResPaths);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
count = res;
|
count = res;
|
||||||
goto bail;
|
goto bail;
|
||||||
|
@ -130,6 +130,7 @@ inline int strictly_order_type(const AaptGroupEntry& lhs, const AaptGroupEntry&
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AaptGroup;
|
class AaptGroup;
|
||||||
|
class FilePathStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single asset file we know about.
|
* A single asset file we know about.
|
||||||
@ -259,7 +260,8 @@ public:
|
|||||||
virtual ssize_t slurpFullTree(Bundle* bundle,
|
virtual ssize_t slurpFullTree(Bundle* bundle,
|
||||||
const String8& srcDir,
|
const String8& srcDir,
|
||||||
const AaptGroupEntry& kind,
|
const AaptGroupEntry& kind,
|
||||||
const String8& resType);
|
const String8& resType,
|
||||||
|
sp<FilePathStore>& fullResPaths);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform some sanity checks on the names of files and directories here.
|
* Perform some sanity checks on the names of files and directories here.
|
||||||
@ -474,6 +476,14 @@ public:
|
|||||||
ResourceTypeSet();
|
ResourceTypeSet();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Storage for lists of fully qualified paths for
|
||||||
|
// resources encountered during slurping.
|
||||||
|
class FilePathStore : public RefBase,
|
||||||
|
public Vector<String8>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FilePathStore();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset hierarchy being operated on.
|
* Asset hierarchy being operated on.
|
||||||
@ -507,7 +517,8 @@ public:
|
|||||||
virtual ssize_t slurpFullTree(Bundle* bundle,
|
virtual ssize_t slurpFullTree(Bundle* bundle,
|
||||||
const String8& srcDir,
|
const String8& srcDir,
|
||||||
const AaptGroupEntry& kind,
|
const AaptGroupEntry& kind,
|
||||||
const String8& resType);
|
const String8& resType,
|
||||||
|
sp<FilePathStore>& fullResPaths);
|
||||||
|
|
||||||
ssize_t slurpResourceTree(Bundle* bundle, const String8& srcDir);
|
ssize_t slurpResourceTree(Bundle* bundle, const String8& srcDir);
|
||||||
ssize_t slurpResourceZip(Bundle* bundle, const char* filename);
|
ssize_t slurpResourceZip(Bundle* bundle, const char* filename);
|
||||||
@ -535,6 +546,10 @@ public:
|
|||||||
inline void
|
inline void
|
||||||
setResources(KeyedVector<String8, sp<ResourceTypeSet> >* res) { delete mRes; mRes = res; }
|
setResources(KeyedVector<String8, sp<ResourceTypeSet> >* res) { delete mRes; mRes = res; }
|
||||||
|
|
||||||
|
inline sp<FilePathStore>& getFullResPaths() { return mFullResPaths; }
|
||||||
|
inline void
|
||||||
|
setFullResPaths(sp<FilePathStore>& res) { mFullResPaths = res; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String8 mPackage;
|
String8 mPackage;
|
||||||
SortedVector<AaptGroupEntry> mGroupEntries;
|
SortedVector<AaptGroupEntry> mGroupEntries;
|
||||||
@ -548,6 +563,8 @@ private:
|
|||||||
|
|
||||||
sp<AaptAssets> mOverlay;
|
sp<AaptAssets> mOverlay;
|
||||||
KeyedVector<String8, sp<ResourceTypeSet> >* mRes;
|
KeyedVector<String8, sp<ResourceTypeSet> >* mRes;
|
||||||
|
|
||||||
|
sp<FilePathStore> mFullResPaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __AAPT_ASSETS_H
|
#endif // __AAPT_ASSETS_H
|
||||||
|
@ -41,7 +41,8 @@ public:
|
|||||||
mCompressionMethod(0), mOutputAPKFile(NULL),
|
mCompressionMethod(0), mOutputAPKFile(NULL),
|
||||||
mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
|
mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
|
||||||
mIsOverlayPackage(false),
|
mIsOverlayPackage(false),
|
||||||
mAutoAddOverlay(false), mAssetSourceDir(NULL), mProguardFile(NULL),
|
mAutoAddOverlay(false), mGenDependencies(false),
|
||||||
|
mAssetSourceDir(NULL), mProguardFile(NULL),
|
||||||
mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
|
mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
|
||||||
mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
|
mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
|
||||||
mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
|
mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
|
||||||
@ -97,6 +98,8 @@ public:
|
|||||||
void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; }
|
void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; }
|
||||||
bool getAutoAddOverlay() { return mAutoAddOverlay; }
|
bool getAutoAddOverlay() { return mAutoAddOverlay; }
|
||||||
void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
|
void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
|
||||||
|
bool getGenDependencies() { return mGenDependencies; }
|
||||||
|
void setGenDependencies(bool val) { mGenDependencies = val; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input options.
|
* Input options.
|
||||||
@ -226,6 +229,7 @@ private:
|
|||||||
const char* mInstrumentationPackageNameOverride;
|
const char* mInstrumentationPackageNameOverride;
|
||||||
bool mIsOverlayPackage;
|
bool mIsOverlayPackage;
|
||||||
bool mAutoAddOverlay;
|
bool mAutoAddOverlay;
|
||||||
|
bool mGenDependencies;
|
||||||
const char* mAssetSourceDir;
|
const char* mAssetSourceDir;
|
||||||
const char* mProguardFile;
|
const char* mProguardFile;
|
||||||
const char* mAndroidManifestFile;
|
const char* mAndroidManifestFile;
|
||||||
|
@ -1353,6 +1353,8 @@ int doPackage(Bundle* bundle)
|
|||||||
status_t err;
|
status_t err;
|
||||||
sp<AaptAssets> assets;
|
sp<AaptAssets> assets;
|
||||||
int N;
|
int N;
|
||||||
|
FILE* fp;
|
||||||
|
String8 dependencyFile;
|
||||||
|
|
||||||
// -c zz_ZZ means do pseudolocalization
|
// -c zz_ZZ means do pseudolocalization
|
||||||
ResourceFilter filter;
|
ResourceFilter filter;
|
||||||
@ -1387,6 +1389,13 @@ int doPackage(Bundle* bundle)
|
|||||||
|
|
||||||
// Load the assets.
|
// Load the assets.
|
||||||
assets = new AaptAssets();
|
assets = new AaptAssets();
|
||||||
|
|
||||||
|
// Set up the resource gathering in assets if we're trying to make R.java
|
||||||
|
if (bundle->getGenDependencies()) {
|
||||||
|
sp<FilePathStore> pathStore = new FilePathStore;
|
||||||
|
assets->setFullResPaths(pathStore);
|
||||||
|
}
|
||||||
|
|
||||||
err = assets->slurpFromArgs(bundle);
|
err = assets->slurpFromArgs(bundle);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1396,7 +1405,7 @@ int doPackage(Bundle* bundle)
|
|||||||
assets->print();
|
assets->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If they asked for any files that need to be compiled, do so.
|
// If they asked for any fileAs that need to be compiled, do so.
|
||||||
if (bundle->getResourceSourceDirs().size() || bundle->getAndroidManifestFile()) {
|
if (bundle->getResourceSourceDirs().size() || bundle->getAndroidManifestFile()) {
|
||||||
err = buildResources(bundle, assets);
|
err = buildResources(bundle, assets);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
@ -1410,18 +1419,26 @@ int doPackage(Bundle* bundle)
|
|||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bundle->getGenDependencies()) {
|
||||||
|
dependencyFile = String8(bundle->getRClassDir());
|
||||||
|
// Make sure we have a clean dependency file to start with
|
||||||
|
dependencyFile.appendPath("R.d");
|
||||||
|
fp = fopen(dependencyFile, "w");
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
// Write out R.java constants
|
// Write out R.java constants
|
||||||
if (assets->getPackage() == assets->getSymbolsPrivatePackage()) {
|
if (assets->getPackage() == assets->getSymbolsPrivatePackage()) {
|
||||||
if (bundle->getCustomPackage() == NULL) {
|
if (bundle->getCustomPackage() == NULL) {
|
||||||
err = writeResourceSymbols(bundle, assets, assets->getPackage(), true);
|
err = writeResourceSymbols(bundle, assets, assets->getPackage(), true);
|
||||||
// Copy R.java for libraries
|
// Copy R.java for libraries
|
||||||
if (bundle->getExtraPackages() != NULL) {
|
if (bundle->getExtraPackages() != NULL) {
|
||||||
// Split on semicolon
|
// Split on colon
|
||||||
String8 libs(bundle->getExtraPackages());
|
String8 libs(bundle->getExtraPackages());
|
||||||
char* packageString = strtok(libs.lockBuffer(libs.length()), ";");
|
char* packageString = strtok(libs.lockBuffer(libs.length()), ":");
|
||||||
while (packageString != NULL) {
|
while (packageString != NULL) {
|
||||||
err = writeResourceSymbols(bundle, assets, String8(packageString), true);
|
err = writeResourceSymbols(bundle, assets, String8(packageString), true);
|
||||||
packageString = strtok(NULL, ";");
|
packageString = strtok(NULL, ":");
|
||||||
}
|
}
|
||||||
libs.unlockBuffer();
|
libs.unlockBuffer();
|
||||||
}
|
}
|
||||||
@ -1443,6 +1460,19 @@ int doPackage(Bundle* bundle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bundle->getGenDependencies()) {
|
||||||
|
// Now that writeResourceSymbols has taken care of writing the
|
||||||
|
// dependency targets to the dependencyFile, we'll write the
|
||||||
|
// pre-requisites.
|
||||||
|
fp = fopen(dependencyFile, "a+");
|
||||||
|
fprintf(fp, " : ");
|
||||||
|
err = writeDependencyPreReqs(bundle, assets, fp);
|
||||||
|
|
||||||
|
// Also manually add the AndroidManifeset since it's a non-asset
|
||||||
|
fprintf(fp, "%s \\\n", bundle->getAndroidManifestFile());
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
// Write out the ProGuard file
|
// Write out the ProGuard file
|
||||||
err = writeProguardFile(bundle, assets);
|
err = writeProguardFile(bundle, assets);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
|
@ -146,7 +146,9 @@ void usage(void)
|
|||||||
" --custom-package\n"
|
" --custom-package\n"
|
||||||
" generates R.java into a different package.\n"
|
" generates R.java into a different package.\n"
|
||||||
" --extra-packages\n"
|
" --extra-packages\n"
|
||||||
" generate R.java for libraries. Separate libraries with ';'.\n"
|
" generate R.java for libraries. Separate libraries with ':'.\n"
|
||||||
|
" --generate-dependencies\n"
|
||||||
|
" generate a dependency file for R.java.\n"
|
||||||
" --auto-add-overlay\n"
|
" --auto-add-overlay\n"
|
||||||
" Automatically add resources that are only in overlays.\n"
|
" Automatically add resources that are only in overlays.\n"
|
||||||
" --rename-manifest-package\n"
|
" --rename-manifest-package\n"
|
||||||
@ -486,6 +488,8 @@ int main(int argc, char* const argv[])
|
|||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
bundle.setExtraPackages(argv[0]);
|
bundle.setExtraPackages(argv[0]);
|
||||||
|
} else if (strcmp(cp, "-generate-dependencies") == 0) {
|
||||||
|
bundle.setGenDependencies(true);
|
||||||
} else if (strcmp(cp, "-utf16") == 0) {
|
} else if (strcmp(cp, "-utf16") == 0) {
|
||||||
bundle.setWantUTF16(true);
|
bundle.setWantUTF16(true);
|
||||||
} else if (strcmp(cp, "-rename-manifest-package") == 0) {
|
} else if (strcmp(cp, "-rename-manifest-package") == 0) {
|
||||||
|
@ -46,4 +46,5 @@ int dumpResources(Bundle* bundle);
|
|||||||
String8 getAttribute(const ResXMLTree& tree, const char* ns,
|
String8 getAttribute(const ResXMLTree& tree, const char* ns,
|
||||||
const char* attr, String8* outError);
|
const char* attr, String8* outError);
|
||||||
|
|
||||||
|
status_t writeDependencyPreReqs(Bundle* bundle, const sp<AaptAssets>& assets, FILE* fp);
|
||||||
#endif // __MAIN_H
|
#endif // __MAIN_H
|
||||||
|
@ -51,6 +51,12 @@ ResourceTypeSet::ResourceTypeSet()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePathStore::FilePathStore()
|
||||||
|
:RefBase(),
|
||||||
|
Vector<String8>()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
class ResourceDirIterator
|
class ResourceDirIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -1849,6 +1855,16 @@ status_t writeResourceSymbols(Bundle* bundle, const sp<AaptAssets>& assets,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
if (bundle->getGenDependencies()) {
|
||||||
|
// Add this R.java to the dependency file
|
||||||
|
String8 dependencyFile(bundle->getRClassDir());
|
||||||
|
dependencyFile.appendPath("R.d");
|
||||||
|
|
||||||
|
fp = fopen(dependencyFile.string(), "a");
|
||||||
|
fprintf(fp,"%s \\\n", dest.string());
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
@ -2170,3 +2186,16 @@ writeProguardFile(Bundle* bundle, const sp<AaptAssets>& assets)
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
writeDependencyPreReqs(Bundle* bundle, const sp<AaptAssets>& assets, FILE* fp)
|
||||||
|
{
|
||||||
|
status_t deps = -1;
|
||||||
|
sp<FilePathStore> files = assets->getFullResPaths();
|
||||||
|
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;
|
||||||
|
}
|
@ -57,7 +57,7 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Open a new or existing archive.
|
* Open a new or existing archive.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
enum {
|
||||||
kOpenReadOnly = 0x01,
|
kOpenReadOnly = 0x01,
|
||||||
kOpenReadWrite = 0x02,
|
kOpenReadWrite = 0x02,
|
||||||
kOpenCreate = 0x04, // create if it doesn't exist
|
kOpenCreate = 0x04, // create if it doesn't exist
|
||||||
|
Reference in New Issue
Block a user