Bug 1378410 - 2. Preprocess generated bindings; r=nalexander draft
authorJim Chen <nchen@mozilla.com>
Fri, 01 Sep 2017 14:02:44 -0400
changeset 657616 3a1769e4b45bab3175b3609d08e53534380facce
parent 657615 5cfe8080ec333a1eca70cd3edba2aaaff6406820
child 657617 55b65c665263723e5d34560099e1c9d7044b981f
push id77575
push userbmo:nchen@mozilla.com
push dateFri, 01 Sep 2017 18:04:14 +0000
reviewersnalexander
bugs1378410
milestone57.0a1
Bug 1378410 - 2. Preprocess generated bindings; r=nalexander Preprocess the generated bindings to support the new BuildFlag annotation, so that we can compare bindings despite build flag changes. The build system preprocessor is used because it's easy-to-use and invoking the actual C++ preprocessor would require much more work. However, as a result, we use a MOZ_PREPROCESSOR macro to make the build system preprocessor not handle `#include` lines in the binding files. MozReview-Commit-ID: 3Gweuwnb1V3
mobile/android/base/Makefile.in
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -496,17 +496,17 @@ update-generated-wrappers:
 	@echo Updated generated JNI code
 
 update-fennec-wrappers:
 	@cp $(CURDIR)/FennecJNIWrappers.cpp \
 	    $(CURDIR)/FennecJNIWrappers.h \
 	    $(CURDIR)/FennecJNINatives.h $(topsrcdir)/widget/android/fennec
 	@echo Updated Fennec JNI code
 
-.PHONY: update-generated-wrappers
+.PHONY: update-generated-wrappers update-fennec-wrappers
 
 # This target is only used by IDE integrations. It rebuilds resources
 # that end up in omni.ja using the equivalent of |mach build faster|,
 # does most of the packaging step, and then updates omni.ja in
 # place. If you're not using an IDE, you should be using |mach build
 # mobile/android && mach package|.
 $(ABS_DIST)/fennec/$(OMNIJAR_NAME): FORCE
 	$(REPORT_BUILD)
@@ -532,34 +532,56 @@ endif
 
 .PHONY: gradle-targets gradle-omnijar
 
 # GeneratedJNIWrappers.cpp target also generates
 #   GeneratedJNIWrappers.h and GeneratedJNINatives.h
 # FennecJNIWrappers.cpp target also generates
 #   FennecJNIWrappers.h and FennecJNINatives.h
 ifndef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
+
+# List of build flags used by auto-generated JNI bindings (through the
+# @BuildFlag annotation in Java). For example, add a "MOZ_FOO \" line to this
+# list to support @BuildFlag(MOZ_FOO).
+BINDING_BUILD_FLAGS = \
+  $(NULL)
+
+# Preprocess a JNI binding file using the build flags defined above.
+# $(1): JNI binding file to preprocess.
+preprocess-binding = ($(call py_action,preprocessor, \
+                      $(foreach flag,$(BINDING_BUILD_FLAGS),$(if $($(flag)),-D$(flag))) \
+                      -DMOZ_PREPROCESSOR $(1)) || echo $(1))
+
+# Preprocess and compare two versions of a JNI binding file, one in-tree
+# version and one newly generated version.
+# $(1): Base file name of the JNI binding file.
+# $(2): Additional path to prepend to the in-tree file name. This is required
+#       because in-tree Fennec-specific bindings are in a separate fennec/ directory.
+compare-binding = $(call preprocess-binding,$(1)) | ( \
+                  $(call preprocess-binding,$(topsrcdir)/widget/android/$(2)$(1)) 3<&- | \
+                  diff /dev/fd/3 - >/dev/null ) 3<&0
+
 libs:: GeneratedJNIWrappers.cpp
-	@(diff GeneratedJNIWrappers.cpp $(topsrcdir)/widget/android/GeneratedJNIWrappers.cpp >/dev/null && \
-	  diff GeneratedJNIWrappers.h $(topsrcdir)/widget/android/GeneratedJNIWrappers.h >/dev/null && \
-	  diff GeneratedJNINatives.h $(topsrcdir)/widget/android/GeneratedJNINatives.h >/dev/null) || \
+	@($(call compare-binding,GeneratedJNIWrappers.cpp) && \
+	  $(call compare-binding,GeneratedJNIWrappers.h) && \
+	  $(call compare-binding,GeneratedJNINatives.h)) || \
 	 (echo '*****************************************************' && \
 	  echo '***   Error: The generated JNI code has changed   ***' && \
 	  echo '* To update generated code in the tree, please run  *' && \
 	  echo && \
 	  echo '  make -C $(CURDIR) update-generated-wrappers' && \
 	  echo && \
 	  echo '* Repeat the build, and check in any changes.       *' && \
 	  echo '*****************************************************' && \
 	  exit 1)
 
 libs:: FennecJNIWrappers.cpp
-	@(diff FennecJNIWrappers.cpp $(topsrcdir)/widget/android/fennec/FennecJNIWrappers.cpp >/dev/null && \
-	  diff FennecJNIWrappers.h $(topsrcdir)/widget/android/fennec/FennecJNIWrappers.h >/dev/null && \
-	  diff FennecJNINatives.h $(topsrcdir)/widget/android/fennec/FennecJNINatives.h >/dev/null) || \
+	@($(call compare-binding,FennecJNIWrappers.cpp,fennec/) && \
+	  $(call compare-binding,FennecJNIWrappers.h,fennec/) && \
+	  $(call compare-binding,FennecJNINatives.h,fennec/)) || \
 	 (echo '*****************************************************' && \
 	  echo '***     Error: The Fennec JNI code has changed    ***' && \
 	  echo '* To update generated code in the tree, please run  *' && \
 	  echo && \
 	  echo '  make -C $(CURDIR) update-fennec-wrappers' && \
 	  echo && \
 	  echo '* Repeat the build, and check in any changes.       *' && \
 	  echo '*****************************************************' && \