Skip to content

Commit

Permalink
vscode: add initial support
Browse files Browse the repository at this point in the history
For the moment, only to build.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
  • Loading branch information
matttbe committed May 1, 2024
1 parent 9268a6f commit a8244e5
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update && \
libdbus-1-dev libnl-genl-3-dev libibverbs-dev \
tcpdump \
pkg-config libmnl-dev \
clang lld llvm llvm-dev libcap-dev \
clang clangd lld llvm llvm-dev libcap-dev \
gdb gdb-multiarch crash dwarves strace trace-cmd \
iptables ebtables nftables vim psmisc bash-completion less jq \
gettext-base libevent-dev libtraceevent-dev libnewt0.52 libslang2 libutempter0 python3-newt tmux \
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,25 @@ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --rm -it \
mptcp/mptcp-upstream-virtme-docker:latest \
cmd rm -r .virtme/build*/tools
```

## Working with VSCode

If you use [VSCode for Linux kernel development](https://github.com/FlorentRevest/linux-kernel-vscode)
add-on, you can configure it to use this docker image: simply copy all files
from the [`vscode`](/tree/main/vscode) directory in your `.vscode` dir from the
kernel source (or use symbolic links).

Notes:
- The VSCode add-on needs some modifications, see
[PR #5](https://github.com/FlorentRevest/linux-kernel-vscode/pull/5) and
[PR #6](https://github.com/FlorentRevest/linux-kernel-vscode/pull/6). If these
PRs are not merged, you can use
[this fork](https://github.com/matttbe/linux-kernel-vscode/) (`virtme-support`
branch) for the moment.
- If you build the Docker image yourself, you can use a symbolic link instead of
the `clangd` script:
```bash
ln -s /PATH/TO/mptcp-upstream-virtme-docker/run-tests-dev-cmd.sh .vscode/mptcp-virtme-clangd
```
- CLang will be used by VSCode, e.g. to generate `compile_commands.json`. You
then need to launch docker commands with `-e INPUT_CLANG=1`
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,9 @@ case "${INPUT_MODE}" in
COMPILER="${COMPILER}" \
"${MAKE_CROSS}" "${@}"
;;
"defconfig")
gen_kconfig "${@:-normal}"
;;
"cmd" | "command")
"${@}"
;;
Expand Down
21 changes: 21 additions & 0 deletions run-tests-dev-cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e
# SPDX-License-Identifier: GPL-2.0
DIR="$(dirname "$(realpath -P "${0}")")"
CMD="$(basename "${0}")"

if [ "${CMD}" = "run-tests-dev-cmd.sh" ]; then
if [ -n "${1}" ]; then
CMD="${1}"
shift
else
CMD="bash"
fi
elif [[ "${CMD}" = ".virtme-run-"* ]]; then
export VIRTME_NO_INTERACTIVE=1
CMD="${CMD:12}"
elif [[ "${CMD}" = "mptcp-virtme-"* ]]; then
export VIRTME_NO_INTERACTIVE=1
CMD="${CMD:13}"
fi

bash "-${-}" "${DIR}/run-tests-dev.sh" cmd "${CMD}" "${@}"
33 changes: 33 additions & 0 deletions vscode/local-virtme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0

# shellcheck disable=SC2317

export VIRTME_NO_INTERACTIVE=1
export INPUT_CLANG="1"
export MAKE="./.virtme.sh make"
export SILENT_BUILD_FLAG=" "
export SPINNER=0

defconfig() {
./.virtme.sh defconfig
}

case "${COMMAND}" in
"build" | "clean" | "menuconfig" | "update" | "systemtap-build")
echo "local: allow: ${COMMAND}"
;;
"gdb-index")
echo "local: skip: ${COMMAND}"
exit 0
;;
"defconfig")
echo "local: custom: ${COMMAND}"
${COMMAND}
exit
;;
*)
echo "local: block: ${COMMAND}"
exit 1
;;
esac
6 changes: 6 additions & 0 deletions vscode/mptcp-virtme-clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0

docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --rm -t \
mptcp/mptcp-upstream-virtme-docker:latest \
cmd clangd "${@}"
6 changes: 6 additions & 0 deletions vscode/settings-extra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"clangd.arguments": [
"-compile-commands-dir=${workspaceFolder}/.virtme/build-clang"
],
"clangd.path": "${workspaceFolder}/.vscode/mptcp-virtme-clangd"
}

0 comments on commit a8244e5

Please sign in to comment.