Skip to content

Commit

Permalink
:build:vscode-debug module generates VSCode debug config file
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Oct 25, 2021
1 parent 58118b0 commit a8e10e7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tools/build_script_generator/vscode_debug/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, Raphael Lehmann
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

from os.path import join, relpath, isdir, exists

def init(module):
module.name = ":build:vscode-debug"
module.description = FileReader("module.md")


def prepare(module, options):
if env[":target"].has_driver("core:cortex-m*"):
return True
else:
return False


def build(env):
pass


def post_build(env):
debug_profiles = list()
build_path = env.relative_outpath(env["::build.path"])
for buildtool in ["scons", "make", "cmake"]:
for profile in ["release", "debug"]:
if env.has_module(":build:" + buildtool):
debug_profiles.append({
"name": buildtool + " profile=" + profile,
"executable": "".join([build_path, "/", buildtool, "-", profile, "/", env[":build:project.name"], ".elf"]),
})

env.substitutions.update({
"profiles": debug_profiles,
"target": str(env[":target"]),
})
# these are the ONLY files that are allowed to NOT be namespaced with modm!
env.outbasepath = ".vscode/"
env.template("resources/vscode_launch.json.in", "launch.json")
10 changes: 10 additions & 0 deletions tools/build_script_generator/vscode_debug/module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Visual Studio Code (VSCode) Debug Configuration

[Visual Studio Code (VSCode)][VSCode] is a popular IDE with an integrated debugger UI.
Together with the [Cortex-Debug][] extension it works great for Cortex-M targets.
This modules generates a configuration suitable to launch the debugger with
a single click (or keyboard shortcut) from the IDE.


[VSCode]: https://code.visualstudio.com/
[Cortex-Debug]: https://github.com/Marus/cortex-debug#readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
%% for profile in profiles
{
"name": "modm debug configuration ({{ profile.name }}) for {{ target }}",
"cwd": "${workspaceRoot}",
"executable": "{{ profile.executable }}",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "{{ target }}",
"configFiles": [
"modm/openocd.cfg"
]
}{% if not loop.last %},{% endif %}
%% endfor
]
}

0 comments on commit a8e10e7

Please sign in to comment.