OSDN Git Service

Improve indirect library dependency support.
authorXavier Ducrohet <xav@android.com>
Fri, 14 Oct 2011 23:46:45 +0000 (16:46 -0700)
committerXavier Ducrohet <xav@android.com>
Fri, 14 Oct 2011 23:46:45 +0000 (16:46 -0700)
Previously with the following setup:
    Main app depends on Lib1, Lib2.
    Lib1 and Lib2 both depends on Lib3.
Lib3 would be compiled 3 times, as the main app would attempt
to build it and then Libr1, and Lib2 would do it too.

Of course it wasn't actually built 3 times. After the first time it would
do nothing, checking dependencies and do nothing. However, for projects
will a lot of libraries and a lot of indirect dependencies this could
slow down a lot compilations, as the build would spend its time checking
whether to build the same library many times.

This ensure that only the main project attempts to build all of its library
dependencies (direct and indirect), in the right order of course.
When libraries are built they are told (through the "only" target) to not
build their dependencies.

Change-Id: Ie80f32a96e3c473d897aca5d05bf6fe9ea086884

anttasks/src/com/android/ant/AaptExecTask.java
anttasks/src/com/android/ant/NewSetupTask.java
files/ant/build.xml

index 8731732..c01afe2 100644 (file)
@@ -96,7 +96,7 @@ public final class AaptExecTask extends SingleDependencyTask {
     private boolean mNonConstantId;
 
     /**
-     * Input path that ignores the same file that aapt does.
+     * Input path that ignores the same folders/files that aapt does.
      */
     private static class ResFolderInputPath extends InputPath {
         public ResFolderInputPath(File file, Set<String> extensionsToCheck) {
index 165ea08..46f5b14 100644 (file)
@@ -452,21 +452,20 @@ public class NewSetupTask extends Task {
 
         System.out.println("\n------------------\nResolving library dependencies:");
 
+        // get the list of ordered libraries.
         ArrayList<File> libraries = getProjectLibraries(antProject);
 
         if (libraries.size() > 0) {
             System.out.println("------------------\nOrdered libraries:");
 
+            // use that same order to return ordered res folders, as well as jars and output.
             for (File library : libraries) {
+                // get the root path.
                 String libRootPath = library.getAbsolutePath();
                 System.out.println(libRootPath);
 
-                // get the root path.
-                PathElement element = rootPath.createPathElement();
-                element.setPath(libRootPath);
-
                 // get the res path. Always $PROJECT/res as well as the crunch cache.
-                element = resPath.createPathElement();
+                PathElement element = resPath.createPathElement();
                 element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT +
                         "/" + SdkConstants.FD_RES);
                 element = resPath.createPathElement();
@@ -506,6 +505,18 @@ public class NewSetupTask extends Task {
                     throw new BuildException(e);
                 }
             }
+
+            // now use the reverse order to get the full list of library project.
+            // This is used to compile all the libraries, direct or indirect dependencies,
+            // in a single pass.
+            final int count = libraries.size();
+            for (int i = count - 1 ; i >= 0 ; i--) {
+                File library = libraries.get(i);
+
+                PathElement element = rootPath.createPathElement();
+                element.setPath(library.getAbsolutePath());
+            }
+
         } else {
             System.out.println("No library dependencies.\n");
         }
index 91dbb1f..57effb2 100644 (file)
     <!-- ******************** Build Targets ******************** -->
     <!-- ******************************************************* -->
 
+    <!-- target to disable building dependencies -->
+    <target name="only">
+        <property name="dont.build.deps" value="true" />
+    </target>
+
     <!-- this target simply force running -setup making
          the project info be read. To be used as
              ant all clean
         <!-- compile the libraries if any -->
         <if>
             <condition>
-                <isreference refid="project.libraries" />
+                <and>
+                    <isreference refid="project.libraries" />
+                    <not><isset property="dont.build.deps" /></not>
+                </and>
             </condition>
             <then>
                 <echo>Building Libraries</echo>
-                <subant
+                <subant failonerror="true"
                         buildpathref="project.libraries"
-                        antfile="build.xml"
-                        target="${build.target}"
-                        failonerror="true"/>
+                        antfile="build.xml">
+                    <target name="only" />
+                    <target name="${build.target}" />
+                </subant>
                 <echo></echo>
                 <echo>############################################</echo>
                 <echo>**** Back to project ${ant.project.name} ****</echo>
         <echo>              (tested projects and libraries)at the same time</echo>
         <echo>              using: 'ant all clean'</echo>
         <echo>   debug:     Builds the application and signs it with a debug key.</echo>
+        <echo>              The 'only' target can be used to only build the</echo>
+        <echo>              current project and ignore the libraries using:</echo>
+        <echo>              'ant only debug'</echo>
         <echo>   release:   Builds the application. The generated apk file must be</echo>
         <echo>              signed before it is published.</echo>
+        <echo>              The 'only' target can be used to only build the</echo>
+        <echo>              current project and ignore the libraries using:</echo>
+        <echo>              'ant only release'</echo>
         <echo>   instrument:Builds an instrumented package and signs it with a</echo>
         <echo>              debug key.</echo>
         <echo>   test:      Runs the tests. Project must be a test project and</echo>