From: Adrian Freihofer <[email protected]>

VSCode searches for the .vscode/settings.json file in the workspace
folder and its parent folders. Or the other way round, VSCode needs to
be started in a folder which contains the .vscode/settings.json file.
With bitbake-setup the .vscode/settings.json file created by
oe-setup-vscode is located for example in
bitbake-builds/poky-master/layers/oe-init-build-env-dir/.vscode/settings.json.

Layers looks like this:
  bitbake
  logs
  meta-yocto
  oe-init-build-env-dir -> openembedded-core
  .oe-layers.json
  oe-scripts -> openembedded-core/scripts
  openembedded-core
  setup-build -> openembedded-core/scripts/oe-setup-build
  yocto-docs

Since oe-init-build-env-dir is a sym-link to openembedded-core the
.vscode folder is effectively located in openembedded-core/.vscode.

Starting VSCode in oe-init-build-env-dir picks up the settings.json
file correctly but the VSCode Bitake plugin cannot find bitbake. Bitbake
is located in a folder at the same level as openembedded-core. So the
path to bitbake is not anymore workspaceFolder/bitbake but ../bitbake
relative to the workspace folder.
To fix this, we now dynamically determine the actual location of
bitbake by using `which bitbake` and adjusting the
bitbake.pathToBitbakeFolder setting accordingly.

This minimal fix makes VSCode usable without running into issues with
OOM exceptions due to indexing the build folder or bitbake not found
errors.

But the user experience is still much worse than with the simple poky
layout. Only the openembedded-core layer is visible in the workspace
folder. The other layers are not visible which means this setup is not
really usable yet. The .vscode/settings.json file is created at the
wrong path. This should be improved in future iterations.

Signed-off-by: Adrian Freihofer <[email protected]>
---
 scripts/oe-setup-vscode | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/oe-setup-vscode b/scripts/oe-setup-vscode
index b8642780d5..6818641d42 100755
--- a/scripts/oe-setup-vscode
+++ b/scripts/oe-setup-vscode
@@ -22,13 +22,14 @@ fi
 
 VSCODE_SETTINGS=$VSCODEDIR/settings.json
 ws_builddir="$(echo "$BUILDDIR" | sed -e "s|$OEINIT|\${workspaceFolder}|g")"
+bb_dir="$(dirname "$(which bitbake)" | sed 's|/bin$||')"
 
 # 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.pathToBitbakeFolder": "$bb_dir",
     "bitbake.pathToEnvScript": "\${workspaceFolder}/oe-init-build-env",
     "bitbake.pathToBuildFolder": "$ws_builddir",
     "bitbake.commandWrapper": "",
-- 
2.52.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#228543): 
https://lists.openembedded.org/g/openembedded-core/message/228543
Mute This Topic: https://lists.openembedded.org/mt/116929994/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to