Bug 1291375 - 2. Let AnnotationProcessor generate multiple sets of bindings; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 16 Sep 2016 15:13:47 -0400
changeset 414603 3d98d13567fcab822f2da7fd71a9148290a1d641
parent 414602 797a4dbc48d82b47e03a818bbc14a12e75daddda
child 414604 9e9c3d6cb11bca002bc455d09c99594285bda241
push id29721
push userbmo:mstange@themasta.com
push dateFri, 16 Sep 2016 20:54:58 +0000
reviewerssnorp
bugs1291375
milestone51.0a1
Bug 1291375 - 2. Let AnnotationProcessor generate multiple sets of bindings; r=snorp Let AnnotationProcessor accept an output prefix argument, so that we can generate two different sets of bindings for different jars - one set for GeckoView code and one set for Fennec code.
build/annotationProcessors/AnnotationProcessor.java
--- a/build/annotationProcessors/AnnotationProcessor.java
+++ b/build/annotationProcessors/AnnotationProcessor.java
@@ -10,74 +10,76 @@ import org.mozilla.gecko.annotationProce
 import org.mozilla.gecko.annotationProcessors.utils.GeneratableElementIterator;
 
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Iterator;
 
 public class AnnotationProcessor {
-    public static final String SOURCE_FILE = "GeneratedJNIWrappers.cpp";
-    public static final String HEADER_FILE = "GeneratedJNIWrappers.h";
-    public static final String NATIVES_FILE = "GeneratedJNINatives.h";
-
     public static final String GENERATED_COMMENT =
             "// GENERATED CODE\n" +
             "// Generated by the Java program at /build/annotationProcessors at compile time\n" +
             "// from annotations on Java methods. To update, change the annotations on the\n" +
             "// corresponding Java methods and rerun the build. Manually updating this file\n" +
             "// will cause your build to fail.\n" +
             "\n";
 
     private static final StringBuilder headerFile = new StringBuilder(GENERATED_COMMENT);
     private static final StringBuilder implementationFile = new StringBuilder(GENERATED_COMMENT);
     private static final StringBuilder nativesFile = new StringBuilder(GENERATED_COMMENT);
 
     public static void main(String[] args) {
         // We expect a list of jars on the commandline. If missing, whinge about it.
-        if (args.length <= 1) {
-            System.err.println("Usage: java AnnotationProcessor jarfiles ...");
+        if (args.length <= 2) {
+            System.err.println("Usage: java AnnotationProcessor outprefix jarfiles ...");
             System.exit(1);
         }
 
+        final String OUTPUT_PREFIX = args[0];
+        final String SOURCE_FILE = OUTPUT_PREFIX + "JNIWrappers.cpp";
+        final String HEADER_FILE = OUTPUT_PREFIX + "JNIWrappers.h";
+        final String NATIVES_FILE = OUTPUT_PREFIX + "JNINatives.h";
+
         System.out.println("Processing annotations...");
 
         // We want to produce the same output as last time as often as possible. Ordering of
         // generated statements, therefore, needs to be consistent.
-        Arrays.sort(args);
+        final String[] jars = Arrays.copyOfRange(args, 1, args.length);
+        Arrays.sort(jars);
 
         // Start the clock!
         long s = System.currentTimeMillis();
 
         // Get an iterator over the classes in the jar files given...
-        Iterator<ClassWithOptions> jarClassIterator = IterableJarLoadingURLClassLoader.getIteratorOverJars(args);
+        Iterator<ClassWithOptions> jarClassIterator = IterableJarLoadingURLClassLoader.getIteratorOverJars(jars);
 
         headerFile.append(
                 "#ifndef " + getHeaderGuardName(HEADER_FILE) + "\n" +
                 "#define " + getHeaderGuardName(HEADER_FILE) + "\n" +
                 "\n" +
                 "#include \"mozilla/jni/Refs.h\"\n" +
                 "\n" +
                 "namespace mozilla {\n" +
                 "namespace java {\n" +
                 "\n");
 
         implementationFile.append(
-                "#include \"GeneratedJNIWrappers.h\"\n" +
+                "#include \"" + HEADER_FILE + "\"\n" +
                 "#include \"mozilla/jni/Accessors.h\"\n" +
                 "\n" +
                 "namespace mozilla {\n" +
                 "namespace java {\n" +
                 "\n");
 
         nativesFile.append(
                 "#ifndef " + getHeaderGuardName(NATIVES_FILE) + "\n" +
                 "#define " + getHeaderGuardName(NATIVES_FILE) + "\n" +
                 "\n" +
-                "#include \"GeneratedJNIWrappers.h\"\n" +
+                "#include \"" + HEADER_FILE + "\"\n" +
                 "#include \"mozilla/jni/Natives.h\"\n" +
                 "\n" +
                 "namespace mozilla {\n" +
                 "namespace java {\n" +
                 "\n");
 
         while (jarClassIterator.hasNext()) {
             generateClass(jarClassIterator.next());