r262845 - python binding: expose compile command filename
Guillaume Papin via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 7 10:44:42 PST 2016
Author: papin_g
Date: Mon Mar 7 12:44:42 2016
New Revision: 262845
URL: http://llvm.org/viewvc/llvm-project?rev=262845&view=rev
Log:
python binding: expose compile command filename
Reviewers: compnerd, skalinichev
Differential Revision: http://reviews.llvm.org/D17278
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_cdb.py
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=262845&r1=262844&r2=262845&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Mon Mar 7 12:44:42 2016
@@ -2703,6 +2703,11 @@ class CompileCommand(object):
return conf.lib.clang_CompileCommand_getDirectory(self.cmd)
@property
+ def filename(self):
+ """Get the working filename for this CompileCommand"""
+ return conf.lib.clang_CompileCommand_getFilename(self.cmd)
+
+ @property
def arguments(self):
"""
Get an iterable object providing each argument in the
@@ -2883,6 +2888,11 @@ functionList = [
[c_object_p],
_CXString,
_CXString.from_result),
+
+ ("clang_CompileCommand_getFilename",
+ [c_object_p],
+ _CXString,
+ _CXString.from_result),
("clang_CompileCommand_getNumArgs",
[c_object_p],
Modified: cfe/trunk/bindings/python/tests/cindex/test_cdb.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cdb.py?rev=262845&r1=262844&r2=262845&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cdb.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cdb.py Mon Mar 7 12:44:42 2016
@@ -38,27 +38,34 @@ def test_all_compilecommand():
cmds = cdb.getAllCompileCommands()
assert len(cmds) == 3
expected = [
+ { 'wd': '/home/john.doe/MyProject',
+ 'file': '/home/john.doe/MyProject/project.cpp',
+ 'line': ['clang++', '-o', 'project.o', '-c',
+ '/home/john.doe/MyProject/project.cpp']},
{ 'wd': '/home/john.doe/MyProjectA',
+ 'file': '/home/john.doe/MyProject/project2.cpp',
'line': ['clang++', '-o', 'project2.o', '-c',
'/home/john.doe/MyProject/project2.cpp']},
{ 'wd': '/home/john.doe/MyProjectB',
+ 'file': '/home/john.doe/MyProject/project2.cpp',
'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']
+ assert cmds[i].filename == expected[i]['file']
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)
- cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
+ file = '/home/john.doe/MyProject/project.cpp'
+ cmds = cdb.getCompileCommands(file)
assert len(cmds) == 1
- assert cmds[0].directory == '/home/john.doe/MyProject'
+ assert cmds[0].directory == os.path.dirname(file)
+ assert cmds[0].filename == file
expected = [ 'clang++', '-o', 'project.o', '-c',
'/home/john.doe/MyProject/project.cpp']
for arg, exp in zip(cmds[0].arguments, expected):
More information about the cfe-commits
mailing list