Bug 1509572 - Part 6: Don't always generate annotations from Gradle. r=snorp
☠☠ backed out by 79ae8ec996e6 ☠ ☠
authorNick Alexander <nalexander@mozilla.com>
Mon, 26 Nov 2018 21:02:52 +0000
changeset 507336 9f6a7e664cef95703e629aa3fd02cd6a5b014f54
parent 507335 f6653c7d29671c942662c75945ae4f82ef21a31d
child 507337 089d689d8eb5ed58ab0014858cdb44b15b7ff34d
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [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. Depends on D12794 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
         }
     }
 }