Bug 794162 - Mach command to generate a .clang_complete file; r=ehsan
authorGregory Szorc <gps@mozilla.com>
Fri, 01 Feb 2013 12:21:43 -0800
changeset 126568 b546bd987ed4007bcf9006b21f3234157ce7d71a
parent 126567 95bec0e5a600654c34f4b9f280e4293c71055885
child 126690 4e7c92906a795f721806e19aa86566bfd2c89018
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs794162
milestone21.0a1
Bug 794162 - Mach command to generate a .clang_complete file; r=ehsan DONTBUILD (NPOTB)
python/mozbuild/mozbuild/mach_commands.py
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -203,14 +203,66 @@ class Warnings(MachCommandBase):
             if warning['column'] is not None:
                 print('%s:%d:%d [%s] %s' % (filename, warning['line'],
                     warning['column'], warning['flag'], warning['message']))
             else:
                 print('%s:%d [%s] %s' % (filename, warning['line'],
                     warning['flag'], warning['message']))
 
 @CommandProvider
+class ClangCommands(MachCommandBase):
+    @Command('clang-complete', help='Generate a .clang_complete file.')
+    def clang_complete(self):
+        import shlex
+
+        build_vars = {}
+
+        def on_line(line):
+            elements = [s.strip() for s in line.split('=', 1)]
+
+            if len(elements) != 2:
+                return
+
+            build_vars[elements[0]] = elements[1]
+
+        try:
+            old_logger = self.log_manager.replace_terminal_handler(None)
+            self._run_make(target='showbuild', log=False, line_handler=on_line)
+        finally:
+            self.log_manager.replace_terminal_handler(old_logger)
+
+        def print_from_variable(name):
+            if name not in build_vars:
+                return
+
+            value = build_vars[name]
+
+            value = value.replace('-I.', '-I%s' % self.topobjdir)
+            value = value.replace(' .', ' %s' % self.topobjdir)
+            value = value.replace('-I..', '-I%s/..' % self.topobjdir)
+            value = value.replace(' ..', ' %s/..' % self.topobjdir)
+
+            args = shlex.split(value)
+            for i in range(0, len(args) - 1):
+                arg = args[i]
+
+                if arg.startswith(('-I', '-D')):
+                    print(arg)
+                    continue
+
+                if arg.startswith('-include'):
+                    print(arg + ' ' + args[i + 1])
+                    continue
+
+        print_from_variable('COMPILE_CXXFLAGS')
+
+        print('-I%s/ipc/chromium/src' % self.topsrcdir)
+        print('-I%s/ipc/glue' % self.topsrcdir)
+        print('-I%s/ipc/ipdl/_ipdlheaders' % self.topobjdir)
+
+
+@CommandProvider
 class Package(MachCommandBase):
     """Package the built product for distribution."""
 
     @Command('package', help='Package the built product for distribution as an APK, DMG, etc.')
     def package(self):
         return self._run_make(directory=".", target='package', ensure_exit_code=False)