Skip to content

Feature vscode #3915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tools/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from tools.toolchains import Resources
from tools.export import lpcxpresso, ds5_5, iar, makefile
from tools.export import embitz, coide, kds, simplicity, atmelstudio
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt, vscode
from tools.export import gnuarmeclipse
from tools.targets import TARGET_NAMES

Expand All @@ -56,7 +56,10 @@
'eclipse_armc5' : cdt.EclipseArmc5,
'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
'zip' : zip.ZIP,
'cmsis' : cmsis.CMSIS
'cmsis' : cmsis.CMSIS,
'vscode_gcc_arm' : vscode.VSCodeGcc,
'vscode_iar' : vscode.VSCodeIAR,
'vscode_armc5' : vscode.VSCodeArmc5
}

ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """
Expand Down
95 changes: 95 additions & 0 deletions tools/export/vscode/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# mbed SDK
# Copyright (c) 2011-2016 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from os.path import join, exists, realpath, relpath, basename, isfile, splitext
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license header on top of the file

from os import makedirs, listdir
import json

from tools.export.makefile import Makefile, GccArm, Armc5, IAR

class VSCode(Makefile):
"""Generic VSCode project. Intended to be subclassed by classes that
specify a type of Makefile.
"""
def generate(self):
"""Generate Makefile and VSCode launch and task files
"""
super(VSCode, self).generate()
ctx = {
'name': self.project_name,
'elf_location': join('BUILD', self.project_name)+'.elf',
'c_symbols': self.toolchain.get_symbols(),
'asm_symbols': self.toolchain.get_symbols(True),
'target': self.target,
'include_paths': self.resources.inc_dirs,
'load_exe': str(self.LOAD_EXE).lower()
}

if not exists(join(self.export_dir, '.vscode')):
makedirs(join(self.export_dir, '.vscode'))

self.gen_file('vscode/tasks.tmpl', ctx,
join('.vscode', 'tasks.json'))
self.gen_file('vscode/launch.tmpl', ctx,
join('.vscode', 'launch.json'))
self.gen_file('vscode/settings.tmpl', ctx,
join('.vscode', 'settings.json'))

# So.... I want all .h and .hpp files in self.resources.inc_dirs
all_directories = []

for directory in self.resources.inc_dirs:
if not directory:
continue

if directory == ".":
all_directories.append("${workspaceRoot}/*")
else:
all_directories.append(directory.replace("./", "${workspaceRoot}/") + "/*")

cpp_props = {
"configurations": [
{
"name": "Windows",
"includePath": [x.replace("/", "\\") for x in all_directories]
},
{
"name": "Mac",
"includePath": all_directories
},
{
"name": "Linux",
"includePath": all_directories
}
]
}

with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile:
json.dump(cpp_props, outfile, indent=4, separators=(',', ': '))


class VSCodeGcc(VSCode, GccArm):
LOAD_EXE = True
NAME = "VSCode-GCC-ARM"

class VSCodeArmc5(VSCode, Armc5):
LOAD_EXE = True
NAME = "VSCode-Armc5"

class VSCodeIAR(VSCode, IAR):
LOAD_EXE = True
NAME = "VSCode-IAR"


64 changes: 64 additions & 0 deletions tools/export/vscode/launch.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/BUILD/${workspaceRootFolderName}.elf",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"debugServerArgs": "",
"serverLaunchTimeout": 20000,
"filterStderr": true,
"filterStdout": false,
"serverStarted": "GDB\\ server\\ started",
"preLaunchTask": "make",
"setupCommands": [
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
{ "text": "-file-exec-and-symbols ${workspaceRoot}/BUILD/${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
{ "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
{ "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
{ "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
{ "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
{ "text": "-target-download", "description": "flash target", "ignoreFailures": false }
],
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"programOutput": true,
"exceptions": true
},
"linux": {
"MIMode": "gdb",
"MIDebuggerPath": "/usr/bin/arm-none-eabi-gdb",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it was ok to just use the executable name. Why the path here?

"debugServerPath": "pyocd-gdbserver"
},
"osx": {
"MIMode": "gdb",
"MIDebuggerPath": "/usr/local/bin/arm-none-eabi-gdb",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it was ok to just use the executable name. Why the path here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sg- Only for debugServerPath unfortunately... See this comment.

"debugServerPath": "pyocd-gdbserver"
},
"windows": {
"preLaunchTask": "make.exe",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to prelaunch and run make on windows only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't. There's a global prelaunchTask for make which runs on macOS and Linux.

"MIMode": "gdb",
"MIDebuggerPath": "C:\\Program Files (x86)\\GNU Tools ARM Embedded\\4.9 2015q3\\bin\\arm-none-eabi-gdb.exe",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it was ok to just use the executable name. Why the path here?

"debugServerPath": "pyocd-gdbserver.exe",
"setupCommands": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this override global setup commands or should they be moved under Mac / Linux?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this overrides the global setupCommands section. So only applies on Windows.

{ "text": "-environment-cd ${workspaceRoot}\\BUILD" },
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
{ "text": "-file-exec-and-symbols ${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
{ "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
{ "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
{ "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
{ "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
{ "text": "-target-download", "description": "flash target", "ignoreFailures": false }
]
}
}
]
}
4 changes: 4 additions & 0 deletions tools/export/vscode/settings.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"C_Cpp.addWorkspaceRootToIncludePath": false
}
30 changes: 30 additions & 0 deletions tools/export/vscode/tasks.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"name": "make",
"isShellCommand": true,
"showOutput": "always",
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}/mbed-os"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"args": ["-j"],
"linux": {
"command": "make"
},
"osx": {
"command": "make"
},
"windows": {
"command": "make.exe"
}
}