Bug 1305157 - Handle the build/ directory's GENERATED_FILES; r?gps draft
authorMike Shal <mshal@mozilla.com>
Wed, 28 Sep 2016 13:59:36 -0400
changeset 418656 453f75f1ddd5ca1c9dfef588a3977a9c5ea0bfc0
parent 418655 698d3a6a8477849d63c334b437ce0fb42769d377
child 532401 22c23203406e7a5ea6fc8c5f2ed18f303fc3b731
push id30739
push userbmo:mshal@mozilla.com
push dateWed, 28 Sep 2016 21:27:25 +0000
reviewersgps
bugs1305157
milestone52.0a1
Bug 1305157 - Handle the build/ directory's GENERATED_FILES; r?gps This is a little tricky since tup expects rules in a single Tupfile to be topologically sorted, and the emitter emits the GeneratedFile object before it emits the FinalTargetPreprocessedFile object. We work around this by delaying when we process the application.ini.h GeneratedFile object, but it's a hack. MozReview-Commit-ID: 8nVm76nZOKb
python/mozbuild/mozbuild/backend/tup.py
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -36,16 +36,17 @@ class BackendTupfile(object):
         self.objdir = objdir
         self.relobjdir = mozpath.relpath(objdir, topobjdir)
         self.environment = environment
         self.name = mozpath.join(objdir, 'Tupfile')
         self.rules_included = False
         self.shell_exported = False
         self.defines = []
         self.host_defines = []
+        self.delayed_generated_files = []
 
         self.fh = FileAvoidWrite(self.name, capture_diff=True)
         self.fh.write('# THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT.\n')
         self.fh.write('\n')
 
     def write(self, buf):
         self.fh.write(buf)
 
@@ -145,32 +146,41 @@ class TupOnly(CommonBackend, PartialBack
             skip_files = (
                 'buildid.h',
                 'source-repo.h',
             )
             if any(f in skip_files for f in obj.outputs):
                 # Let the RecursiveMake backend handle these.
                 return False
 
-            self._process_generated_file(backend_file, obj)
+            if 'application.ini.h' in obj.outputs:
+                # application.ini.h is a special case since we need to process
+                # the FINAL_TARGET_PP_FILES for application.ini before running
+                # the GENERATED_FILES script, and tup doesn't handle the rules
+                # out of order.
+                backend_file.delayed_generated_files.append(obj)
+            else:
+                self._process_generated_file(backend_file, obj)
         elif isinstance(obj, Defines):
             self._process_defines(backend_file, obj)
         elif isinstance(obj, HostDefines):
             self._process_defines(backend_file, obj, host=True)
         elif isinstance(obj, FinalTargetPreprocessedFiles):
             self._process_final_target_pp_files(obj, backend_file)
         elif isinstance(obj, ObjdirPreprocessedFiles):
             self._process_final_target_pp_files(obj, backend_file)
 
         return True
 
     def consume_finished(self):
         CommonBackend.consume_finished(self)
 
         for objdir, backend_file in sorted(self._backend_files.items()):
+            for obj in backend_file.delayed_generated_files:
+                self._process_generated_file(backend_file, obj)
             with self._write_file(fh=backend_file):
                 pass
 
         with self._write_file(mozpath.join(self.environment.topobjdir, 'Tuprules.tup')) as fh:
             acdefines = [name for name in self.environment.defines
                 if not name in self.environment.non_global_defines]
             acdefines_flags = ' '.join(['-D%s=%s' % (name,
                 shell_quote(self.environment.defines[name]))
@@ -194,17 +204,16 @@ class TupOnly(CommonBackend, PartialBack
         if not os.path.exists(mozpath.join(self.environment.topsrcdir, ".tup")):
             tup = self.environment.substs.get('TUP', 'tup')
             self._cmd.run_process(cwd=self.environment.topsrcdir, log_name='tup', args=[tup, 'init'])
 
     def _process_generated_file(self, backend_file, obj):
         # TODO: These are directories that don't work in the tup backend
         # yet, because things they depend on aren't built yet.
         skip_directories = (
-            'build', # FinalTargetPreprocessedFiles
             'layout/style/test', # HostSimplePrograms
             'toolkit/library', # libxul.so
         )
         if obj.script and obj.method and obj.relobjdir not in skip_directories:
             backend_file.export_shell()
             cmd = self._py_action('file_generate')
             cmd.extend([
                 obj.script,