Skip to content

Commit f475072

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

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

tools/aapt/Command.cpp

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

13931393
// Set up the resource gathering in assets if we're going to generate
1394-
// dependency files
1394+
// dependency files. Every time we encounter a resource while slurping
1395+
// the tree, we'll add it to these stores so we have full resource paths
1396+
// to write to a dependency file.
13951397
if (bundle->getGenDependencies()) {
13961398
sp<FilePathStore> resPathStore = new FilePathStore;
13971399
assets->setFullResPaths(resPathStore);
@@ -1422,15 +1424,20 @@ int doPackage(Bundle* bundle)
14221424
goto bail;
14231425
}
14241426

1427+
// If we've been asked to generate a dependency file, do that here
14251428
if (bundle->getGenDependencies()) {
1429+
// If this is the packaging step, generate the dependency file next to
1430+
// the output apk (e.g. bin/resources.ap_.d)
14261431
if (outputAPKFile) {
14271432
dependencyFile = String8(outputAPKFile);
1428-
// Strip the extension and add new one
1429-
dependencyFile = dependencyFile.getBasePath();
1433+
// Add the .d extension to the dependency file.
14301434
dependencyFile.append(".d");
14311435
} else {
1436+
// Else if this is the R.java dependency generation step,
1437+
// generate the dependency file in the R.java package subdirectory
1438+
// e.g. gen/com/foo/app/R.java.d
14321439
dependencyFile = String8(bundle->getRClassDir());
1433-
dependencyFile.appendPath("R.d");
1440+
dependencyFile.appendPath("R.java.d");
14341441
}
14351442
// Make sure we have a clean dependency file to start with
14361443
fp = fopen(dependencyFile, "w");
@@ -1440,13 +1447,18 @@ int doPackage(Bundle* bundle)
14401447
// Write out R.java constants
14411448
if (assets->getPackage() == assets->getSymbolsPrivatePackage()) {
14421449
if (bundle->getCustomPackage() == NULL) {
1450+
// Write the R.java file into the appropriate class directory
1451+
// e.g. gen/com/foo/app/R.java
14431452
err = writeResourceSymbols(bundle, assets, assets->getPackage(), true);
1444-
// Copy R.java for libraries
1453+
// If we have library files, we're going to write our R.java file into
1454+
// the appropriate class directory for those libraries as well.
1455+
// e.g. gen/com/foo/app/lib/R.java
14451456
if (bundle->getExtraPackages() != NULL) {
14461457
// Split on colon
14471458
String8 libs(bundle->getExtraPackages());
14481459
char* packageString = strtok(libs.lockBuffer(libs.length()), ":");
14491460
while (packageString != NULL) {
1461+
// Write the R.java file out with the correct package name
14501462
err = writeResourceSymbols(bundle, assets, String8(packageString), true);
14511463
packageString = strtok(NULL, ":");
14521464
}
@@ -1485,14 +1497,19 @@ int doPackage(Bundle* bundle)
14851497
}
14861498
}
14871499

1500+
// If we've been asked to generate a dependency file, we need to finish up here.
1501+
// the writeResourceSymbols and writeAPK functions have already written the target
1502+
// half of the dependency file, now we need to write the prerequisites. (files that
1503+
// the R.java file or .ap_ file depend on)
14881504
if (bundle->getGenDependencies()) {
14891505
// Now that writeResourceSymbols or writeAPK has taken care of writing
14901506
// the targets to our dependency file, we'll write the prereqs
14911507
fp = fopen(dependencyFile, "a+");
14921508
fprintf(fp, " : ");
14931509
bool includeRaw = (outputAPKFile != NULL);
14941510
err = writeDependencyPreReqs(bundle, assets, fp, includeRaw);
1495-
// Also manually add the AndroidManifeset since it's a non-asset
1511+
// Also manually add the AndroidManifeset since it's not under res/ or assets/
1512+
// and therefore was not added to our pathstores during slurping
14961513
fprintf(fp, "%s \\\n", bundle->getAndroidManifestFile());
14971514
fclose(fp);
14981515
}

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
@@ -1890,10 +1890,12 @@ status_t writeResourceSymbols(Bundle* bundle, const sp<AaptAssets>& assets,
18901890
}
18911891
fclose(fp);
18921892

1893+
// If we were asked to generate a dependency file, we'll go ahead and add this R.java
1894+
// as a target in the dependency file right next to it.
18931895
if (bundle->getGenDependencies()) {
18941896
// Add this R.java to the dependency file
18951897
String8 dependencyFile(bundle->getRClassDir());
1896-
dependencyFile.appendPath("R.d");
1898+
dependencyFile.appendPath("R.java.d");
18971899

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

0 commit comments

Comments
 (0)