From 8c0bb5ea1702ba4f31a35cbf7c82b3be3a0a933a Mon Sep 17 00:00:00 2001 From: Josiah Gaskin Date: Fri, 24 Jun 2011 14:58:32 -0700 Subject: Add support to Ant for packaging dependency checks This change adds in support for making aapt generate a dependency file for the .ap_ package generated during resource packaging. Ant will then check this dependency file before calling aapt again and will only repackage resources if the dependencies have been modified in some way. Change-Id: I56462163c5dd064c1416bc43913f044df8ee9be1 --- anttasks/src/com/android/ant/AaptExecLoopTask.java | 68 +++++++++++++++------- 1 file changed, 46 insertions(+), 22 deletions(-) (limited to 'anttasks') diff --git a/anttasks/src/com/android/ant/AaptExecLoopTask.java b/anttasks/src/com/android/ant/AaptExecLoopTask.java index ed0277a..aac61b1 100644 --- a/anttasks/src/com/android/ant/AaptExecLoopTask.java +++ b/anttasks/src/com/android/ant/AaptExecLoopTask.java @@ -282,34 +282,57 @@ public final class AaptExecLoopTask extends BaseTask { // Get whether we have libraries Object libResRef = taskProject.getReference(AntConstants.PROP_PROJECT_LIBS_RES_REF); - if (generateRClass) { - // If the only reason we're here is to generate R.java and that doesn't need updating - // we can skip what comes next. First we grab the dependency file. - // Then query to see if an update is needed. - ArrayList watchPaths = new ArrayList(); - // We need to watch for changes in the main project res folder - for (Path pathList : mResources) { - for (String path : pathList.list()) { - watchPaths.add(new File(path)); - } + // Set up our folders to check for changed files + ArrayList watchPaths = new ArrayList(); + // We need to watch for changes in the main project res folder + for (Path pathList : mResources) { + for (String path : pathList.list()) { + watchPaths.add(new File(path)); } - // and if libraries exist, in their res folders - if (libResRef instanceof Path) { - for (String path : ((Path)libResRef).list()) { - watchPaths.add(new File(path)); - } + } + // and if libraries exist, in their res folders + if (libResRef instanceof Path) { + for (String path : ((Path)libResRef).list()) { + watchPaths.add(new File(path)); + } + } + // If we're here to generate a .ap_ file we need to watch assets as well + if (!generateRClass) { + File assetsDir = new File(mAssets); + if (mAssets != null && assetsDir.isDirectory()) { + watchPaths.add(assetsDir); } + } + + // Now we figure out what we need to do + if (generateRClass) { + // Check to see if our dependencies have changed. If not, then skip if (initDependencies(mRFolder + File.separator + "R.d", watchPaths) && dependenciesHaveChanged() == false) { System.out.println("No changed resources. R.java and Manifest.java untouched."); return; } - } else if (mResourceFilter == null) { - System.out.println("Creating full resource package..."); } else { - System.out.println(String.format( - "Creating resource package with filter: (%1$s)...", - mResourceFilter)); + // Find our dependency file. It should have the same name as our target .ap_ but + // with a .d extension + String dependencyFilePath = mApkFolder + File.separator + mApkName; + dependencyFilePath = + dependencyFilePath.substring(0, dependencyFilePath.lastIndexOf(".")) + ".d"; + + // Check to see if our dependencies have changed + if (initDependencies(dependencyFilePath , watchPaths) + && dependenciesHaveChanged() == false) { + System.out.println("No changed resources or assets. " + dependencyFilePath + + " remains untouched"); + return; + } + if (mResourceFilter == null) { + System.out.println("Creating full resource package..."); + } else { + System.out.println(String.format( + "Creating resource package with filter: (%1$s)...", + mResourceFilter)); + } } // create a task for the default apk. @@ -441,10 +464,11 @@ public final class AaptExecLoopTask extends BaseTask { if (generateRClass) { task.createArg().setValue("-J"); task.createArg().setValue(mRFolder); - // Use dependency generation - task.createArg().setValue("--generate-dependencies"); } + // Use dependency generation + task.createArg().setValue("--generate-dependencies"); + // final setup of the task task.setProject(taskProject); task.setOwningTarget(getOwningTarget()); -- cgit v1.1