diff mbox series

[v3,2/2] oe-init-build-env: generate .vscode from template

Message ID 20240214173914.136799-3-adrian.freihofer@siemens.com
State Accepted, archived
Commit 48829be7ab2edcbc2e4473f81cdaf35889d63f9c
Headers show
Series oe-init-build-env: generate .vscode from template | expand

Commit Message

Adrian Freihofer Feb. 14, 2024, 5:36 p.m. UTC
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>
---
 oe-init-build-env       |  6 +++
 scripts/oe-setup-vscode | 90 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
 create mode 100755 scripts/oe-setup-vscode

Comments

Alexander Kanavin Feb. 14, 2024, 5:49 p.m. UTC | #1
Thanks, I have no objections to this version.

Alex

On Wed, 14 Feb 2024 at 18:39, Adrian Freihofer
<adrian.freihofer@gmail.com> wrote:
>
> 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>
> ---
>  oe-init-build-env       |  6 +++
>  scripts/oe-setup-vscode | 90 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 96 insertions(+)
>  create mode 100755 scripts/oe-setup-vscode
>
> diff --git a/oe-init-build-env b/oe-init-build-env
> index 38333ab8582..82382f27078 100755
> --- a/oe-init-build-env
> +++ b/oe-init-build-env
> @@ -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
> index 00000000000..db1cde4ffb6
> --- /dev/null
> +++ b/scripts/oe-setup-vscode
> @@ -0,0 +1,90 @@
> +#!/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.pathToBuildFolder": "$ws_builddir",
> +    "bitbake.pathToEnvScript": "\${workspaceFolder}/oe-init-build-env",
> +    "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."
> --
> 2.43.0
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#195488): https://lists.openembedded.org/g/openembedded-core/message/195488
> Mute This Topic: https://lists.openembedded.org/mt/104357383/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Adrian Freihofer Feb. 14, 2024, 5:59 p.m. UTC | #2
On Wed, 2024-02-14 at 18:49 +0100, Alexander Kanavin wrote:
> Thanks, I have no objections to this version.

I have done my best to take all your ideas into account :-).
I agree, it is much simpler and it still does what is needed to improve
the user experience when working with VSCode, the new yocto-bitbake
plugin as well as with Git (on the command line).

Thank you!
Adrian


> 
> Alex
Enguerrand de Ribaucourt Feb. 15, 2024, 8:31 a.m. UTC | #3
Hello Adrian,

I recommend to keep expliciting other vscode-bitbake parameters. In addition to the default config, the user may have overridden the configuration in their global setting. In which case, the unspecified settings in your template will take that value and probably break.

```
    "bitbake.pathToBitbakeFolder": "${workspaceFolder}/bitbake",
    "bitbake.pathToEnvScript": "${workspaceFolder}/oe-init-build-env",
    "bitbake.pathToBuildFolder": "${workspaceFolder}/build",
    "bitbake.commandWrapper": "",
    "bitbake.workingDirectory": "${workspaceFolder}",
```

Thanks for this new feature which is a great way to share the VSCode configs!
diff mbox series

Patch

diff --git a/oe-init-build-env b/oe-init-build-env
index 38333ab8582..82382f27078 100755
--- a/oe-init-build-env
+++ b/oe-init-build-env
@@ -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
index 00000000000..db1cde4ffb6
--- /dev/null
+++ b/scripts/oe-setup-vscode
@@ -0,0 +1,90 @@ 
+#!/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.pathToBuildFolder": "$ws_builddir",
+    "bitbake.pathToEnvScript": "\${workspaceFolder}/oe-init-build-env",
+    "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."