Skip to content

Commit f8ea6c6

Browse files
authored
[tools] add project.json generation in vsc.py. (#9632)
* [tools] fix the SDK path issue in env script. * [tools] add project.json generation in vsc.py. * [tools] provide correct and clear comments in vsc.py
1 parent 56c9bbe commit f8ea6c6

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tools/vsc.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import json
3131
import utils
3232
import rtconfig
33+
3334
from utils import _make_path_relative
3435

3536
def delete_repeatelist(data):
@@ -39,7 +40,7 @@ def delete_repeatelist(data):
3940

4041
def GenerateCFiles(env):
4142
"""
42-
Generate c_cpp_properties files
43+
Generate c_cpp_properties.json and build/compile_commands.json files
4344
"""
4445
if not os.path.exists('.vscode'):
4546
os.mkdir('.vscode')
@@ -113,8 +114,47 @@ def GenerateCFiles(env):
113114
vsc_space_file.close()
114115
return
115116

117+
def GenerateProjectFiles(env):
118+
"""
119+
Generate project.json file
120+
"""
121+
if not os.path.exists('.vscode'):
122+
os.mkdir('.vscode')
123+
124+
project = env['project']
125+
vsc_file = open('.vscode/project.json', 'w')
126+
if vsc_file:
127+
groups = []
128+
for group in project:
129+
if len(group['src']) > 0:
130+
item = {}
131+
item['name'] = group['name']
132+
item['path'] = _make_path_relative(os.getcwd(), group['path'])
133+
item['files'] = []
134+
135+
for fn in group['src']:
136+
item['files'].append(str(fn))
137+
138+
# append SConscript if exist
139+
if os.path.exists(os.path.join(item['path'], 'SConscript')):
140+
item['files'].append(os.path.join(item['path'], 'SConscript'))
141+
142+
groups.append(item)
143+
144+
json_dict = {}
145+
json_dict['RT-Thread'] = env['RTT_ROOT']
146+
json_dict['Groups'] = groups
147+
148+
# write groups to project.json
149+
vsc_file.write(json.dumps(json_dict, ensure_ascii=False, indent=4))
150+
vsc_file.close()
151+
152+
return
153+
116154
def GenerateVSCode(env):
117155
print('Update setting files for VSCode...')
156+
157+
GenerateProjectFiles(env)
118158
GenerateCFiles(env)
119159
print('Done!')
120160

0 commit comments

Comments
 (0)