Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/devel/generate_vscode_tasks.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2015-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file generate_vscode_tasks.py
15
# @author Michael Behrisch
16
# @date 2025-02-28
17
18
"""
19
This script creates the tasks.json and launch.json for easier debugging of SUMO with Visual Studio Code.
20
"""
21
22
import json
23
import os
24
from os.path import join, dirname
25
26
BINARIES = ("activitygen", "emissionsDrivingCycle", "emissionsMap",
27
"dfrouter", "duarouter", "jtrrouter", "marouter",
28
"netconvert", "netedit", "netgenerate",
29
"od2trips", "polyconvert", "sumo", "sumo-gui",
30
"testcommon", "testfoxtools", "testgeom", "testlibsumo", "testlibsumostatic",
31
"testlibtraci", "testmicrosim", "testnetbuild", "testthreadpool",
32
"TraCITestClient")
33
34
TASK_TEMPLATE = {
35
"type": "cmake",
36
"command": "build",
37
"group": {
38
"kind": "build",
39
"isDefault": False
40
}
41
}
42
43
LAUNCH_TEMPLATE = {
44
"type": "cppdbg",
45
"request": "launch",
46
"args": [],
47
"stopAtEntry": False,
48
"cwd": "${workspaceFolder}/tests/",
49
"environment": [],
50
"externalConsole": False,
51
"MIMode": "gdb",
52
"setupCommands": [
53
{
54
"text": "-enable-pretty-printing",
55
"ignoreFailures": True
56
},
57
{
58
"text": "-gdb-set disassembly-flavor intel",
59
"ignoreFailures": True
60
}
61
]
62
}
63
64
LAUNCH_TEMPLATE_VS = {
65
"type": "cppvsdbg",
66
"request": "launch",
67
"args": [],
68
"stopAtEntry": False,
69
"cwd": "${workspaceFolder}/tests/",
70
"environment": [],
71
"console": "integratedTerminal"
72
}
73
74
75
if __name__ == "__main__":
76
print("This script will overwrite any existing tasks.json and launch.json."
77
" If you don't want that abort now, otherwise press enter.")
78
input()
79
tasks_content = {"version": "2.0.0", "tasks": []}
80
launch_content = {"version": "0.2.0", "configurations": []}
81
for app in BINARIES:
82
t = dict(TASK_TEMPLATE)
83
t.update(label="build " + app, targets=[app])
84
tasks_content["tasks"].append(t)
85
lc = dict(LAUNCH_TEMPLATE_VS if os.name == "nt" else LAUNCH_TEMPLATE)
86
lc.update(name=app + "D", program="${workspaceFolder}/bin/%sD" % app, preLaunchTask="build " + app)
87
if "test" not in app.lower():
88
lc.update(args=["test.%scfg" % app[:4]])
89
launch_content["configurations"].append(lc)
90
vscode_dir = join(dirname(__file__), '..', '..', '.vscode')
91
os.makedirs(vscode_dir, exist_ok=True)
92
with open(join(dirname(__file__), '..', '..', '.vscode', "tasks.json"), "w") as tasks:
93
json.dump(tasks_content, tasks, indent=2)
94
with open(join(dirname(__file__), '..', '..', '.vscode', "launch.json"), "w") as launch:
95
json.dump(launch_content, launch, indent=2)
96
97