-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-include-paths.py
executable file
·51 lines (39 loc) · 1.47 KB
/
parse-include-paths.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
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""
Parses .vscode/.cmaketools.json to obtain a list of include paths.
These can then be subsequently pasted into .vscode/c_cpp_properties.json
to make intellisense work. This is script exists purely for convenience
and only needs to be used when the include paths change (e.g. when a new
dependency is added).
"""
import json
import os
import sys
def iterate_over(dict_or_list, result):
"""
Iterates recursively over nested lists and dictionaries
keeping track of all "path" values with the key "includePath"
within nested dictionaries.
"""
if isinstance(dict_or_list, list):
for child in dict_or_list:
iterate_over(child, result)
elif isinstance(dict_or_list, dict):
for key, value in dict_or_list.items():
if key == "includePath":
for child in value:
result.add(child["path"])
else:
iterate_over(value, result)
def main(arguments):
"""Main function of this program."""
workspace = os.path.realpath(os.path.join(__file__, os.pardir, os.pardir))
print("Workspace root: '{}'".format(workspace))
with open(os.path.join(workspace, ".vscode", ".cmaketools.json")) as f:
data = json.loads(f.read())
result = set()
iterate_over(data, result)
result = [x.replace(workspace, "${workspaceRoot}") for x in result]
print(json.dumps(result, indent=0))
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))