Skip to content

Commit cf87e7d

Browse files
Merge pull request #3915 from janjongboom/feature-vscode
Feature vscode
2 parents bc58c1b + 336e036 commit cf87e7d

File tree

5 files changed

+198
-2
lines changed

5 files changed

+198
-2
lines changed

tools/export/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from tools.toolchains import Resources
3131
from tools.export import lpcxpresso, ds5_5, iar, makefile
3232
from tools.export import embitz, coide, kds, simplicity, atmelstudio
33-
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt
33+
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt, vscode
3434
from tools.export import gnuarmeclipse
3535
from tools.export import qtcreator
3636
from tools.targets import TARGET_NAMES
@@ -58,7 +58,10 @@
5858
'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
5959
'qtcreator': qtcreator.QtCreator,
6060
'zip' : zip.ZIP,
61-
'cmsis' : cmsis.CMSIS
61+
'cmsis' : cmsis.CMSIS,
62+
'vscode_gcc_arm' : vscode.VSCodeGcc,
63+
'vscode_iar' : vscode.VSCodeIAR,
64+
'vscode_armc5' : vscode.VSCodeArmc5
6265
}
6366

6467
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """

tools/export/vscode/__init__.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# mbed SDK
2+
# Copyright (c) 2011-2016 ARM Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from os.path import join, exists, realpath, relpath, basename, isfile, splitext
17+
from os import makedirs, listdir
18+
import json
19+
20+
from tools.export.makefile import Makefile, GccArm, Armc5, IAR
21+
22+
class VSCode(Makefile):
23+
"""Generic VSCode project. Intended to be subclassed by classes that
24+
specify a type of Makefile.
25+
"""
26+
def generate(self):
27+
"""Generate Makefile and VSCode launch and task files
28+
"""
29+
super(VSCode, self).generate()
30+
ctx = {
31+
'name': self.project_name,
32+
'elf_location': join('BUILD', self.project_name)+'.elf',
33+
'c_symbols': self.toolchain.get_symbols(),
34+
'asm_symbols': self.toolchain.get_symbols(True),
35+
'target': self.target,
36+
'include_paths': self.resources.inc_dirs,
37+
'load_exe': str(self.LOAD_EXE).lower()
38+
}
39+
40+
if not exists(join(self.export_dir, '.vscode')):
41+
makedirs(join(self.export_dir, '.vscode'))
42+
43+
self.gen_file('vscode/tasks.tmpl', ctx,
44+
join('.vscode', 'tasks.json'))
45+
self.gen_file('vscode/launch.tmpl', ctx,
46+
join('.vscode', 'launch.json'))
47+
self.gen_file('vscode/settings.tmpl', ctx,
48+
join('.vscode', 'settings.json'))
49+
50+
# So.... I want all .h and .hpp files in self.resources.inc_dirs
51+
all_directories = []
52+
53+
for directory in self.resources.inc_dirs:
54+
if not directory:
55+
continue
56+
57+
if directory == ".":
58+
all_directories.append("${workspaceRoot}/*")
59+
else:
60+
all_directories.append(directory.replace("./", "${workspaceRoot}/") + "/*")
61+
62+
cpp_props = {
63+
"configurations": [
64+
{
65+
"name": "Windows",
66+
"includePath": [x.replace("/", "\\") for x in all_directories]
67+
},
68+
{
69+
"name": "Mac",
70+
"includePath": all_directories
71+
},
72+
{
73+
"name": "Linux",
74+
"includePath": all_directories
75+
}
76+
]
77+
}
78+
79+
with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile:
80+
json.dump(cpp_props, outfile, indent=4, separators=(',', ': '))
81+
82+
83+
class VSCodeGcc(VSCode, GccArm):
84+
LOAD_EXE = True
85+
NAME = "VSCode-GCC-ARM"
86+
87+
class VSCodeArmc5(VSCode, Armc5):
88+
LOAD_EXE = True
89+
NAME = "VSCode-Armc5"
90+
91+
class VSCodeIAR(VSCode, IAR):
92+
LOAD_EXE = True
93+
NAME = "VSCode-IAR"
94+
95+

tools/export/vscode/launch.tmpl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "C++ Launch",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/BUILD/${workspaceRootFolderName}.elf",
9+
"args": [],
10+
"stopAtEntry": true,
11+
"cwd": "${workspaceRoot}",
12+
"environment": [],
13+
"externalConsole": false,
14+
"debugServerArgs": "",
15+
"serverLaunchTimeout": 20000,
16+
"filterStderr": true,
17+
"filterStdout": false,
18+
"serverStarted": "GDB\\ server\\ started",
19+
"preLaunchTask": "make",
20+
"setupCommands": [
21+
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
22+
{ "text": "-file-exec-and-symbols ${workspaceRoot}/BUILD/${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
23+
{ "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
24+
{ "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
25+
{ "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
26+
{ "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
27+
{ "text": "-target-download", "description": "flash target", "ignoreFailures": false }
28+
],
29+
"logging": {
30+
"moduleLoad": true,
31+
"trace": true,
32+
"engineLogging": true,
33+
"programOutput": true,
34+
"exceptions": true
35+
},
36+
"linux": {
37+
"MIMode": "gdb",
38+
"MIDebuggerPath": "/usr/bin/arm-none-eabi-gdb",
39+
"debugServerPath": "pyocd-gdbserver"
40+
},
41+
"osx": {
42+
"MIMode": "gdb",
43+
"MIDebuggerPath": "/usr/local/bin/arm-none-eabi-gdb",
44+
"debugServerPath": "pyocd-gdbserver"
45+
},
46+
"windows": {
47+
"preLaunchTask": "make.exe",
48+
"MIMode": "gdb",
49+
"MIDebuggerPath": "C:\\Program Files (x86)\\GNU Tools ARM Embedded\\4.9 2015q3\\bin\\arm-none-eabi-gdb.exe",
50+
"debugServerPath": "pyocd-gdbserver.exe",
51+
"setupCommands": [
52+
{ "text": "-environment-cd ${workspaceRoot}\\BUILD" },
53+
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
54+
{ "text": "-file-exec-and-symbols ${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
55+
{ "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
56+
{ "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
57+
{ "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
58+
{ "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
59+
{ "text": "-target-download", "description": "flash target", "ignoreFailures": false }
60+
]
61+
}
62+
}
63+
]
64+
}

tools/export/vscode/settings.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"C_Cpp.addWorkspaceRootToIncludePath": false
4+
}

tools/export/vscode/tasks.tmpl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"name": "make",
6+
"isShellCommand": true,
7+
"showOutput": "always",
8+
"problemMatcher": {
9+
"owner": "cpp",
10+
"fileLocation": ["relative", "${workspaceRoot}/mbed-os"],
11+
"pattern": {
12+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
13+
"file": 1,
14+
"line": 2,
15+
"column": 3,
16+
"severity": 4,
17+
"message": 5
18+
}
19+
},
20+
"args": ["-j"],
21+
"linux": {
22+
"command": "make"
23+
},
24+
"osx": {
25+
"command": "make"
26+
},
27+
"windows": {
28+
"command": "make.exe"
29+
}
30+
}

0 commit comments

Comments
 (0)