Bug 1319222 - Support compiling *.s with yasm; r=chmanchester draft
authorMike Shal <mshal@mozilla.com>
Wed, 22 Nov 2017 17:12:50 -0500 (2017-11-22)
changeset 707638 402cf6be86dd6723930c7a0b93bbd0341f5f53c0
parent 707637 2972a5a54694c82661cbcafa7bc920f3023c8247
child 707639 e650283c9bb3ee174b58f8591a785663677cde8f
push id92183
push userbmo:mshal@mozilla.com
push dateTue, 05 Dec 2017 16:33:02 +0000 (2017-12-05)
reviewerschmanchester
bugs1319222
milestone59.0a1
Bug 1319222 - Support compiling *.s with yasm; r=chmanchester The moz.build files that specify USE_YASM = True will get the value of AS_DASH_C_FLAG and AS overwritten in PassthruVariables. We can save those in the BackendTupfile and use them in place of the configure or default settings as appropriate. This enables compilation of those .s files that are built with yasm. MozReview-Commit-ID: J66q8nKQ0an
python/mozbuild/mozbuild/backend/tup.py
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -30,16 +30,17 @@ from ..frontend.data import (
     GeneratedFile,
     GeneratedSources,
     HostDefines,
     HostSources,
     JARManifest,
     ObjdirFiles,
     PerSourceFlag,
     Sources,
+    VariablePassthru,
 )
 from ..util import (
     FileAvoidWrite,
     expand_variables,
 )
 from ..frontend.context import (
     AbsolutePath,
     ObjDirPath,
@@ -60,16 +61,17 @@ class BackendTupfile(object):
         self.shell_exported = False
         self.defines = []
         self.host_defines = []
         self.delayed_generated_files = []
         self.per_source_flags = defaultdict(list)
         self.local_flags = defaultdict(list)
         self.sources = defaultdict(list)
         self.host_sources = defaultdict(list)
+        self.variables = {}
 
         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)
 
@@ -116,31 +118,34 @@ class BackendTupfile(object):
             cmd=['!tup_ln'],
             inputs=[source],
             outputs=outputs,
         )
 
     def gen_sources_rules(self, extra_inputs):
         sources = self.sources
         host_sources = self.host_sources
+        as_dash_c = self.variables.get('AS_DASH_C_FLAG', self.environment.substs['AS_DASH_C_FLAG'])
         compilers = [
-            (sources['.S'], 'AS', 'ASFLAGS', ''),
-            (sources['.cpp'], 'CXX', 'CXXFLAGS', ''),
-            (sources['.c'], 'CC', 'CFLAGS', ''),
-            (host_sources['.cpp'], 'HOST_CXX', 'HOST_CXXFLAGS', 'host_'),
-            (host_sources['.c'], 'HOST_CC', 'HOST_CFLAGS', 'host_'),
+            (sources['.S'], 'AS', 'SFLAGS', '-c', ''),
+            (sources['.s'], 'AS', 'ASFLAGS', as_dash_c, ''),
+            (sources['.cpp'], 'CXX', 'CXXFLAGS', '-c', ''),
+            (sources['.c'], 'CC', 'CFLAGS', '-c', ''),
+            (host_sources['.cpp'], 'HOST_CXX', 'HOST_CXXFLAGS', '-c', 'host_'),
+            (host_sources['.c'], 'HOST_CC', 'HOST_CFLAGS', '-c', 'host_'),
         ]
-        for srcs, compiler, flags, prefix in compilers:
+        for srcs, compiler, flags, dash_c, prefix in compilers:
             for src in sorted(srcs):
                 # AS can be set to $(CC), so we need to call expand_variables on
                 # the compiler to get the real value.
-                cmd = [expand_variables(self.environment.substs[compiler], self.environment.substs)]
+                compiler_value = self.variables.get(compiler, self.environment.substs[compiler])
+                cmd = [expand_variables(compiler_value, self.environment.substs)]
                 cmd.extend(shell_quote(f) for f in self.local_flags[flags])
                 cmd.extend(shell_quote(f) for f in self.per_source_flags[src])
-                cmd.extend(['-c', '%f', '-o', '%o'])
+                cmd.extend([dash_c, '%f', '-o', '%o'])
                 self.rule(
                     cmd=cmd,
                     inputs=[src],
                     extra_inputs=extra_inputs,
                     outputs=[prefix + '%B.o'],
                     display='%s %%f' % compiler,
                 )
 
@@ -275,16 +280,18 @@ class TupOnly(CommonBackend, PartialBack
             backend_file.per_source_flags[obj.file_name].extend(obj.flags)
         elif isinstance(obj, ComputedFlags):
             self._process_computed_flags(obj, backend_file)
         elif isinstance(obj, (Sources, GeneratedSources)):
             if obj.relobjdir.startswith(self._supported_dirs):
                 backend_file.sources[obj.canonical_suffix].extend(obj.files)
         elif isinstance(obj, HostSources):
             backend_file.host_sources[obj.canonical_suffix].extend(obj.files)
+        elif isinstance(obj, VariablePassthru):
+            backend_file.variables = obj.variables
 
         return True
 
     def consume_finished(self):
         CommonBackend.consume_finished(self)
 
         # The approach here is similar to fastermake.py, but we
         # simply write out the resulting files here.