Bug 1412267 - Fix the inclusion of MOZ_DEBUG_FLAGS in the compile command line to depend on MOZ_DEBUG_SYMBOLS and MOZ_DEBUG. draft
authorChris Manchester <cmanchester@mozilla.com>
Fri, 27 Oct 2017 09:39:44 -0700
changeset 687712 924aa35199b322ab980ca32fef8fb3df7cb0bee6
parent 686801 0d1e55d87931fe70ec1d007e886bcd58015ff770
child 737719 11936db73d5ae96358cb3bf966fa1831acf0cc35
push id86578
push userbmo:cmanchester@mozilla.com
push dateFri, 27 Oct 2017 16:41:49 +0000
bugs1412267
milestone58.0a1
Bug 1412267 - Fix the inclusion of MOZ_DEBUG_FLAGS in the compile command line to depend on MOZ_DEBUG_SYMBOLS and MOZ_DEBUG. MozReview-Commit-ID: 4MgzRQCX5iW
python/mozbuild/mozbuild/frontend/context.py
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -330,18 +330,17 @@ class CompileFlags(ContextDerivedValue, 
             ('OS_COMPILE_CXXFLAGS', context.config.substs.get('OS_COMPILE_CXXFLAGS'),
              ('CXXFLAGS',)),
             ('OS_CPPFLAGS', context.config.substs.get('OS_CPPFLAGS'),
              ('CXXFLAGS', 'CFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('OS_CFLAGS', context.config.substs.get('OS_CFLAGS'),
              ('CFLAGS', 'C_LDFLAGS')),
             ('OS_CXXFLAGS', context.config.substs.get('OS_CXXFLAGS'),
              ('CXXFLAGS', 'CXX_LDFLAGS')),
-            ('DEBUG', (context.config.substs['MOZ_DEBUG_FLAGS'].split() if
-                       'MOZ_DEBUG_FLAGS' in context.config.substs else []),
+            ('DEBUG', self._debug_flags(),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('CLANG_PLUGIN', context.config.substs.get('CLANG_PLUGIN_FLAGS'),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('OPTIMIZE', self._optimize_flags(),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('FRAMEPTR', context.config.substs.get('MOZ_FRAMEPTR_FLAGS'),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('WARNINGS_AS_ERRORS', self._warnings_as_errors(),
@@ -355,16 +354,22 @@ class CompileFlags(ContextDerivedValue, 
         # a template were set and which were provided as defaults.
         template_name = getattr(context, 'template', None)
         if template_name in (None, 'Gyp'):
             dict.__init__(self, ((k, v if v is None else TypedList(unicode)(v))
                                  for k, v, _ in self.flag_variables))
         else:
             dict.__init__(self)
 
+    def _debug_flags(self):
+        if (self._context.config.substs.get('MOZ_DEBUG') or
+            self._context.config.substs.get('MOZ_DEBUG_SYMBOLS')):
+            return self._context.config.substs.get('MOZ_DEBUG_FLAGS', '').split()
+        return []
+
     def _warnings_as_errors(self):
         warnings_as_errors = self._context.config.substs.get('WARNINGS_AS_ERRORS')
         if self._context.config.substs.get('MOZ_PGO'):
             # Don't use warnings-as-errors in Windows PGO builds because it is suspected of
             # causing problems in that situation. (See bug 437002.)
             if self._context.config.substs['OS_ARCH'] == 'WINNT':
                 warnings_as_errors = None
 
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -209,16 +209,34 @@ class TestEmitterBasic(unittest.TestCase
             'WARNINGS_AS_ERRORS': '-Werror',
         })
         sources, lib, flags = self.read_topsrcdir(reader)
         self.assertIsInstance(flags, ComputedFlags)
         self.assertEqual(flags.flags['STL'], reader.config.substs['STL_FLAGS'])
         self.assertEqual(flags.flags['VISIBILITY'], reader.config.substs['VISIBILITY_FLAGS'])
         self.assertEqual(flags.flags['WARNINGS_AS_ERRORS'], ['-Werror'])
 
+    def test_debug_flags(self):
+        reader = self.reader('compile-flags', extra_substs={
+            'MOZ_DEBUG_FLAGS': '-g',
+            'MOZ_DEBUG_SYMBOLS': '1',
+        })
+        sources, lib, flags = self.read_topsrcdir(reader)
+        self.assertIsInstance(flags, ComputedFlags)
+        self.assertEqual(flags.flags['DEBUG'], ['-g'])
+
+    def test_disable_debug_flags(self):
+        reader = self.reader('compile-flags', extra_substs={
+            'MOZ_DEBUG_FLAGS': '-g',
+            'MOZ_DEBUG_SYMBOLS': '',
+        })
+        sources, lib, flags = self.read_topsrcdir(reader)
+        self.assertIsInstance(flags, ComputedFlags)
+        self.assertEqual(flags.flags['DEBUG'], [])
+
     def test_compile_flags_validation(self):
         reader = self.reader('compile-flags-field-validation')
 
         with self.assertRaisesRegexp(BuildReaderError, 'Invalid value.'):
             self.read_topsrcdir(reader)
 
         reader = self.reader('compile-flags-type-validation')
         with self.assertRaisesRegexp(BuildReaderError,