diff options
author | Xavier Ducrohet <xav@android.com> | 2011-09-01 17:45:06 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-09-01 18:00:43 -0700 |
commit | 0fd7983848915b9424501afee8d8f0ea6f08f858 (patch) | |
tree | c05f5200248592de0d06cd71ae5c28c79ec9f274 /anttasks | |
parent | 4f033cc9ca1b81ce8d2a7ea4bd448cbd40c3bcbc (diff) | |
download | sdk-0fd7983848915b9424501afee8d8f0ea6f08f858.zip sdk-0fd7983848915b9424501afee8d8f0ea6f08f858.tar.gz sdk-0fd7983848915b9424501afee8d8f0ea6f08f858.tar.bz2 |
Make the dependency graph use extension restrictions per folder.
Before there was a way to filter touched file by extension(s) but
this was for all input folders.
Now each input folder can have a different set of extension restrictions.
This will allow apkbuilder to use DependencyGraph and extension restriction
for all its input folders.
Also fixed an issue where aapt would not package the resources if an
xml files was touched. This is because it didn't make a difference
between compiling the resources for IDs and packaging the resource
values.
Change-Id: I797d3a24c6c1f999e9d412c4ff8aa826ed16fc09
Diffstat (limited to 'anttasks')
-rw-r--r-- | anttasks/src/com/android/ant/AaptExecTask.java | 22 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/AidlExecTask.java | 3 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/BaseTask.java | 35 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/DependencyGraph.java | 71 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/DexExecTask.java | 15 |
5 files changed, 94 insertions, 52 deletions
diff --git a/anttasks/src/com/android/ant/AaptExecTask.java b/anttasks/src/com/android/ant/AaptExecTask.java index 2c242d3..4d16d1f 100644 --- a/anttasks/src/com/android/ant/AaptExecTask.java +++ b/anttasks/src/com/android/ant/AaptExecTask.java @@ -16,6 +16,8 @@ package com.android.ant; +import com.android.ant.DependencyGraph.InputPath; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.ExecTask; @@ -23,6 +25,8 @@ import org.apache.tools.ant.types.Path; import java.io.File; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * Task to execute aapt. @@ -324,24 +328,24 @@ public final class AaptExecTask extends BaseTask { Object libResRef = taskProject.getReference(mProjectLibrariesResName); // Set up our input paths that matter for dependency checks - ArrayList<File> inputPaths = new ArrayList<File>(); + ArrayList<File> paths = new ArrayList<File>(); // the project res folder is an input path of course for (Path pathList : mResources) { for (String path : pathList.list()) { - inputPaths.add(new File(path)); + paths.add(new File(path)); } } // as is its AndroidManifest.xml if (mManifest != null) { - inputPaths.add(new File(mManifest)); + paths.add(new File(mManifest)); } // and if libraries exist, their res folders folders too. if (libResRef instanceof Path) { for (String path : ((Path)libResRef).list()) { - inputPaths.add(new File(path)); + paths.add(new File(path)); } } @@ -349,12 +353,16 @@ public final class AaptExecTask extends BaseTask { if (!generateRClass) { File assetsDir = new File(mAssets); if (mAssets != null && assetsDir.isDirectory()) { - inputPaths.add(assetsDir); + paths.add(assetsDir); } } // Now we figure out what we need to do if (generateRClass) { + // in this case we only want to run aapt if an XML file was touched, or if any + // file is added/removed + List<InputPath> inputPaths = getInputPaths(paths, Collections.singleton("xml")); + // Check to see if our dependencies have changed. If not, then skip if (initDependencies(mRFolder + File.separator + "R.java.d", inputPaths) && dependenciesHaveChanged() == false) { @@ -364,6 +372,10 @@ public final class AaptExecTask extends BaseTask { System.out.println("Generating resource IDs..."); } } else { + // in this case we want to run aapt if any file updated/removed/added in any of the + // input path + List<InputPath> inputPaths = getInputPaths(paths, null /*extensionsToCheck*/); + // 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; diff --git a/anttasks/src/com/android/ant/AidlExecTask.java b/anttasks/src/com/android/ant/AidlExecTask.java index 1fd5a61..ab01c71 100644 --- a/anttasks/src/com/android/ant/AidlExecTask.java +++ b/anttasks/src/com/android/ant/AidlExecTask.java @@ -130,8 +130,7 @@ public class AidlExecTask extends Task { // also need to remove the dep file. depsToRemove.add(depFile); - } else if (graph.dependenciesHaveChanged(null /*extensionsToCheck*/, - false /*printStatus*/)) { + } else if (graph.dependenciesHaveChanged(false /*printStatus*/)) { // need to recompile! toCompile.add(sourceFilePath); } diff --git a/anttasks/src/com/android/ant/BaseTask.java b/anttasks/src/com/android/ant/BaseTask.java index 4eb954b..8a82fe9 100644 --- a/anttasks/src/com/android/ant/BaseTask.java +++ b/anttasks/src/com/android/ant/BaseTask.java @@ -16,13 +16,15 @@ package com.android.ant; +import com.android.ant.DependencyGraph.InputPath; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; -import java.util.HashSet; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -45,20 +47,24 @@ public abstract class BaseTask extends Task { protected abstract String getExecTaskName(); - private Set<String> mRestrictTouchedExtensionsTo; - /** - * Sets the value of the "restricttouchedextensionsto" attribute. - * @param touchedExtensions the extensions to check to see if they have been modified. - * values should be separated by a colon (:). If left blank or not set, all extensions - * will be checked. + * Creates a list of {@link InputPath} from a list of {@link File} and an optional list of + * extensions. All the {@link InputPath} will share the same extension restrictions. + * @param paths the list of path + * @param extensionsToCheck A set of extensions. Only files with an extension in this set will + * be considered for a modification check. All deleted/created files will still be + * checked. If this is null, all files will be checked for modification date + * @return a list of {@link InputPath} */ - public void setRestrictTouchedExtensionsTo(String restrictTouchedExtensionsTo) { - mRestrictTouchedExtensionsTo = new HashSet<String>(); - String[] extensions = restrictTouchedExtensionsTo.split(":"); - for (String s : extensions) { - mRestrictTouchedExtensionsTo.add(s); + protected static List<InputPath> getInputPaths(List<File> paths, + Set<String> extensionsToCheck) { + List<InputPath> result = new ArrayList<InputPath>(paths.size()); + + for (File f : paths) { + result.add(new InputPath(f, extensionsToCheck)); } + + return result; } /** @@ -68,7 +74,7 @@ public abstract class BaseTask extends Task { * @param the new input paths for this new compilation. * @return true if the dependency graph was successfully initialized */ - protected boolean initDependencies(String dependencyFile, List<File> inputPaths) { + protected boolean initDependencies(String dependencyFile, List<InputPath> inputPaths) { if (mBuildType != null && mBuildType.equals(mPreviousBuildType) == false) { // we don't care about deps, we need to execute the task no matter what. return true; @@ -103,8 +109,7 @@ public abstract class BaseTask extends Task { } assert mDependencies != null : "Dependencies have not been initialized"; - return mDependencies.dependenciesHaveChanged(mRestrictTouchedExtensionsTo, - true /*printStatus*/); + return mDependencies.dependenciesHaveChanged(true /*printStatus*/); } protected void generateDependencyFile(String depFilePath, diff --git a/anttasks/src/com/android/ant/DependencyGraph.java b/anttasks/src/com/android/ant/DependencyGraph.java index 7f9c65a..b51965d 100644 --- a/anttasks/src/com/android/ant/DependencyGraph.java +++ b/anttasks/src/com/android/ant/DependencyGraph.java @@ -45,23 +45,37 @@ public class DependencyGraph { private File mFirstPrereq = null; private boolean mMissingDepFile = false; private long mDepFileLastModified; - private final List<File> mNewInputs; + private final List<InputPath> mNewInputs; + + public static class InputPath { + File mFile; + /** + * A set of extensions. Only files with an extension in this set will + * be considered for a modification check. All deleted/created files will still be + * checked. If this is null, all files will be checked for modification date + */ + Set<String> mExtensionsToCheck; + + public InputPath(File file, Set<String> extensions) { + mFile = file; + mExtensionsToCheck = extensions; + } + } + - public DependencyGraph(String dependencyFilePath, List<File> newInputPaths) { + public DependencyGraph(String dependencyFilePath, List<InputPath> newInputPaths) { mNewInputs = newInputPaths; parseDependencyFile(dependencyFilePath); } /** * Check all the dependencies to see if anything has changed. - * @param extensionsToCheck a set of extensions. Only files with an extension in this set will - * be considered for a modification check. All deleted/created files will still be - * checked. If this is null, all files will be checked for modification date + * * @param printStatus will print to {@link System#out} the dependencies status. * @return true if new prerequisites have appeared, target files are missing or if * prerequisite files have been modified since the last target generation. */ - public boolean dependenciesHaveChanged(Set<String> extensionsToCheck, boolean printStatus) { + public boolean dependenciesHaveChanged(boolean printStatus) { // If no dependency file has been set up, then we'll just return true // if we have a dependency file, we'll check to see what's been changed if (mMissingDepFile) { @@ -77,11 +91,11 @@ public class DependencyGraph { return true; } - // get the timestamp of the oldest target. + // get the time stamp of the oldest target. long oldestTarget = getOutputLastModified(); // first look through the input folders and look for new files or modified files. - DependencyStatus status = checkInputs(extensionsToCheck, oldestTarget); + DependencyStatus status = checkInputs(oldestTarget); // this can't find missing files. This is done later. switch (status) { @@ -100,7 +114,7 @@ public class DependencyGraph { } // now do a full check on the remaining files. - status = checkPrereqFiles(extensionsToCheck, oldestTarget); + status = checkPrereqFiles(oldestTarget); // this can't find new input files. This is done above. switch (status) { case ERROR: @@ -214,26 +228,23 @@ public class DependencyGraph { * If a change is found, this will return immediatly with either * {@link DependencyStatus#NEW_FILE} or {@link DependencyStatus#UPDATED_FILE}. * - * @param extensionsToCheck a set of extensions. Only files with an extension in this set will - * be considered for a modification check. All deleted/created files will still be - * checked. If this is null, all files will be checked for modification date * @param oldestTarget the timestamp of the oldest output file to compare against. * * @return the status of the file in the watched folders. * */ - private DependencyStatus checkInputs(Set<String> extensionsToCheck, long oldestTarget) { + private DependencyStatus checkInputs(long oldestTarget) { if (mNewInputs != null) { - for (File input : mNewInputs) { - if (input.isDirectory()) { - DependencyStatus status = checkInputFolder(input, extensionsToCheck, - oldestTarget); + for (InputPath input : mNewInputs) { + if (input.mFile.isDirectory()) { + DependencyStatus status = checkInputFolder(input.mFile, + input.mExtensionsToCheck, oldestTarget); if (status != DependencyStatus.NONE) { return status; } - } else if (input.isFile()) { - DependencyStatus status = checkInputFile(input, extensionsToCheck, - oldestTarget); + } else if (input.mFile.isFile()) { + DependencyStatus status = checkInputFile(input.mFile, + input.mExtensionsToCheck, oldestTarget); if (status != DependencyStatus.NONE) { return status; } @@ -253,7 +264,7 @@ public class DependencyGraph { * @param extensionsToCheck a set of extensions. Only files with an extension in this set will * be considered for a modification check. All deleted/created files will still be * checked. If this is null, all files will be checked for modification date - * @param oldestTarget the timestamp of the oldest output file to compare against. + * @param oldestTarget the time stamp of the oldest output file to compare against. * * @return the status of the file in the folder. */ @@ -308,13 +319,11 @@ public class DependencyGraph { * Check all the prereq files we know about to make sure they're still there, or that they * haven't been modified since the last build. * - * @param extensionsToCheck a set of extensions. Only files with an extension in this set will - * be considered for a modification check. All deleted/created files will still be - * checked. If this is null, all files will be checked for modification date + * @param oldestTarget the time stamp of the oldest output file to compare against. * * @return the status of the files */ - private DependencyStatus checkPrereqFiles(Set<String> extensionsToCheck, long oldestTarget) { + private DependencyStatus checkPrereqFiles(long oldestTarget) { // Loop through our prereq files and make sure they still exist for (File prereq : mPrereqs) { if (prereq.exists() == false) { @@ -323,6 +332,18 @@ public class DependencyGraph { // check the time stamp on this file if it's a file we care about based on the // list of extensions to check. + // to get the extensions to check, we look in which input folder this file is. + Set<String> extensionsToCheck = null; + if (mNewInputs != null) { + String filePath = prereq.getAbsolutePath(); + for (InputPath input : mNewInputs) { + if (filePath.startsWith(input.mFile.getAbsolutePath())) { + extensionsToCheck = input.mExtensionsToCheck; + break; + } + } + } + if (extensionsToCheck == null || extensionsToCheck.contains(getExtension(prereq))) { if (prereq.lastModified() > oldestTarget) { return DependencyStatus.UPDATED_FILE; diff --git a/anttasks/src/com/android/ant/DexExecTask.java b/anttasks/src/com/android/ant/DexExecTask.java index 182ef84..e4296b2 100644 --- a/anttasks/src/com/android/ant/DexExecTask.java +++ b/anttasks/src/com/android/ant/DexExecTask.java @@ -16,6 +16,8 @@ package com.android.ant; +import com.android.ant.DependencyGraph.InputPath; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.ExecTask; import org.apache.tools.ant.types.FileSet; @@ -106,11 +108,11 @@ public class DexExecTask extends BaseTask { public void execute() throws BuildException { // get all input paths - List<File> inputPaths = new ArrayList<File>(); + List<File> paths = new ArrayList<File>(); if (mPathInputs != null) { for (Path pathList : mPathInputs) { for (String path : pathList.list()) { - inputPaths.add(new File(path)); + paths.add(new File(path)); } } } @@ -120,7 +122,7 @@ public class DexExecTask extends BaseTask { Iterator<?> iter = fs.iterator(); while (iter.hasNext()) { FileResource fr = (FileResource) iter.next(); - inputPaths.add(fr.getFile()); + paths.add(fr.getFile()); } } } @@ -128,6 +130,9 @@ public class DexExecTask extends BaseTask { // figure out the path to the dependency file. String depFile = mOutput + ".d"; + // get InputPath with no extension restrictions + List<InputPath> inputPaths = getInputPaths(paths, null /*extensionsToCheck*/); + if (initDependencies(depFile, inputPaths) && dependenciesHaveChanged() == false) { System.out.println( "No new compiled code. No need to convert bytecode to dalvik format."); @@ -158,7 +163,7 @@ public class DexExecTask extends BaseTask { task.createArg().setValue(mOutput); - for (File f :inputPaths) { + for (File f :paths) { task.createArg().setValue(f.getAbsolutePath()); } @@ -166,7 +171,7 @@ public class DexExecTask extends BaseTask { task.execute(); // generate the dependency file. - generateDependencyFile(depFile, inputPaths, mOutput); + generateDependencyFile(depFile, paths, mOutput); } @Override |