Skip to content

Commit

Permalink
Improve VS Code with GN build (project-chip#1878)
Browse files Browse the repository at this point in the history
* Fix VSCode problem matcher for GN

GN runs the compiler in the build directory, so add that as the base
path for the VSCode task.

* Copy Nordic SDK into vscode container

This is not currently included in the devcontainer. Add it by copying it
from the chip-build-nrf-platform container.

* Configure VS Code C/C++ extension to use GN compilation database

This fixes include paths & #defines to enable the richer IntelliSense
features of VS Code.

Usage:
  - Run Task: Update Compilation Database
  - Control-Shift-P -> C/C++ - Select a Configuration.
  • Loading branch information
mspang authored Jul 27, 2020
1 parent 5df39b7 commit 274d626
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
53 changes: 53 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"configurations": [
{
"name": "gcc debug (GN)",
"compileCommands": "${workspaceFolder}/out/debug/compile_commands.gcc.json",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": ["${workspaceFolder}/out/debug/"],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "clang debug (GN)",
"compileCommands": "${workspaceFolder}/out/debug/compile_commands.clang.json",
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "clang-x64",
"browse": {
"path": ["${workspaceFolder}/out/debug/"],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "gcc MbedTLS debug (GN)",
"compileCommands": "${workspaceFolder}/out/debug/compile_commands.mbedtls.json",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": ["${workspaceFolder}/out/debug/"],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "nRF5 examples debug (GN)",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64",
"compileCommands": "${workspaceFolder}/out/debug/compile_commands.nrf5.json",
"compilerPath": "/var/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc",
"browse": {
"path": ["${workspaceFolder}/out/debug/"],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
18 changes: 17 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,23 @@
"reveal": "always",
"panel": "shared"
},
"problemMatcher": ["$gcc"]
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "${workspaceFolder}/out/debug/"]
}
},
{
"label": "Update compilation database",
"type": "shell",
"command": "scripts/helpers/update_compile_commands.sh",
"group": "none",
"dependsOn": "GN Build",
"isBackground": false,
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Auto-enforce coding style",
Expand Down
8 changes: 7 additions & 1 deletion integrations/docker/images/chip-build-vscode/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
ARG VERSION=latest
FROM connectedhomeip/chip-build:${VERSION}
FROM connectedhomeip/chip-build-nrf-platform:${VERSION}
FROM connectedhomeip/chip-build-nrf-platform:${VERSION} AS nrf
FROM connectedhomeip/chip-build-esp32:${VERSION}
FROM connectedhomeip/chip-build-esp32-qemu:${VERSION}
COPY --from=nrf /var/nRF5_tools /var/nRF5_tools
COPY --from=nrf /var/nRF5_SDK_for_Thread_and_Zigbee /var/nRF5_SDK_for_Thread_and_Zigbee
COPY --from=nrf /var/gcc-arm-none-eabi-9-2019-q4-major /var/gcc-arm-none-eabi-9-2019-q4-major
ENV NRF5_SDK_ROOT=/var/nRF5_SDK_for_Thread_and_Zigbee
ENV NRF5_TOOLS_ROOT=/var/nRF5_tools
ENV ARM_GCC_INSTALL_ROOT=/var/gcc-arm-none-eabi-9-2019-q4-major/bin/
38 changes: 38 additions & 0 deletions scripts/helpers/update_compile_commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#
# Copyright (c) 2020 Project CHIP Authors
#
# 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.
#

# Update compilation database in VS Code devcontainer.

set -e

CHIP_ROOT="$(dirname "$0")/../.."

set +e
source "$CHIP_ROOT/scripts/activate.sh"
set -e

gn --root="$CHIP_ROOT" gen "$CHIP_ROOT/out/debug" --export-compile-commands=all_host_gcc
mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_commands.gcc.json"

gn --root="$CHIP_ROOT" gen "$CHIP_ROOT/out/debug" --export-compile-commands=all_host_clang
mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_commands.clang.json"

gn --root="$CHIP_ROOT" gen "$CHIP_ROOT/out/debug" --export-compile-commands=all_host_gcc_mbedtls
mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_commands.mbedtls.json"

gn --root="$CHIP_ROOT" gen "$CHIP_ROOT/out/debug" --export-compile-commands=nrf5_lock_app,nrf5_lighting_app
mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_commands.nrf5.json"

0 comments on commit 274d626

Please sign in to comment.