File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import clang .cindex as clang
2+
3+
4+ class CompilationDatabase :
5+ """
6+ Build a compilation database from a given directory
7+ """
8+
9+ def __init__ (self , compilation_database_path ):
10+ self .compilation_database = clang .CompilationDatabase .fromDirectory (
11+ buildDir = compilation_database_path
12+ )
13+
14+ def get_compilation_arguments (self , filename = None ):
15+ """
16+ Returns the compilation commands extracted from the compilation database
17+
18+ Parameters:
19+ - compilation_database_path: The path to `compile_commands.json`
20+ - filename (optional): To get compilaton commands of a file
21+
22+ Returns:
23+ - compilation_arguments (dict): {filename: compiler arguments}
24+ """
25+
26+ if filename :
27+ # Get compilation commands from the compilation database for the given file
28+ compilation_commands = self .compilation_database .getCompileCommands (
29+ filename = filename
30+ )
31+ else :
32+ # Get all compilation commands from the compilation database
33+ compilation_commands = self .compilation_database .getAllCompileCommands ()
34+
35+ # {file: compiler arguments}
36+ compilation_arguments = {
37+ command .filename : list (command .arguments )[1 :- 1 ]
38+ for command in compilation_commands
39+ }
40+ return compilation_arguments
You can’t perform that action at this time.
0 commit comments