Skip to content

Commit d561d31

Browse files
committed
Script to generate compile_commands.json from compile_flags.txt
This enables background index for a compile_flags.txt driven project. (We should really have a better solution for this)
1 parent 411063a commit d561d31

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scripts/compile_flags_json.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
import os, sys, json
3+
4+
EXTS = ('.c','.C','.cpp','.cc','.cxx','.m','.mm'
5+
'.h','.H','.hpp','.hh','.hxx')
6+
7+
input = sys.argv[1] if len(sys.argv) > 1 else 'compile_flags.txt'
8+
driver = sys.argv[2] if len(sys.argv) > 2 else 'clang'
9+
with open(input) as f:
10+
flags = [line.strip() for line in f]
11+
12+
dir = os.path.dirname(os.path.abspath(input))
13+
14+
entries = []
15+
16+
for root, dirs, files in os.walk(dir):
17+
for file in files:
18+
ext = os.path.splitext(file)[1]
19+
if ext in EXTS:
20+
entries.append({
21+
'directory': dir,
22+
'file': os.path.join(dir, file),
23+
'arguments': [driver] + flags + [os.path.join(dir, file)]})
24+
25+
with open(os.path.join(dir, 'compile_commands.json'), 'w') as file:
26+
json.dump(entries, file, indent=2)
27+

0 commit comments

Comments
 (0)