-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_compdb.py
executable file
·40 lines (34 loc) · 1.14 KB
/
gen_compdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
""" Creates a compilation database entry for the given command """
import json
import argparse
import os
def generate_db_json(source_file, command):
""" Generates a single compilation database string from
all provided files """
compdb = [
{
"arguments": command.split(),
"directory": os.getcwd(),
"file": source_file
}
]
return json.dumps(compdb, indent=4)
def main():
""" Entrypoint for the program """
parser = argparse.ArgumentParser()
parser.add_argument("--file",
help='File to build',
required=True)
parser.add_argument("--command",
help='command to build',
required=True)
parser.add_argument('--output', nargs='?',
help='Output file. Defaults to file.json',
default='file.json')
args = parser.parse_args()
comp_db = generate_db_json(args.file, args.command)
with open(args.output, 'w') as output_file:
output_file.write(comp_db)
if __name__ == '__main__':
main()