]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
oe-init-build-env: generate .vscode from template
authorAdrian Freihofer <adrian.freihofer@gmail.com>
Thu, 15 Feb 2024 22:53:33 +0000 (23:53 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 19 Feb 2024 11:34:09 +0000 (11:34 +0000)
Provide a reasonable default configuration for VSCode and the
yocto.bitbake extension.
The generated default configuration is generic and minimal. It's mostly
supposed to prevent VSCode from OOM exceptions if the build directory is
in the scope of the indexer plugins of VSCode.
But it also configures the yocto-bitbake plugin to just work without
manual user interaction.

The configuration is only generated if VSCode is installed. Currently,
VSCode is one of many popular editors for Yocto/OE. Removing the check
would mean that the configuration would be generated by e.g. oe-selftest
or for users not using VSCode. If it should prove useful, the check can
be removed later.

Customization for other layers is possible. A layer might provide it's
own oe-setup-build-env script which calls the oe-setup-vscode script
from poky with different folders. But it's also possible to override the
oe-setup-vscode script by another layer with a custom implementation.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
oe-init-build-env
scripts/oe-setup-vscode [new file with mode: 0755]

index 38333ab858249269e3ef3bf83f282a85c5d49877..82382f27078f6a7cd909f7c34be5fda85e37ce62 100755 (executable)
@@ -47,6 +47,12 @@ export OEROOT
     unset OEROOT
     return 1
 }
+
+# Generate an initial configuration for VSCode and the yocto-bitbake plugin.
+if command -v code > /dev/null && [ ! -d "$OEROOT/.vscode" ]; then
+    oe-setup-vscode "$OEROOT" "$BUILDDIR"
+fi
+
 unset OEROOT
 
 [ -z "$BUILDDIR" ] || cd "$BUILDDIR"
diff --git a/scripts/oe-setup-vscode b/scripts/oe-setup-vscode
new file mode 100755 (executable)
index 0000000..b864278
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+usage() {
+    echo "$0 <OEINIT> <BUILDDIR>"
+    echo "  OEINIT:   path to directory where the .vscode folder is"
+    echo "  BUILDDIR: directory passed to the oe-init-setup-env script"
+}
+
+if [ "$#" -ne 2 ]; then
+    usage
+    exit 1
+fi
+
+OEINIT=$(readlink -f "$1")
+BUILDDIR=$(readlink -f "$2")
+VSCODEDIR=$OEINIT/.vscode
+
+if [ ! -d "$OEINIT" ] || [ ! -d "$BUILDDIR" ]; then
+    echo "$OEINIT and/or $BUILDDIR directories are not present."
+    exit 1
+fi
+
+VSCODE_SETTINGS=$VSCODEDIR/settings.json
+ws_builddir="$(echo "$BUILDDIR" | sed -e "s|$OEINIT|\${workspaceFolder}|g")"
+
+# If BUILDDIR is in scope of VSCode ensure VSCode does not try to index the build folder.
+# This would lead to a busy CPU and finally to an OOM exception.
+mkdir -p "$VSCODEDIR"
+cat <<EOMsettings > "$VSCODE_SETTINGS"
+{
+    "bitbake.pathToBitbakeFolder": "\${workspaceFolder}/bitbake",
+    "bitbake.pathToEnvScript": "\${workspaceFolder}/oe-init-build-env",
+    "bitbake.pathToBuildFolder": "$ws_builddir",
+    "bitbake.commandWrapper": "",
+    "bitbake.workingDirectory": "\${workspaceFolder}",
+    "files.exclude": {
+        "**/.git/**": true,
+        "**/_build/**": true,
+        "**/buildhistory/**": true,
+        "**/cache/**": true,
+        "**/downloads/**": true,
+        "**/node_modules/**": true,
+        "**/oe-logs/**": true,
+        "**/oe-workdir/**": true,
+        "**/sstate-cache/**": true,
+        "**/tmp*/**": true,
+        "**/workspace/attic/**": true,
+        "**/workspace/sources/**": true
+    },
+    "files.watcherExclude": {
+        "**/.git/**": true,
+        "**/_build/**": true,
+        "**/buildhistory/**": true,
+        "**/cache/**": true,
+        "**/downloads/**": true,
+        "**/node_modules/**": true,
+        "**/oe-logs/**": true,
+        "**/oe-workdir/**": true,
+        "**/sstate-cache/**": true,
+        "**/tmp*/**": true,
+        "**/workspace/attic/**": true,
+        "**/workspace/sources/**": true
+    },
+    "python.analysis.exclude": [
+        "**/_build/**",
+        "**/.git/**",
+        "**/buildhistory/**",
+        "**/cache/**",
+        "**/downloads/**",
+        "**/node_modules/**",
+        "**/oe-logs/**",
+        "**/oe-workdir/**",
+        "**/sstate-cache/**",
+        "**/tmp*/**",
+        "**/workspace/attic/**",
+        "**/workspace/sources/**"
+    ]
+}
+EOMsettings
+
+
+# Ask the user if the yocto-bitbake extension should be installed
+VSCODE_EXTENSIONS=$VSCODEDIR/extensions.json
+cat <<EOMextensions > "$VSCODE_EXTENSIONS"
+{
+    "recommendations": [
+        "yocto-project.yocto-bitbake"
+    ]
+}
+EOMextensions
+
+echo "You had no $VSCODEDIR configuration."
+echo "These configuration files have therefore been created for you."