Skip to content

Commit 53adb4a

Browse files
committed
[cmake_frontend.py] compilation db frontend
1 parent 722214c commit 53adb4a

2 files changed

Lines changed: 37 additions & 40 deletions

File tree

clang_bind/cmake_frontend.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
import os
22
import json
3+
import clang.cindex as clang
4+
5+
6+
class CompilationDatabase:
7+
"""
8+
Build a compilation database from a given directory
9+
"""
10+
11+
def __init__(self, build_dir):
12+
self.compilation_database = clang.CompilationDatabase.fromDirectory(
13+
buildDir=build_dir
14+
)
15+
16+
def get_compilation_arguments(self, filename=None):
17+
"""
18+
Returns the compilation commands extracted from the compilation database
19+
20+
Parameters:
21+
- filename (optional): To get compilaton commands of a file
22+
23+
Returns:
24+
- compilation_arguments (dict): {filename: compiler arguments}
25+
"""
26+
27+
if filename:
28+
# Get compilation commands from the compilation database for the given file
29+
compilation_commands = self.compilation_database.getCompileCommands(
30+
filename=filename
31+
)
32+
else:
33+
# Get all compilation commands from the compilation database
34+
compilation_commands = self.compilation_database.getAllCompileCommands()
35+
36+
return {
37+
command.filename: list(command.arguments)[1:-1]
38+
for command in compilation_commands
39+
}
340

441

542
class Codemodel:

clang_bind/compilation_database.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)