hi there,

made a short patch to add CompilationDatabase.getAllCompileCommands to
the python binding.

please review and commit.

regards,
Laszlo
Index: clang/cindex.py
===================================================================
--- clang/cindex.py	(revision 197292)
+++ clang/cindex.py	(working copy)
@@ -2607,6 +2607,14 @@
         return conf.lib.clang_CompilationDatabase_getCompileCommands(self,
                                                                      filename)
 
+    def getAllCompileCommands(self):
+        """
+        Get an iterable object providing all the CompileCommands available from
+        the database.
+        """
+        return conf.lib.clang_CompilationDatabase_getAllCompileCommands(self)
+
+
 class Token(Structure):
     """Represents a single token from the preprocessor.
 
@@ -2673,6 +2681,11 @@
    c_object_p,
    CompilationDatabase.from_result),
 
+  ("clang_CompilationDatabase_getAllCompileCommands",
+   [c_object_p],
+   c_object_p,
+   CompileCommands.from_result),
+
   ("clang_CompilationDatabase_getCompileCommands",
    [c_object_p, c_char_p],
    c_object_p,
Index: tests/cindex/test_cdb.py
===================================================================
--- tests/cindex/test_cdb.py	(revision 197292)
+++ tests/cindex/test_cdb.py	(working copy)
@@ -32,6 +32,27 @@
     cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
     assert len(cmds) != 0
 
+def test_all_compilecommand():
+    """Check we get all results from the db"""
+    cdb = CompilationDatabase.fromDirectory(kInputsDir)
+    cmds = cdb.getAllCompileCommands()
+    assert len(cmds) == 3
+    expected = [
+        { 'wd': '/home/john.doe/MyProjectA',
+          'line': ['clang++', '-o', 'project2.o', '-c',
+                   '/home/john.doe/MyProject/project2.cpp']},
+        { 'wd': '/home/john.doe/MyProjectB',
+          'line': ['clang++', '-DFEATURE=1', '-o', 'project2-feature.o', '-c',
+                   '/home/john.doe/MyProject/project2.cpp']},
+        { 'wd': '/home/john.doe/MyProject',
+          'line': ['clang++', '-o', 'project.o', '-c',
+                   '/home/john.doe/MyProject/project.cpp']}
+        ]
+    for i in range(len(cmds)):
+        assert cmds[i].directory == expected[i]['wd']
+        for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
+            assert arg == exp
+
 def test_1_compilecommand():
     """Check file with single compile command"""
     cdb = CompilationDatabase.fromDirectory(kInputsDir)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to