"""
This script creates the tasks.json and launch.json for easier debugging of SUMO with Visual Studio Code.
"""
import json
import os
from os.path import join, dirname
BINARIES = ("activitygen", "emissionsDrivingCycle", "emissionsMap",
"dfrouter", "duarouter", "jtrrouter", "marouter",
"netconvert", "netedit", "netgenerate",
"od2trips", "polyconvert", "sumo", "sumo-gui",
"testcommon", "testfoxtools", "testgeom", "testlibsumo", "testlibsumostatic",
"testlibtraci", "testmicrosim", "testnetbuild", "testthreadpool",
"TraCITestClient")
TASK_TEMPLATE = {
"type": "cmake",
"command": "build",
"group": {
"kind": "build",
"isDefault": False
}
}
LAUNCH_TEMPLATE = {
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": False,
"cwd": "${workspaceFolder}/tests/",
"environment": [],
"externalConsole": False,
"MIMode": "gdb",
"setupCommands": [
{
"text": "-enable-pretty-printing",
"ignoreFailures": True
},
{
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": True
}
]
}
LAUNCH_TEMPLATE_VS = {
"type": "cppvsdbg",
"request": "launch",
"args": [],
"stopAtEntry": False,
"cwd": "${workspaceFolder}/tests/",
"environment": [],
"console": "integratedTerminal"
}
if __name__ == "__main__":
print("This script will overwrite any existing tasks.json and launch.json."
" If you don't want that abort now, otherwise press enter.")
input()
tasks_content = {"version": "2.0.0", "tasks": []}
launch_content = {"version": "0.2.0", "configurations": []}
for app in BINARIES:
t = dict(TASK_TEMPLATE)
t.update(label="build " + app, targets=[app])
tasks_content["tasks"].append(t)
lc = dict(LAUNCH_TEMPLATE_VS if os.name == "nt" else LAUNCH_TEMPLATE)
lc.update(name=app + "D", program="${workspaceFolder}/bin/%sD" % app, preLaunchTask="build " + app)
if "test" not in app.lower():
lc.update(args=["test.%scfg" % app[:4]])
launch_content["configurations"].append(lc)
vscode_dir = join(dirname(__file__), '..', '..', '.vscode')
os.makedirs(vscode_dir, exist_ok=True)
with open(join(dirname(__file__), '..', '..', '.vscode', "tasks.json"), "w") as tasks:
json.dump(tasks_content, tasks, indent=2)
with open(join(dirname(__file__), '..', '..', '.vscode', "launch.json"), "w") as launch:
json.dump(launch_content, launch, indent=2)