Skip to content

Commit d98e1be

Browse files
Xavier DucrohetAndroid Git Automerger
authored andcommitted
am f475072: am 9d829f9: am 21e6e2d: Merge "Change generated dependency file names"
* commit 'f4750724cf8db972a052cb388dc9a39fc7aa6dd6': Change generated dependency file names
2 parents 294539d + f475072 commit d98e1be

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

tools/aapt/Command.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,9 @@ int doPackage(Bundle* bundle)
15461546
assets = new AaptAssets();
15471547

15481548
// Set up the resource gathering in assets if we're going to generate
1549-
// dependency files
1549+
// dependency files. Every time we encounter a resource while slurping
1550+
// the tree, we'll add it to these stores so we have full resource paths
1551+
// to write to a dependency file.
15501552
if (bundle->getGenDependencies()) {
15511553
sp<FilePathStore> resPathStore = new FilePathStore;
15521554
assets->setFullResPaths(resPathStore);
@@ -1577,15 +1579,20 @@ int doPackage(Bundle* bundle)
15771579
goto bail;
15781580
}
15791581

1582+
// If we've been asked to generate a dependency file, do that here
15801583
if (bundle->getGenDependencies()) {
1584+
// If this is the packaging step, generate the dependency file next to
1585+
// the output apk (e.g. bin/resources.ap_.d)
15811586
if (outputAPKFile) {
15821587
dependencyFile = String8(outputAPKFile);
1583-
// Strip the extension and add new one
1584-
dependencyFile = dependencyFile.getBasePath();
1588+
// Add the .d extension to the dependency file.
15851589
dependencyFile.append(".d");
15861590
} else {
1591+
// Else if this is the R.java dependency generation step,
1592+
// generate the dependency file in the R.java package subdirectory
1593+
// e.g. gen/com/foo/app/R.java.d
15871594
dependencyFile = String8(bundle->getRClassDir());
1588-
dependencyFile.appendPath("R.d");
1595+
dependencyFile.appendPath("R.java.d");
15891596
}
15901597
// Make sure we have a clean dependency file to start with
15911598
fp = fopen(dependencyFile, "w");
@@ -1595,13 +1602,18 @@ int doPackage(Bundle* bundle)
15951602
// Write out R.java constants
15961603
if (assets->getPackage() == assets->getSymbolsPrivatePackage()) {
15971604
if (bundle->getCustomPackage() == NULL) {
1605+
// Write the R.java file into the appropriate class directory
1606+
// e.g. gen/com/foo/app/R.java
15981607
err = writeResourceSymbols(bundle, assets, assets->getPackage(), true);
1599-
// Copy R.java for libraries
1608+
// If we have library files, we're going to write our R.java file into
1609+
// the appropriate class directory for those libraries as well.
1610+
// e.g. gen/com/foo/app/lib/R.java
16001611
if (bundle->getExtraPackages() != NULL) {
16011612
// Split on colon
16021613
String8 libs(bundle->getExtraPackages());
16031614
char* packageString = strtok(libs.lockBuffer(libs.length()), ":");
16041615
while (packageString != NULL) {
1616+
// Write the R.java file out with the correct package name
16051617
err = writeResourceSymbols(bundle, assets, String8(packageString), true);
16061618
packageString = strtok(NULL, ":");
16071619
}
@@ -1640,14 +1652,19 @@ int doPackage(Bundle* bundle)
16401652
}
16411653
}
16421654

1655+
// If we've been asked to generate a dependency file, we need to finish up here.
1656+
// the writeResourceSymbols and writeAPK functions have already written the target
1657+
// half of the dependency file, now we need to write the prerequisites. (files that
1658+
// the R.java file or .ap_ file depend on)
16431659
if (bundle->getGenDependencies()) {
16441660
// Now that writeResourceSymbols or writeAPK has taken care of writing
16451661
// the targets to our dependency file, we'll write the prereqs
16461662
fp = fopen(dependencyFile, "a+");
16471663
fprintf(fp, " : ");
16481664
bool includeRaw = (outputAPKFile != NULL);
16491665
err = writeDependencyPreReqs(bundle, assets, fp, includeRaw);
1650-
// Also manually add the AndroidManifeset since it's a non-asset
1666+
// Also manually add the AndroidManifeset since it's not under res/ or assets/
1667+
// and therefore was not added to our pathstores during slurping
16511668
fprintf(fp, "%s \\\n", bundle->getAndroidManifestFile());
16521669
fclose(fp);
16531670
}

tools/aapt/Package.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,17 @@ status_t writeAPK(Bundle* bundle, const sp<AaptAssets>& assets,
177177
}
178178
}
179179

180+
// If we've been asked to generate a dependency file for the .ap_ package,
181+
// do so here
180182
if (bundle->getGenDependencies()) {
181-
// Add this file to the dependency file
182-
String8 dependencyFile = outputFile.getBasePath();
183+
// The dependency file gets output to the same directory
184+
// as the specified output file with an additional .d extension.
185+
// e.g. bin/resources.ap_.d
186+
String8 dependencyFile = outputFile;
183187
dependencyFile.append(".d");
184188

185189
FILE* fp = fopen(dependencyFile.string(), "a");
190+
// Add this file to the dependency file
186191
fprintf(fp, "%s \\\n", outputFile.string());
187192
fclose(fp);
188193
}

tools/aapt/Resource.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,10 +1958,12 @@ status_t writeResourceSymbols(Bundle* bundle, const sp<AaptAssets>& assets,
19581958
}
19591959
fclose(fp);
19601960

1961+
// If we were asked to generate a dependency file, we'll go ahead and add this R.java
1962+
// as a target in the dependency file right next to it.
19611963
if (bundle->getGenDependencies()) {
19621964
// Add this R.java to the dependency file
19631965
String8 dependencyFile(bundle->getRClassDir());
1964-
dependencyFile.appendPath("R.d");
1966+
dependencyFile.appendPath("R.java.d");
19651967

19661968
fp = fopen(dependencyFile.string(), "a");
19671969
fprintf(fp,"%s \\\n", dest.string());

0 commit comments

Comments
 (0)