Bug 1108750 - part 8 - move WebIDL unification logic to CommonBackend; r=mshal
authorNathan Froyd <froydnj@mozilla.com>
Mon, 19 Jan 2015 15:38:26 -0500
changeset 239743 2c010ad45bd386f2e80e458c15a6f2d6e6d56255
parent 239742 a75da472515fe68558bf8277348d406a30e9bce9
child 239744 5a3d567fd8b56e998cb89df22742a4dd245cb29e
push id506
push usermleibovic@mozilla.com
push dateThu, 29 Jan 2015 12:40:10 +0000
reviewersmshal
bugs1108750
milestone38.0a1
Bug 1108750 - part 8 - move WebIDL unification logic to CommonBackend; r=mshal Similar to the changes made for IPDL files, this commit moves all of the non-makefile related logic for WebIDL files out of the recursive make backend and into the common build backend. Derivative backends that would like to do interesting things with WebIDL files now need to implement _handle_webidl_build, which takes more parameters, but should ideally require less duplication of logic.
python/mozbuild/mozbuild/backend/common.py
python/mozbuild/mozbuild/backend/recursivemake.py
--- a/python/mozbuild/mozbuild/backend/common.py
+++ b/python/mozbuild/mozbuild/backend/common.py
@@ -5,16 +5,17 @@
 from __future__ import unicode_literals
 
 import itertools
 import json
 import os
 import re
 
 import mozpack.path as mozpath
+import mozwebidlcodegen
 
 from .base import BuildBackend
 
 from ..frontend.data import (
     ConfigFileSubstitution,
     ExampleWebIDLInterface,
     HeaderFileSubstitution,
     IPDLFile,
@@ -274,16 +275,62 @@ class CommonBackend(BuildBackend):
             self.backend_input_files.add(config.source)
 
         # Write out a machine-readable file describing every test.
         path = mozpath.join(self.environment.topobjdir, 'all-tests.json')
         with self._write_file(path) as fh:
             s = json.dumps(self._test_manager.tests_by_path)
             fh.write(s)
 
+    def _handle_webidl_collection(self, webidls):
+        if not webidls.all_stems():
+            return
+
+        bindings_dir = mozpath.join(self.environment.topobjdir, 'dom', 'bindings')
+
+        all_inputs = set(webidls.all_static_sources())
+        for s in webidls.all_non_static_basenames():
+            all_inputs.add(mozpath.join(bindings_dir, s))
+
+        generated_events_stems = webidls.generated_events_stems()
+        exported_stems = webidls.all_regular_stems()
+
+        # The WebIDL manager reads configuration from a JSON file. So, we
+        # need to write this file early.
+        o = dict(
+            webidls=sorted(all_inputs),
+            generated_events_stems=sorted(generated_events_stems),
+            exported_stems=sorted(exported_stems),
+            example_interfaces=sorted(webidls.example_interfaces),
+        )
+
+        file_lists = mozpath.join(bindings_dir, 'file-lists.json')
+        with self._write_file(file_lists) as fh:
+            json.dump(o, fh, sort_keys=True, indent=2)
+
+        manager = mozwebidlcodegen.create_build_system_manager(
+            self.environment.topsrcdir,
+            self.environment.topobjdir,
+            mozpath.join(self.environment.topobjdir, 'dist')
+        )
+
+        # Bindings are compiled in unified mode to speed up compilation and
+        # to reduce linker memory size. Note that test bindings are separated
+        # from regular ones so tests bindings aren't shipped.
+        unified_source_mapping = list(group_unified_files(webidls.all_regular_cpp_basenames(),
+                                                          unified_prefix='UnifiedBindings',
+                                                          unified_suffix='cpp',
+                                                          files_per_unified_file=32))
+        self._write_unified_files(unified_source_mapping, bindings_dir,
+                                  poison_windows_h=True)
+        self._handle_webidl_build(bindings_dir, unified_source_mapping,
+                                  webidls,
+                                  manager.expected_build_output_files(),
+                                  manager.GLOBAL_DEFINE_FILES)
+
     def _write_unified_file(self, unified_file, source_filenames,
                             output_directory, poison_windows_h=False):
         with self._write_file(mozpath.join(output_directory, unified_file)) as f:
             f.write('#define MOZ_UNIFIED_BUILD\n')
             includeTemplate = '#include "%(cppfile)s"'
             if poison_windows_h:
                 includeTemplate += (
                     '\n'
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -12,17 +12,16 @@ import re
 import types
 
 from collections import (
     defaultdict,
     namedtuple,
 )
 from StringIO import StringIO
 
-import mozwebidlcodegen
 from reftest import ReftestManifest
 
 from mozpack.copier import FilePurger
 from mozpack.manifests import (
     InstallManifest,
 )
 import mozpack.path as mozpath
 
@@ -1247,64 +1246,32 @@ INSTALL_TARGETS += %(prefix)s
                                       unified_files_makefile_variable='CPPSRCS')
 
         mk.add_statement('IPDLDIRS := %s' % ' '.join(sorted(set(mozpath.dirname(p)
             for p in self._ipdl_sources))))
 
         with self._write_file(mozpath.join(ipdl_dir, 'ipdlsrcs.mk')) as ipdls:
             mk.dump(ipdls, removal_guard=False)
 
-    def _handle_webidl_collection(self, webidls):
-        if not webidls.all_stems():
-            return
-
-        bindings_dir = mozpath.join(self.environment.topobjdir, 'dom',
-            'bindings')
-
-        all_inputs = set(webidls.all_static_sources())
-        for s in webidls.all_non_static_basenames():
-            all_inputs.add(mozpath.join(bindings_dir, s))
-
-        generated_events_stems = webidls.generated_events_stems()
-        exported_stems = webidls.all_regular_stems()
-
-        # The WebIDL manager reads configuration from a JSON file. So, we
-        # need to write this file early.
-        o = dict(
-            webidls=sorted(all_inputs),
-            generated_events_stems=sorted(generated_events_stems),
-            exported_stems=sorted(exported_stems),
-            example_interfaces=sorted(webidls.example_interfaces),
-        )
-
-        file_lists = mozpath.join(bindings_dir, 'file-lists.json')
-        with self._write_file(file_lists) as fh:
-            json.dump(o, fh, sort_keys=True, indent=2)
-
-        manager = mozwebidlcodegen.create_build_system_manager(
-            self.environment.topsrcdir,
-            self.environment.topobjdir,
-            mozpath.join(self.environment.topobjdir, 'dist')
-        )
-
-        # The manager is the source of truth on what files are generated.
-        # Consult it for install manifests.
+    def _handle_webidl_build(self, bindings_dir, unified_source_mapping,
+                             webidls, expected_build_output_files,
+                             global_define_files):
         include_dir = mozpath.join(self.environment.topobjdir, 'dist',
             'include')
-        for f in manager.expected_build_output_files():
+        for f in expected_build_output_files:
             if f.startswith(include_dir):
                 self._install_manifests['dist_include'].add_optional_exists(
                     mozpath.relpath(f, include_dir))
 
         # We pass WebIDL info to make via a completely generated make file.
         mk = Makefile()
         mk.add_statement('nonstatic_webidl_files := %s' % ' '.join(
             sorted(webidls.all_non_static_basenames())))
         mk.add_statement('globalgen_sources := %s' % ' '.join(
-            sorted(manager.GLOBAL_DEFINE_FILES)))
+            sorted(global_define_files)))
         mk.add_statement('test_sources := %s' % ' '.join(
             sorted('%sBinding.cpp' % s for s in webidls.all_test_stems())))
 
         # Add rules to preprocess bindings.
         # This should ideally be using PP_TARGETS. However, since the input
         # filenames match the output filenames, the existing PP_TARGETS rules
         # result in circular dependencies and other make weirdness. One
         # solution is to rename the input or output files repsectively. See
@@ -1317,24 +1284,15 @@ INSTALL_TARGETS += %(prefix)s
                 # Remove the file before writing so bindings that go from
                 # static to preprocessed don't end up writing to a symlink,
                 # which would modify content in the source directory.
                 '$(RM) $@',
                 '$(call py_action,preprocessor,$(DEFINES) $(ACDEFINES) '
                     '$(XULPPFLAGS) $< -o $@)'
             ])
 
-        # Bindings are compiled in unified mode to speed up compilation and
-        # to reduce linker memory size. Note that test bindings are separated
-        # from regular ones so tests bindings aren't shipped.
-        unified_source_mapping = list(group_unified_files(webidls.all_regular_cpp_basenames(),
-                                                          unified_prefix='UnifiedBindings',
-                                                          unified_suffix='cpp',
-                                                          files_per_unified_file=32))
-        self._write_unified_files(unified_source_mapping, bindings_dir,
-                                  poison_windows_h=True)
         self._add_unified_build_rules(mk,
             unified_source_mapping,
             unified_files_makefile_variable='unified_binding_cpp_files')
 
         webidls_mk = mozpath.join(bindings_dir, 'webidlsrcs.mk')
         with self._write_file(webidls_mk) as fh:
             mk.dump(fh, removal_guard=False)