Bug 1509572 - Part 6: Don't always generate annotations from Gradle. r=snorp
authorNick Alexander <nalexander@mozilla.com>
Mon, 26 Nov 2018 21:44:00 +0000
changeset 504572 8d0de38dc4c80f1382ec80ae8ecb2f0788837be0
parent 504571 d8102b5a209ab02d281b87e351a568be934c7ee6
child 504573 0a2f54a1a5ca4e1a14ed516fe4b7de2bf8d23a05
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1509572
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509572 - Part 6: Don't always generate annotations from Gradle. r=snorp Before, we always ran the "generate JNI wrappers" command and had the command be smart about updating the output. Now we move the smarts to the Gradle side to streamline the build. Differential Revision: https://phabricator.services.mozilla.com/D12795
mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/AnnotationProcessor.java
mobile/android/gradle/with_gecko_binaries.gradle
--- a/mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/AnnotationProcessor.java
+++ b/mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/AnnotationProcessor.java
@@ -165,31 +165,16 @@ public class AnnotationProcessor {
 
     private static String getHeaderGuardName(final String name) {
         return name.replaceAll("\\W", "_");
     }
 
     private static int writeOutputFile(final String name, final StringBuilder content) {
         final byte[] contentBytes = content.toString().getBytes(StandardCharsets.UTF_8);
 
-        try {
-            final byte[] existingBytes = Files.readAllBytes(new File(name).toPath());
-            if (Arrays.equals(contentBytes, existingBytes)) {
-                return 0;
-            }
-        } catch (FileNotFoundException e) {
-            // Pass.
-        } catch (NoSuchFileException e) {
-            // Pass.
-        } catch (IOException e) {
-            System.err.println("Unable to read " + name + ". Perhaps a permissions issue?");
-            e.printStackTrace(System.err);
-            return 1;
-        }
-
         try (FileOutputStream outStream = new FileOutputStream(name)) {
             outStream.write(contentBytes);
         } catch (IOException e) {
             System.err.println("Unable to write " + name + ". Perhaps a permissions issue?");
             e.printStackTrace(System.err);
             return 1;
         }
 
--- a/mobile/android/gradle/with_gecko_binaries.gradle
+++ b/mobile/android/gradle/with_gecko_binaries.gradle
@@ -110,17 +110,17 @@ ext.configureLibraryVariantWithJNIWrappe
     //
     // It's not really possible to insert something immediately _after_
     // ...WithPrepareIntermediateJars..., so we make the consuming moz.build
     // system invoke this target directly, and force the
     // ...WithPrepareIntermediateJars... dependency.  The real consumer of the
     // JNI wrappers is the moz.build system, which always builds geckoview to
     // consume from Fennec, so that dependency likely adds less to the build time.
     def jarTask = tasks["transformClassesAndResourcesWithPrepareIntermediateJarsFor${variant.name.capitalize()}"]
-    def output = jarTask.outputs.files.find({ it.absolutePath.contains('/classes.jar') })
+    def bundleJar = jarTask.outputs.files.find({ it.absolutePath.contains('/classes.jar') })
 
     def annotationProcessorsJarTask = project(':annotations').jar
 
     def wrapperTask
     if (System.env.IS_LANGUAGE_REPACK == '1') {
         // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
         // really have a build environment.
         wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
@@ -133,35 +133,43 @@ ext.configureLibraryVariantWithJNIWrappe
             doFirst {
                 classpath variant.javaCompile.classpath
                 // Include android.jar.
                 classpath variant.javaCompile.options.bootClasspath
             }
     
             main = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
             args module
-            args output
+            args bundleJar
             
             workingDir "${topobjdir}/widget/android"
-            
+
+            inputs.file(bundleJar)
+            inputs.file(annotationProcessorsJarTask.archivePath)
+            inputs.property("module", module)
+
+            outputs.file("${topobjdir}/widget/android/GeneratedJNINatives.h")
+            outputs.file("${topobjdir}/widget/android/GeneratedJNIWrappers.cpp")
+            outputs.file("${topobjdir}/widget/android/GeneratedJNIWrappers.h")
+
             dependsOn jarTask
             dependsOn annotationProcessorsJarTask
         }
     }
 
     if (module == 'Generated') {
         tasks["bundle${variant.name.capitalize()}"].dependsOn wrapperTask
     } else {
         tasks["assemble${variant.name.capitalize()}"].dependsOn wrapperTask
     }
 }
 
 ext.configureApplicationVariantWithJNIWrappers = { variant, module ->
     def jarTask = tasks["bundleAppClasses${variant.name.capitalize()}"]
-    def output = jarTask.outputs.files.find({ it.absolutePath.contains('/classes.jar') })
+    def bundleJar = jarTask.outputs.files.find({ it.absolutePath.contains('/classes.jar') })
 
     def annotationProcessorsJarTask = project(':annotations').jar
 
     def wrapperTask
     if (System.env.IS_LANGUAGE_REPACK == '1') {
         // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
         // really have a build environment.
         wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
@@ -174,19 +182,27 @@ ext.configureApplicationVariantWithJNIWr
             doFirst {
                 classpath variant.javaCompile.classpath
                 // Include android.jar.
                 classpath variant.javaCompile.options.bootClasspath
             }
         
             main = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
             args module
-            args output
+            args bundleJar
         
             workingDir "${topobjdir}/widget/android/fennec"
-    
+
+            inputs.file(bundleJar)
+            inputs.file(annotationProcessorsJarTask.archivePath)
+            inputs.property("module", module)
+
+            outputs.file("${topobjdir}/widget/android/fennec/FennecJNINatives.h")
+            outputs.file("${topobjdir}/widget/android/fennec/FennecJNIWrappers.cpp")
+            outputs.file("${topobjdir}/widget/android/fennec/FennecJNIWrappers.h")
+
             // This forces bundling, which isn't usually part of the assemble* process.
             dependsOn jarTask
 
             dependsOn annotationProcessorsJarTask
         }
     }
 }