Message ID | 20240213221846.109260-4-adrian.freihofer@siemens.com |
---|---|
State | Accepted, archived |
Commit | 48829be7ab2edcbc2e4473f81cdaf35889d63f9c |
Headers | show |
Series | vscode: improve settings for new yocto plugin | expand |
On Tue, 13 Feb 2024 at 23:19, Adrian Freihofer <adrian.freihofer@gmail.com> wrote: > > --- a/scripts/oe-setup-builddir > +++ b/scripts/oe-setup-builddir > @@ -59,6 +59,8 @@ if [ -n "$TEMPLATECONF" ]; then > OECORELOCALCONF="$TEMPLATECONF/local.conf.sample" > OECOREDESCRCONF="$TEMPLATECONF/conf-description.txt" > OECORENOTESCONF="$TEMPLATECONF/conf-notes.txt" > + VSCODE_SETTINGS_CONF="$TEMPLATECONF/vscode/settings.json.sample" > + VSCODE_EXTENSIONS_CONF="$TEMPLATECONF/vscode/extensions.json" > fi > > unset SHOWYPDOC > @@ -114,11 +116,52 @@ if [ ! -r "$BUILDDIR/conf/conf-notes.txt" ]; then > [ ! -r "$OECORENOTESCONF" ] || cp "$OECORENOTESCONF" "$BUILDDIR/conf/conf-notes.txt" > fi > > +# If VSCode is installed generate a reasonable configuration > +if command -v code > /dev/null; then > + # Ensure VSCode does not try to index $BUILDDIR and ends up with an OOM exception. > + # Configure also the yocto-bitbake extension to work. > + if [ -z "$VSCODE_SETTINGS_CONF" ]; then > + VSCODE_SETTINGS_CONF="$OEROOT/meta/conf/templates/default/vscode/settings.json.sample" > + fi > + if [ ! -r "$OEINIT/.vscode/settings.json" ] && [ -f "$VSCODE_SETTINGS_CONF" ]; then > + cat <<EOM > +You had no .vscode/settings.json file. This configuration file has therefore been > +created for you from $VSCODE_SETTINGS_CONF. > + > +EOM > + mkdir -p "$OEINIT/.vscode" > + sed -e "s|##OEINIT##|$OEINIT|g" \ > + -e "s|##OEROOT##|$OEROOT|g" \ > + -e "s|##BUILDDIR##|$BUILDDIR|g" \ > + \ > + -e "s|\"$OEINIT|\"\${workspaceFolder}|g" \ > + "$VSCODE_SETTINGS_CONF" > "$OEINIT/.vscode/settings.json" > + SHOWYPDOC=yes > + fi > + > + # Support also recommending extensions for VSCode. > + if [ -z "$VSCODE_EXTENSIONS_CONF" ]; then > + VSCODE_EXTENSIONS_CONF="$OEROOT/meta/conf/templates/default/vscode/extensions.json" > + fi > + if [ ! -r "$OEINIT/.vscode/extensions.json" ] && [ -f "$VSCODE_EXTENSIONS_CONF" ]; then > + cat <<EOM > +You had no .vscode/extensions.json file. This configuration file has therefore been > +created for you from $VSCODE_EXTENSIONS_CONF. > + > +EOM > + mkdir -p "$OEINIT/.vscode" > + cp "$VSCODE_EXTENSIONS_CONF" "$OEINIT/.vscode" > + SHOWYPDOC=yes > + fi > +fi > + > # Prevent disturbing a new GIT clone in same console > unset OECORELOCALCONF > unset OECORELAYERCONF > unset OECOREDESCRCONF > unset OECORENOTESCONF > +unset VSCODE_SETTINGS_CONF > +unset VSCODE_EXTENSIONS_CONF This certainly has to go into a separate script. oe-setup-builddir is already over-stuffed and difficult to maintain, please don't make it worse. Alex
On Tue, 13 Feb 2024 at 23:19, Adrian Freihofer <adrian.freihofer@gmail.com> wrote: > +++ b/meta-poky/conf/templates/default/vscode/settings.json.sample > @@ -0,0 +1,47 @@ > +{ > + "bitbake.pathToBitbakeFolder": "##OEROOT##/bitbake", > + "bitbake.pathToBuildFolder": "##BUILDDIR##", > + "bitbake.pathToEnvScript": "##OEINIT##/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/**" > + ] > +} Does every template really need to provide this separately? If they don't do it, then experience in vscode is going to be poor. On the other hand I don't think there's anything particular to poky/core default template in the above, so why not place this somewhere global like meta/files, and then all templates will gain vscode settings automatically? Same should be considered for extensions.json, although there might be a use case for per-template extensions, not sure. Alex
On Wed, 2024-02-14 at 11:01 +0100, Alexander Kanavin wrote: > On Tue, 13 Feb 2024 at 23:19, Adrian Freihofer > <adrian.freihofer@gmail.com> wrote: > > +++ b/meta-poky/conf/templates/default/vscode/settings.json.sample > > @@ -0,0 +1,47 @@ > > +{ > > + "bitbake.pathToBitbakeFolder": "##OEROOT##/bitbake", > > + "bitbake.pathToBuildFolder": "##BUILDDIR##", > > + "bitbake.pathToEnvScript": "##OEINIT##/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/**" > > + ] > > +} > > Does every template really need to provide this separately? If they > don't do it, then experience in vscode is going to be poor. On the > other hand I don't think there's anything particular to poky/core > default template in the above, so why not place this somewhere global > like meta/files, and then all templates will gain vscode settings > automatically? > > Same should be considered for extensions.json, although there might > be > a use case for per-template extensions, not sure. > Ideally there would be a generic template (as the one here) which is used by default for all build configurations. But the .vscode configuration can also be much more specific. The best would be to do something in the middle from what my patches do and what you suggest: Take the .vscode templates from a user specific folder if there is one, otherwise take the default one which is found in poky. Currently this is possible with sym-links on the user side but I agree that this could be better (without sym-links). I will send a v3 which will improve that. Thank you. Adrian > Alex
On Tue, 13 Feb 2024 at 23:19, Adrian Freihofer
<adrian.freihofer@gmail.com> wrote:
> + "bitbake.pathToBitbakeFolder": "##OEROOT##/bitbake",
I wonder what in vscode needs this path, and why? The reason I ask is
that bitbake executable itself is already in PATH, and hardcoding the
path to bitbake folder like that is problematic in setups that use
separate checkouts for oe-core and bitbake, where bitbake can be
anywhere.
I'd suggest using ##BITBAKEROOT## replacement and have BITBAKEROOT set
by vscode-specific setup script (as suggested elsewhere) from parent
dir of 'which bitbake'.
Alex
On Wed, 14 Feb 2024 at 11:37, <adrian.freihofer@gmail.com> wrote: > > > + "bitbake.pathToBuildFolder": "##BUILDDIR##", > Ideally there would be a generic template (as the one here) which is > used by default for all build configurations. > > But the .vscode configuration can also be much more specific. The best > would be to do something in the middle from what my patches do and what > you suggest: Take the .vscode templates from a user specific folder if > there is one, otherwise take the default one which is found in poky. > Currently this is possible with sym-links on the user side but I agree > that this could be better (without sym-links). > > I will send a v3 which will improve that. In the other thread the following format for multiple build dirs was proposed: "bitbake.environments": [ { "name": "product1", "pathToBuildFolder": "${workspaceFolder}/build_product1", "sshTarget": "root@192.168.7.2", }, { "name": "product2", "pathToBuildFolder": "${workspaceFolder}/build_product2", "bitbake.shellEnv": { "BB_ENV_PASSTHROUGH": "MACHINE", "MACHINE": "product2" }, "sshTarget": "root@192.168.7.3", } With that in mind, I think it's not longer possible to copy a template file with macro replacement, and something more sophisticated is needed that would adjust bitbake.environments in a file that may already exist? Alex
diff --git a/meta-poky/conf/templates/default/vscode/settings.json.sample b/meta-poky/conf/templates/default/vscode/settings.json.sample new file mode 100644 index 00000000000..4439f5f5c5c --- /dev/null +++ b/meta-poky/conf/templates/default/vscode/settings.json.sample @@ -0,0 +1,47 @@ +{ + "bitbake.pathToBitbakeFolder": "##OEROOT##/bitbake", + "bitbake.pathToBuildFolder": "##BUILDDIR##", + "bitbake.pathToEnvScript": "##OEINIT##/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/**" + ] +} \ No newline at end of file diff --git a/scripts/oe-setup-builddir b/scripts/oe-setup-builddir index dfd9acbb2cf..10c813788d2 100755 --- a/scripts/oe-setup-builddir +++ b/scripts/oe-setup-builddir @@ -59,6 +59,8 @@ if [ -n "$TEMPLATECONF" ]; then OECORELOCALCONF="$TEMPLATECONF/local.conf.sample" OECOREDESCRCONF="$TEMPLATECONF/conf-description.txt" OECORENOTESCONF="$TEMPLATECONF/conf-notes.txt" + VSCODE_SETTINGS_CONF="$TEMPLATECONF/vscode/settings.json.sample" + VSCODE_EXTENSIONS_CONF="$TEMPLATECONF/vscode/extensions.json" fi unset SHOWYPDOC @@ -114,11 +116,52 @@ if [ ! -r "$BUILDDIR/conf/conf-notes.txt" ]; then [ ! -r "$OECORENOTESCONF" ] || cp "$OECORENOTESCONF" "$BUILDDIR/conf/conf-notes.txt" fi +# If VSCode is installed generate a reasonable configuration +if command -v code > /dev/null; then + # Ensure VSCode does not try to index $BUILDDIR and ends up with an OOM exception. + # Configure also the yocto-bitbake extension to work. + if [ -z "$VSCODE_SETTINGS_CONF" ]; then + VSCODE_SETTINGS_CONF="$OEROOT/meta/conf/templates/default/vscode/settings.json.sample" + fi + if [ ! -r "$OEINIT/.vscode/settings.json" ] && [ -f "$VSCODE_SETTINGS_CONF" ]; then + cat <<EOM +You had no .vscode/settings.json file. This configuration file has therefore been +created for you from $VSCODE_SETTINGS_CONF. + +EOM + mkdir -p "$OEINIT/.vscode" + sed -e "s|##OEINIT##|$OEINIT|g" \ + -e "s|##OEROOT##|$OEROOT|g" \ + -e "s|##BUILDDIR##|$BUILDDIR|g" \ + \ + -e "s|\"$OEINIT|\"\${workspaceFolder}|g" \ + "$VSCODE_SETTINGS_CONF" > "$OEINIT/.vscode/settings.json" + SHOWYPDOC=yes + fi + + # Support also recommending extensions for VSCode. + if [ -z "$VSCODE_EXTENSIONS_CONF" ]; then + VSCODE_EXTENSIONS_CONF="$OEROOT/meta/conf/templates/default/vscode/extensions.json" + fi + if [ ! -r "$OEINIT/.vscode/extensions.json" ] && [ -f "$VSCODE_EXTENSIONS_CONF" ]; then + cat <<EOM +You had no .vscode/extensions.json file. This configuration file has therefore been +created for you from $VSCODE_EXTENSIONS_CONF. + +EOM + mkdir -p "$OEINIT/.vscode" + cp "$VSCODE_EXTENSIONS_CONF" "$OEINIT/.vscode" + SHOWYPDOC=yes + fi +fi + # Prevent disturbing a new GIT clone in same console unset OECORELOCALCONF unset OECORELAYERCONF unset OECOREDESCRCONF unset OECORENOTESCONF +unset VSCODE_SETTINGS_CONF +unset VSCODE_EXTENSIONS_CONF # Ending the first-time run message. Show the YP Documentation banner. if [ -n "$SHOWYPDOC" ]; then
Provide a reasonable default configuration for VSCode and the yocto.bitbake extension as it is provided by templates. The configuration is only generated if VSCode is installed. Currently, VSCode is one of many popular editors for Yocto/OE. Removing the check for code would result in the .vscode configuration being generated by e.g. oe-selftest or for users not using VSCode. If it should prove useful, the check can be removed later. Supporting different layers and build folder structures is supported e.g. by overriding the oe-init-build-env script and the templates in a custom layer. Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com> --- .../default/vscode/settings.json.sample | 47 +++++++++++++++++++ scripts/oe-setup-builddir | 43 +++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 meta-poky/conf/templates/default/vscode/settings.json.sample