Bug 1108750 - part 3 - move unified source mapping to the callers of _add_unified_build_rules; r=mshal
authorNathan Froyd <froydnj@mozilla.com>
Mon, 19 Jan 2015 14:58:21 -0500
changeset 239738 e0a55a8b70bfce0b9b3b8ed8020b01de5eca13a9
parent 239737 a55bd91ead7db804967c066c5294aa3a1c8191be
child 239739 e80c66667c38b7ceb48d9e47db67c4d401252f39
push id506
push usermleibovic@mozilla.com
push dateThu, 29 Jan 2015 12:40:10 +0000
reviewersmshal
bugs1108750
milestone38.0a1
Bug 1108750 - part 3 - move unified source mapping to the callers of _add_unified_build_rules; r=mshal _add_unified_build_rules shouldn't be in the business of determining how to group files into their unified files. That logic belongs in the caller of _add_unified_build_rules. Once that's done, the logic for determining how to group files can migrate out of the recursive make bakend.
python/mozbuild/mozbuild/backend/recursivemake.py
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -403,25 +403,26 @@ class RecursiveMakeBackend(CommonBackend
                 # so avoid creating extremely long path names.
                 unified_prefix = mozpath.relpath(backend_file.objdir,
                     backend_file.environment.topobjdir)
                 if len(unified_prefix) > 20:
                     unified_prefix = unified_prefix[-20:].split('/', 1)[-1]
                 unified_prefix = unified_prefix.replace('/', '_')
 
                 suffix = obj.canonical_suffix[1:]
-                self._add_unified_build_rules(backend_file, source_files,
+                unified_prefix='Unified_%s_%s' % (suffix, unified_prefix)
+                unified_source_mapping = list(group_unified_files(source_files,
+                                                                  unified_prefix=unified_prefix,
+                                                                  unified_suffix=suffix,
+                                                                  files_per_unified_file=files_per_unification))
+                self._add_unified_build_rules(backend_file,
+                    unified_source_mapping,
                     backend_file.objdir,
-                    unified_prefix='Unified_%s_%s' % (
-                        suffix,
-                        unified_prefix),
-                    unified_suffix=suffix,
                     unified_files_makefile_variable=var,
-                    include_curdir_build_rules=False,
-                    files_per_unified_file=files_per_unification)
+                    include_curdir_build_rules=False)
                 backend_file.write('%s += $(%s)\n' % (non_unified_var, var))
             else:
                 backend_file.write('%s += %s\n' % (
                     non_unified_var, ' '.join(source_files)))
         elif isinstance(obj, VariablePassthru):
             # Sorted so output is consistent and we don't bump mtimes.
             for k, v in sorted(obj.variables.items()):
                 if isinstance(v, list):
@@ -604,43 +605,35 @@ class RecursiveMakeBackend(CommonBackend
         with self._write_file(
                 mozpath.join(self.environment.topobjdir, 'root.mk')) as root:
             root_mk.dump(root, removal_guard=False)
 
         with self._write_file(
                 mozpath.join(self.environment.topobjdir, 'root-deps.mk')) as root_deps:
             root_deps_mk.dump(root_deps, removal_guard=False)
 
-    def _add_unified_build_rules(self, makefile, files, output_directory,
-                                 unified_prefix='Unified',
-                                 unified_suffix='cpp',
+    def _add_unified_build_rules(self, makefile, unified_source_mapping,
+                                 output_directory,
                                  extra_dependencies=[],
                                  unified_files_makefile_variable='unified_files',
                                  include_curdir_build_rules=True,
-                                 poison_windows_h=False,
-                                 files_per_unified_file=16):
+                                 poison_windows_h=False):
 
         # In case it's a generator.
-        files = sorted(files)
+        unified_source_mapping = sorted(unified_source_mapping)
 
         explanation = "\n" \
             "# We build files in 'unified' mode by including several files\n" \
             "# together into a single source file.  This cuts down on\n" \
-            "# compilation times and debug information size.  %d was chosen as\n" \
-            "# a reasonable compromise between clobber rebuild time, incremental\n" \
-            "# rebuild time, and compiler memory usage." % files_per_unified_file
+            "# compilation times and debug information size."
         makefile.add_statement(explanation)
 
-        unified_source_mapping = list(group_unified_files(files,
-                                                          unified_prefix=unified_prefix,
-                                                          unified_suffix=unified_suffix,
-                                                          files_per_unified_file=files_per_unified_file))
         all_sources = ' '.join(source for source, _ in unified_source_mapping)
         makefile.add_statement('%s := %s' % (unified_files_makefile_variable,
-                                               all_sources))
+                                             all_sources))
 
         for unified_file, source_filenames in unified_source_mapping:
             if extra_dependencies:
                 rule = makefile.create_rule([unified_file])
                 rule.add_dependencies(extra_dependencies)
 
             # The rule we just defined is only for cases where the cpp files get
             # blown away and we need to regenerate them.  The rule doesn't correctly
@@ -1261,18 +1254,21 @@ INSTALL_TARGETS += %(prefix)s
 
     def _handle_ipdl_sources(self, sorted_ipdl_sources, ipdl_cppsrcs):
         # Write out a master list of all IPDL source files.
         ipdl_dir = mozpath.join(self.environment.topobjdir, 'ipc', 'ipdl')
         mk = Makefile()
 
         mk.add_statement('ALL_IPDLSRCS := %s' % ' '.join(sorted_ipdl_sources))
 
-        self._add_unified_build_rules(mk, ipdl_cppsrcs, ipdl_dir,
-                                      unified_prefix='UnifiedProtocols',
+        unified_source_mapping = list(group_unified_files(ipdl_cppsrcs,
+                                                          unified_prefix='UnifiedProtocols',
+                                                          unified_suffix='cpp',
+                                                          files_per_unified_file=16))
+        self._add_unified_build_rules(mk, unified_source_mapping, ipdl_dir,
                                       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)
 
@@ -1344,19 +1340,21 @@ INSTALL_TARGETS += %(prefix)s
                 '$(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._add_unified_build_rules(mk,
-            webidls.all_regular_cpp_basenames(),
+            unified_source_mapping,
             bindings_dir,
-            unified_prefix='UnifiedBindings',
             unified_files_makefile_variable='unified_binding_cpp_files',
-            poison_windows_h=True,
-            files_per_unified_file=32)
+            poison_windows_h=True)
 
         webidls_mk = mozpath.join(bindings_dir, 'webidlsrcs.mk')
         with self._write_file(webidls_mk) as fh:
             mk.dump(fh, removal_guard=False)