本文整理汇总了Python中clang.cindex.CompilationDatabase类的典型用法代码示例。如果您正苦于以下问题:Python CompilationDatabase类的具体用法?Python CompilationDatabase怎么用?Python CompilationDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompilationDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_fail
def test_create_fail():
"""Check we fail loading a database with an assertion"""
path = os.path.dirname(__file__)
try:
CompilationDatabase.fromDirectory(path)
except CompilationDatabaseError as e:
assert e.cdb_error == CompilationDatabaseError.ERROR_CANNOTLOADDATABASE
else:
assert False
示例2: test_compilationDB_references
def test_compilationDB_references(self):
"""Ensure CompilationsCommands are independent of the database"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
del cdb
gc.collect()
workingdir = cmds[0].directory
示例3: test_compilecommand_iterator_stops
def test_compilecommand_iterator_stops(self):
"""Check that iterator stops after the correct number of elements"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
count = 0
for cmd in cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp'):
count += 1
self.assertLessEqual(count, 2)
示例4: test_all_compilecommand
def test_all_compilecommand(self):
"""Check we get all results from the db"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getAllCompileCommands()
self.assertEqual(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']},
]
for i in range(len(cmds)):
self.assertEqual(cmds[i].directory, expected[i]['wd'])
self.assertEqual(cmds[i].filename, expected[i]['file'])
for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
self.assertEqual(arg, exp)
示例5: test_compilecommand_iterator_stops
def test_compilecommand_iterator_stops():
"""Check that iterator stops after the correct number of elements"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
count = 0
for cmd in cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp"):
count += 1
assert count <= 2
示例6: test_2_compilecommand
def test_2_compilecommand():
"""Check file with 2 compile commands"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp")
assert len(cmds) == 2
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",
],
},
]
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
示例7: test_2_compilecommand
def test_2_compilecommand():
"""Check file with 2 compile commands"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp')
assert len(cmds) == 2
expected = [
{
'wd': b'/home/john.doe/MyProjectA',
'line': [
b'clang++',
b'-o', b'project2.o',
b'-c', b'/home/john.doe/MyProject/project2.cpp'
]
},
{
'wd': b'/home/john.doe/MyProjectB',
'line': [
b'clang++',
b'-DFEATURE=1',
b'-o', b'project2-feature.o',
b'-c', b'/home/john.doe/MyProject/project2.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
示例8: test_create_fail
def test_create_fail(self):
"""Check we fail loading a database with an assertion"""
path = os.path.dirname(__file__)
with self.assertRaises(CompilationDatabaseError) as cm:
cdb = CompilationDatabase.fromDirectory(path)
e = cm.exception
self.assertEqual(e.cdb_error,
CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)
示例9: test_compilationCommands_references
def test_compilationCommands_references(self):
"""Ensure CompilationsCommand keeps a reference to CompilationCommands"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
del cdb
cmd0 = cmds[0]
del cmds
gc.collect()
workingdir = cmd0.directory
示例10: test_1_compilecommand
def test_1_compilecommand():
"""Check file with single compile command"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
assert len(cmds) == 1
assert cmds[0].directory == "/home/john.doe/MyProject"
expected = ["clang++", "-o", "project.o", "-c", "/home/john.doe/MyProject/project.cpp"]
for arg, exp in zip(cmds[0].arguments, expected):
assert arg == exp
示例11: initClangComplete
def initClangComplete(clang_complete_flags, clang_compilation_database,
library_path):
global index
debug = int(vim.eval("g:clang_debug")) == 1
quiet = int(vim.eval("g:clang_quiet")) == 1
if library_path:
if os.path.isdir(library_path):
Config.set_library_path(library_path)
else:
Config.set_library_file(library_path)
Config.set_compatibility_check(False)
try:
index = Index.create()
except Exception as e:
if quiet:
return 0
if library_path:
suggestion = "Are you sure '%s' contains libclang?" % library_path
else:
suggestion = "Consider setting g:clang_library_path."
if debug:
exception_msg = str(e)
else:
exception_msg = ''
print('''Loading libclang failed, completion won't be available. %s
%s
''' % (suggestion, exception_msg))
return 0
global builtinHeaderPath
builtinHeaderPath = None
if not canFindBuiltinHeaders(index):
builtinHeaderPath = getBuiltinHeaderPath(library_path)
if not builtinHeaderPath:
print("WARNING: libclang can not find the builtin includes.")
print(" This will cause slow code completion.")
print(" Please report the problem.")
global translationUnits
translationUnits = dict()
global complete_flags
complete_flags = int(clang_complete_flags)
global compilation_database
if clang_compilation_database != '':
compilation_database = CompilationDatabase.fromDirectory(clang_compilation_database)
else:
compilation_database = None
global libclangLock
libclangLock = threading.Lock()
return 1
示例12: test_1_compilecommand
def test_1_compilecommand():
"""Check file with single compile command"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
assert len(cmds) == 1
assert cmds[0].directory == '/home/john.doe/MyProject'
expected = [ 'clang++', '-o', 'project.o', '-c',
'/home/john.doe/MyProject/project.cpp']
for arg, exp in zip(cmds[0].arguments, expected):
assert arg.spelling == exp
示例13: test_1_compilecommand
def test_1_compilecommand(self):
"""Check file with single compile command"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
file = '/home/john.doe/MyProject/project.cpp'
cmds = cdb.getCompileCommands(file)
self.assertEqual(len(cmds), 1)
self.assertEqual(cmds[0].directory, os.path.dirname(file))
self.assertEqual(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):
self.assertEqual(arg, exp)
示例14: test_create_fail
def test_create_fail(self):
"""Check we fail loading a database with an assertion"""
path = os.path.dirname(__file__)
# clang_CompilationDatabase_fromDirectory calls fprintf(stderr, ...)
# Suppress its output.
stderr = os.dup(2)
with open(os.devnull, 'wb') as null:
os.dup2(null.fileno(), 2)
with self.assertRaises(CompilationDatabaseError) as cm:
cdb = CompilationDatabase.fromDirectory(path)
os.dup2(stderr, 2)
os.close(stderr)
e = cm.exception
self.assertEqual(e.cdb_error,
CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)
示例15: test_2_compilecommand
def test_2_compilecommand(self):
"""Check file with 2 compile commands"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp')
self.assertEqual(len(cmds), 2)
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']}
]
for i in range(len(cmds)):
self.assertEqual(cmds[i].directory, expected[i]['wd'])
for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
self.assertEqual(arg, exp)