changeset 5857:2c0a00f8de4a

RT-31360: Gradle build system doesn't do partial build if native code is changed
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Sun, 01 Dec 2013 10:25:59 -0800
parents e5cbd989d3ea
children 207d6d1ca9a3
files build.gradle buildSrc/src/main/groovy/com/sun/javafx/gradle/NativeCompileTask.groovy
diffstat 2 files changed, 61 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/build.gradle	Sun Dec 01 12:14:21 2013 +0200
+++ b/build.gradle	Sun Dec 01 10:25:59 2013 -0800
@@ -1145,6 +1145,11 @@
         task generateD3DHeaders(group: "Build") {
             enabled = IS_WINDOWS
             dependsOn javahWinPrismD3D
+            inputs.file "src/main/native-prism-d3d/hlsl/Mtl1PS.hlsl"
+            inputs.file "src/main/native-prism-d3d/hlsl/Mtl1VS.hlsl"
+            inputs.file "src/main/native-prism-d3d/PassThroughVS.hlsl"
+            outputs.dir "$buildDir/headers/PrismD3D/"
+            outputs.dir "$buildDir/headers/PrismD3D/hlsl/"
             description = "Generate headers by compiling hlsl files"
             doLast {
                 mkdir file("$buildDir/headers/PrismD3D/hlsl")
--- a/buildSrc/src/main/groovy/com/sun/javafx/gradle/NativeCompileTask.groovy	Sun Dec 01 12:14:21 2013 +0200
+++ b/buildSrc/src/main/groovy/com/sun/javafx/gradle/NativeCompileTask.groovy	Sun Dec 01 10:25:59 2013 -0800
@@ -42,13 +42,9 @@
     List<String> params = new ArrayList<String>();
     List sourceRoots = new ArrayList();
     @OutputDirectory File output;
+    @InputFiles List<File> allFiles = [];
     private final PatternFilterable patternSet = new PatternSet();
 
-    @InputFiles public void setSource(Object source) {
-        sourceRoots.clear();
-        sourceRoots.add(source);
-    }
-
     public NativeCompileTask source(Object... sources) {
         for (Object source : sources) {
             if (source instanceof Collection) {
@@ -57,6 +53,7 @@
                 sourceRoots.add(source);
             }
         }
+        updateFiles();
         return this;
     }
 
@@ -70,6 +67,17 @@
         return this;
     }
 
+    private void updateFiles() {
+        // Combine the different source roots into a single List<File> based on all files in each source root
+        allFiles.clear();
+        sourceRoots.each {
+            def file = project.file(it);
+            if (file && file.exists()) {
+                allFiles += file.isDirectory() ? file.listFiles() : file;
+            }
+        }
+    }
+
     @TaskAction void compile() {
         // Get the existing native-dependencies file from build/dependency-cache and load its contents into
         // memory. If the file doesn't exist, then we will just have an empty dependency map.
@@ -87,17 +95,50 @@
         }
 
         project.mkdir(output);
-        // Combine the different source roots into a single FileCollection based on all files in each source root
-        def allFiles = [];
-        sourceRoots.each {
-            def dir = project.file(it);
-            allFiles += dir.isDirectory() ? dir.listFiles() : dir;
+
+        // Recompute the allFiles list as the input can come from auto-generated
+        // content (HSLS files, for example) which might have changed since
+        // the task was configured (i.e. when source() was called).
+        updateFiles();
+        def source = project.files(allFiles);
+        boolean forceCompile = false;
+        final Set<File> files = new HashSet<File>();
+        source.each { File file ->
+            final Map fileData = dependencies.get(file.toString());
+            final boolean isModified = fileData == null ||
+                                       !fileData["DATE"].equals(file.lastModified()) ||
+                                       !fileData["SIZE"].equals(file.length());
+
+            if (matches == null || file.name.matches(matches)) {
+                // If the source file is not listed in dependencies, then we must compile it.
+                // If the target file(s) (.rc or .cur in the case of resources, .pdb or .obj for sources)
+                //    do not exist, then compile.
+                // If the source file date or size differs from dependencies, then compile it.
+                if (isModified) {
+                    files += file;
+                } else {
+                    final File outputFile = outputFile(file);
+                    if (!outputFile.exists()) {
+                        files += file;
+                    }
+                }
+            } else {
+                // This file can be header file or some other type of resource file.
+                // Force all source files to be compile.
+                if (isModified) {
+                    forceCompile = true;
+                    //let the iterator finish to update dependencies map
+                }
+            }
+            if (isModified) {
+                dependencies.put(file.toString(), ["DATE":file.lastModified(), "SIZE":file.length()]);
+            }
         }
-        def source = project.files(allFiles);
-        final Set<File> files = matches == null ? new HashSet<File>(source.files) : source.filter{it.name.matches(matches)}.files;
+        if (forceCompile) {
+            files +=  matches == null ? source.files : source.filter{it.name.matches(matches)}.files;
+        }
+
         project.logger.info("Compiling native files: $files");
-        boolean shouldCompileAnyway = false;
-        final boolean forceCompile = shouldCompileAnyway;
         final ExecutorService executor = Executors.newFixedThreadPool(Integer.parseInt(project.NUM_COMPILE_THREADS.toString()));
         final CountDownLatch latch = new CountDownLatch(files.size());
         List futures = new ArrayList<Future>();
@@ -106,18 +147,7 @@
                 @Override public void run() {
                     try {
                         final File outputFile = outputFile(sourceFile);
-                        // If the source file is not listed in dependencies, then we must compile it.
-                        // If the target file(s) (.rc or .cur in the case of resources, .pdb or .obj for sources)
-                        //    do not exist, then compile.
-                        // If the source file date or size differs from dependencies, then compile it.
-                        final Map sourceFileData = dependencies.get(sourceFile.toString());
-                        if (forceCompile || sourceFileData == null || !outputFile.exists() ||
-                                !sourceFileData["DATE"].equals(sourceFile.lastModified()) ||
-                                !sourceFileData["SIZE"].equals(sourceFile.length()))
-                        {
-                            doCompile(sourceFile, outputFile)
-                        }
-                        dependencies.put(sourceFile.toString(), ["DATE":sourceFile.lastModified(), "SIZE":sourceFile.length()]);
+                        doCompile(sourceFile, outputFile)
                     } finally {
                         latch.countDown();
                     }