Skip to content

Commit

Permalink
[libclang/python] Add CompilationDatabase.getAllCompileCommands to th…
Browse files Browse the repository at this point in the history
…e python bindings.

Patch by Laszlo Nagy!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197765 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
akyrtzi committed Dec 20, 2013
1 parent c3390c0 commit bd9d971
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,6 +2607,14 @@ def getCompileCommands(self, filename):
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.
Expand Down Expand Up @@ -2673,6 +2681,11 @@ def cursor(self):
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,
Expand Down
21 changes: 21 additions & 0 deletions bindings/python/tests/cindex/test_cdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ def test_lookup_succeed():
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)
Expand Down

0 comments on commit bd9d971

Please sign in to comment.