Bug 1099345 - Use pattern rule to generate multiple outputs in widget/android/bindings. r=gps, a=NPOTB FIREFOX_RELEASE_34_BASE
authorNick Alexander <nalexander@mozilla.com>
Wed, 19 Nov 2014 11:33:05 -0800
changeset 226136 e247a7f7c43842941bdb4207ca1b9d8881798997
parent 226135 67a53bb6b0bd70219699129d40d1a4c9d7f016f5
child 226137 52c9248a7c4708b2ebe36237aa967005793c9b6b
push id4175
push userryanvm@gmail.com
push dateMon, 24 Nov 2014 17:08:09 +0000
treeherdermozilla-beta@e247a7f7c438 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, NPOTB
bugs1099345
milestone34.0
Bug 1099345 - Use pattern rule to generate multiple outputs in widget/android/bindings. r=gps, a=NPOTB This works around a race condition observed with GENERATED_SOURCES. A global solution might be to make GENERATED_SOURCES part of the 'export' tier; this is a smaller fix.
widget/android/bindings/Makefile.in
widget/android/bindings/MediaCodec-classes.txt
widget/android/bindings/SurfaceTexture-classes.txt
widget/android/bindings/mediacodec-classes.txt
widget/android/bindings/moz.build
widget/android/bindings/surfacetexture-classes.txt
--- a/widget/android/bindings/Makefile.in
+++ b/widget/android/bindings/Makefile.in
@@ -5,25 +5,23 @@
 annotation_processor_jar_files := $(DEPTH)/build/annotationProcessors/annotationProcessors.jar:$(ANDROID_TOOLS)/lib/lint.jar:$(ANDROID_TOOLS)/lib/lint-checks.jar
 
 sdk_processor := \
   $(JAVA) \
   -Dcom.android.tools.lint.bindir='$(ANDROID_TOOLS)' \
   -classpath $(annotation_processor_jar_files) \
   org.mozilla.gecko.annotationProcessors.SDKProcessor
 
-MediaCodec.cpp: $(ANDROID_SDK)/android.jar mediacodec-classes.txt
-	$(sdk_processor) $(ANDROID_SDK)/android.jar $(srcdir)/mediacodec-classes.txt $(CURDIR) MediaCodec 16
-
-MediaCodec.h: MediaCodec.cpp
+# For the benefit of readers: the following pattern rule says that,
+# for example, MediaCodec.cpp and MediaCodec.h can be produced from
+# MediaCodec-classes.txt.  This formulation invokes the SDK processor
+# at most once.
 
-SurfaceTexture.cpp: $(ANDROID_SDK)/android.jar surfacetexture-classes.txt
-	$(sdk_processor) $(ANDROID_SDK)/android.jar $(srcdir)/surfacetexture-classes.txt $(CURDIR) SurfaceTexture 16
-
-SurfaceTexture.h: SurfaceTexture.cpp
+%.cpp %.h: $(ANDROID_SDK)/android.jar %-classes.txt
+	$(sdk_processor) $(ANDROID_SDK)/android.jar $(srcdir)/$*-classes.txt $(CURDIR) $* 16
 
 # We'd like these to be defined in a future GENERATED_EXPORTS list.
 bindings_exports_FILES := \
   MediaCodec.h \
   SurfaceTexture.h \
   $(NULL)
 bindings_exports_DEST = $(DIST)/include
 bindings_exports_TARGET := export
rename from widget/android/bindings/mediacodec-classes.txt
rename to widget/android/bindings/MediaCodec-classes.txt
rename from widget/android/bindings/surfacetexture-classes.txt
rename to widget/android/bindings/SurfaceTexture-classes.txt
--- a/widget/android/bindings/moz.build
+++ b/widget/android/bindings/moz.build
@@ -1,24 +1,35 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-GENERATED_SOURCES += [
-    'MediaCodec.cpp',
-    'SurfaceTexture.cpp',
+# List of stems to generate .cpp and .h files for.  To add a stem, add it to
+# this list and ensure that $(stem)-classes.txt exists in this directory.
+generated = [
+    'MediaCodec',
+    'SurfaceTexture',
 ]
 
+GENERATED_SOURCES += [stem + '.cpp' for stem in generated]
+
 # We'd like to add these to a future GENERATED_EXPORTS list, but for now we mark
 # them as generated here and manually install them in Makefile.in.
-GENERATED_FILES += [
-    'MediaCodec.h',
-    'SurfaceTexture.h',
-]
+GENERATED_FILES += [stem + '.h' for stem in generated]
+
+# There is an unfortunate race condition when using GENERATED_SOURCES and
+# pattern rules (see Makefile.in) that manifests itself as a VPATH resolution
+# conflict: MediaCodec.o looks for MediaCodec.cpp and $(CURDIR)/MediaCodec.cpp,
+# and the pattern rule is matched but doesn't resolve both sources, causing a
+# failure.  Adding the GENERATED_SOURCES to GENERATED_FILES causes the sources
+# to be built at export time, which is before MediaCodec.o needs them; and by
+# the time MediaCodec.o is built, the source is in place and the VPATH
+# resolution works as expected.
+GENERATED_FILES += GENERATED_SOURCES
 
 FAIL_ON_WARNINGS = True
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '/widget/android',
 ]