Bug 1305157 - Handle FinalTargetPreprocessedFiles in the tup backend; r?gps draft
authorMike Shal <mshal@mozilla.com>
Wed, 28 Sep 2016 13:55:38 -0400
changeset 418655 698d3a6a8477849d63c334b437ce0fb42769d377
parent 418654 fce09de096c8f5da8e3398c4fce0ed5596f28a1b
child 418656 453f75f1ddd5ca1c9dfef588a3977a9c5ea0bfc0
push id30739
push userbmo:mshal@mozilla.com
push dateWed, 28 Sep 2016 21:27:25 +0000
reviewersgps
bugs1305157
milestone52.0a1
Bug 1305157 - Handle FinalTargetPreprocessedFiles in the tup backend; r?gps MozReview-Commit-ID: 6fxTagN6mGl
python/mozbuild/mozbuild/backend/tup.py
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -11,18 +11,20 @@ from mozbuild.base import MozbuildObject
 from mozbuild.backend.base import PartialBackend, HybridBackend
 from mozbuild.backend.recursivemake import RecursiveMakeBackend
 from mozbuild.shellutil import quote as shell_quote
 
 from .common import CommonBackend
 from ..frontend.data import (
     ContextDerived,
     Defines,
+    FinalTargetPreprocessedFiles,
     GeneratedFile,
     HostDefines,
+    ObjdirPreprocessedFiles,
 )
 from ..util import (
     FileAvoidWrite,
 )
 
 
 class BackendTupfile(object):
     """Represents a generated Tupfile.
@@ -148,32 +150,39 @@ class TupOnly(CommonBackend, PartialBack
                 # Let the RecursiveMake backend handle these.
                 return False
 
             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()):
             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]))
                 for name in sorted(acdefines)])
+            # TODO: AB_CD only exists in Makefiles at the moment.
+            acdefines_flags += ' -DAB_CD=en-US'
+
             fh.write('MOZ_OBJ_ROOT = $(TUP_CWD)\n')
             fh.write('DIST = $(MOZ_OBJ_ROOT)/dist\n')
             fh.write('ACDEFINES = %s\n' % acdefines_flags)
             fh.write('topsrcdir = $(MOZ_OBJ_ROOT)/%s\n' % (
                 os.path.relpath(self.environment.topsrcdir, self.environment.topobjdir)
             ))
             fh.write('PYTHON = $(MOZ_OBJ_ROOT)/_virtualenv/bin/python -B\n')
             fh.write('PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py\n')
@@ -220,16 +229,22 @@ class TupOnly(CommonBackend, PartialBack
     def _process_defines(self, backend_file, obj, host=False):
         defines = list(obj.get_defines())
         if defines:
             if host:
                 backend_file.host_defines = defines
             else:
                 backend_file.defines = defines
 
+    def _process_final_target_pp_files(self, obj, backend_file):
+        for i, (path, files) in enumerate(obj.files.walk()):
+            for f in files:
+                self._preprocess(backend_file, f.full_path,
+                                 destdir=mozpath.join(self.environment.topobjdir, obj.install_target, path))
+
     def _handle_idl_manager(self, manager):
         backend_file = self._get_backend_file('xpcom/xpidl')
         backend_file.export_shell()
 
         for module, data in sorted(manager.modules.iteritems()):
             dest, idls = data
             cmd = [
                 '$(PYTHON_PATH)',
@@ -252,26 +267,31 @@ class TupOnly(CommonBackend, PartialBack
                     '$(MOZ_OBJ_ROOT)/xpcom/idl-parser/xpidl/xpidllex.py',
                     '$(MOZ_OBJ_ROOT)/xpcom/idl-parser/xpidl/xpidlyacc.py',
                 ],
                 display='XPIDL %s' % module,
                 cmd=cmd,
                 outputs=outputs,
             )
 
-    def _preprocess(self, backend_file, input_file):
+    def _preprocess(self, backend_file, input_file, destdir=None):
         cmd = self._py_action('preprocessor')
         cmd.extend(backend_file.defines)
         cmd.extend(['$(ACDEFINES)', '%f', '-o', '%o'])
 
+        base_input = mozpath.basename(input_file)
+        if base_input.endswith('.in'):
+            base_input = mozpath.splitext(base_input)[0]
+        output = mozpath.join(destdir, base_input) if destdir else base_input
+
         backend_file.rule(
             inputs=[input_file],
             display='Preprocess %o',
             cmd=cmd,
-            outputs=[mozpath.basename(input_file)],
+            outputs=[output],
         )
 
     def _handle_ipdl_sources(self, ipdl_dir, sorted_ipdl_sources,
                              unified_ipdl_cppsrcs_mapping):
         # TODO: This isn't implemented yet in the tup backend, but it is called
         # by the CommonBackend.
         pass