microsoft / microsoft/vscode-cmake-tools

Environment of sourcing '.bashrc' is not working sometimes in cmake-tools on Linux

Open
#3,705 28 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: other investigation needed more info needed
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

Brief Issue Summary

Recently, I tried to use find_program to find some 3rd-party tools installed on my Kubuntu 22.04 system. For example:

hwhsu1231@vb-kubuntu:~$ which node && which po4a && which mdbook && which jekyll && which crowdin
/home/hwhsu1231/.nvm/versions/node/v20.12.1/bin/node
/home/hwhsu1231/perl5/bin/po4a
/home/hwhsu1231/.cargo/bin/mdbook
/home/hwhsu1231/gems/bin/jekyll
/home/hwhsu1231/.nvm/versions/node/v20.12.1/bin/crowdin
hwhsu1231@vb-kubuntu:~$ echo $PATH
/home/hwhsu1231/.nvm/versions/node/v20.12.1/bin:/home/hwhsu1231/perl5/bin:/home/hwhsu1231/.cargo/bin:/home/hwhsu1231/anaconda3/condabin:/home/hwhsu1231/gems/bin:/home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts
hwhsu1231@vb-kubuntu:~$

However, I found that sometimes cmake-tools cannot find those tools due to the incorrect value of $PATH.

Click to expand the full log
[main] Configuring project: demo-cmake-tools-bashrc 
[proc] Executing command: /usr/bin/cmake -S/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc -B/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default
[cmake] -- ----------------------------------------
[cmake] -- JEKYLL_EXECUTABLE   = JEKYLL_EXECUTABLE-NOTFOUND
[cmake] -- NODE_EXECUTABLE     = NODE_EXECUTABLE-NOTFOUND
[cmake] -- PO4A_EXECUTABLE     = PO4A_EXECUTABLE-NOTFOUND
[cmake] -- MDBOOK_EXECUTABLE   = MDBOOK_EXECUTABLE-NOTFOUND
[cmake] -- CROWDIN_EXECUTABLE  = CROWDIN_EXECUTABLE-NOTFOUND
[cmake] -- ENV{SHELL}          = /bin/bash
[cmake] -- ENV{BASH_VERSION}   = 
[cmake] -- ENV{PATH}           = /home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts
[cmake] -- File "/home/hwhsu1231/.bashrc" exists.
[cmake] -- ----------------------------------------
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default

As we can see, those tools cannot be found by find_program() due to the ENV{PATH}.

But it is working when I configuring the cmake project directly on the command-line:

Click to expand the full log
hwhsu1231@vb-kubuntu:~/Repo/testing/demo-cmake-tools-bashrc$ cmake --preset default
-- ----------------------------------------
-- JEKYLL_EXECUTABLE   = /home/hwhsu1231/gems/bin/jekyll
-- NODE_EXECUTABLE     = /home/hwhsu1231/.nvm/versions/node/v20.12.1/bin/node
-- PO4A_EXECUTABLE     = /home/hwhsu1231/perl5/bin/po4a
-- MDBOOK_EXECUTABLE   = /home/hwhsu1231/.cargo/bin/mdbook
-- CROWDIN_EXECUTABLE  = /home/hwhsu1231/.nvm/versions/node/v20.12.1/bin/crowdin
-- ENV{SHELL}          = /bin/bash
-- ENV{BASH_VERSION}   = 
-- ENV{PATH}           = /home/hwhsu1231/.nvm/versions/node/v20.12.1/bin:/home/hwhsu1231/perl5/bin:/home/hwhsu1231/.cargo/bin:/home/hwhsu1231/gems/bin:/home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts
-- File "/home/hwhsu1231/.bashrc" exists.
-- ----------------------------------------
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default
hwhsu1231@vb-kubuntu:~/Repo/testing/demo-cmake-tools-bashrc$ 

I can't tell how to reproduce this phenomenon exactly because it just happened randomly. (At least, I haven't found the step yet.)

After testing several times, I can be certain of the following points:

  1. Rebooting will definitely resolve the issue.
  2. Closing all VSCode windows, restarting, and reopening the project folder may not always solve the issue.
  3. I highly suspect that it is related to .bashrc since the environments of those 3rd-party tools are configured by .bashrc.

You can see the demo project here: demo-cmake-tools-bashrc

CMake Tools Diagnostics
{
  "os": "linux",
  "vscodeVersion": "1.88.0",
  "cmtVersion": "1.18.21",
  "configurations": [
    {
      "folder": "/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc",
      "cmakeVersion": "3.29.2",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": true,
      "compilers": {
        "C": "/usr/bin/cc",
        "CXX": "/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [
      ""
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}
Debug Log
[expand] expanding cmake
[main] Configuring project: demo-cmake-tools-bashrc 
[main] Saving open files before configure/build
[expand] expanding /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc
[driver] Start configure 
[driver] Running pre-configure checks and steps
[expand] expanding /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc
[cmakefileapi-driver] Configuring using preset
[cmakefileapi-driver] Invoking CMake /usr/bin/cmake with arguments ["-S/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc","-B/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default"]
[proc] Executing command: /usr/bin/cmake -S/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc -B/home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default
[proc]   with environment: {"BAMF_DESKTOP_FILE_HINT":"/var/lib/snapd/desktop/applications/code_code.desktop","CHROME_DESKTOP":"code-url-handler.desktop","CLUTTER_IM_MODULE":"xim","CONDA_EXE":"/home/hwhsu1231/anaconda3/bin/conda","CONDA_PYTHON_EXE":"/home/hwhsu1231/anaconda3/bin/python","CONDA_SHLVL":"0","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1000/bus","DESKTOP_SESSION":"plasma","DISPLAY":":0","ELECTRON_NO_ATTACH_CONSOLE":"1","GDK_BACKEND":"x11","GDK_PIXBUF_MODULEDIR":"/snap/code/156/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders","GDK_PIXBUF_MODULE_FILE":"/home/hwhsu1231/snap/code/common/.cache/gdk-pixbuf-loaders.cache","GEM_HOME":"/home/hwhsu1231/gems","GIO_MODULE_DIR":"/home/hwhsu1231/snap/code/common/.cache/gio-modules","GPG_AGENT_INFO":"/run/user/1000/gnupg/S.gpg-agent:0:1","GSETTINGS_SCHEMA_DIR":"/home/hwhsu1231/snap/code/156/.local/share/glib-2.0/schemas","GTK2_RC_FILES":"/etc/gtk-2.0/gtkrc:/home/hwhsu1231/.gtkrc-2.0:/home/hwhsu1231/.config/gtkrc-2.0","GTK_EXE_PREFIX":"/snap/code/156/usr","GTK_IM_MODULE":"fcitx","GTK_IM_MODULE_FILE":"/home/hwhsu1231/snap/code/common/.cache/immodules/immodules.cache","GTK_PATH":"/snap/code/156/usr/lib/x86_64-linux-gnu/gtk-3.0","GTK_RC_FILES":"/etc/gtk/gtkrc:/home/hwhsu1231/.gtkrc:/home/hwhsu1231/.config/gtkrc","HOME":"/home/hwhsu1231","IM_CONFIG_PHASE":"1","KDE_APPLICATIONS_AS_SCOPE":"1","KDE_FULL_SESSION":"true","KDE_SESSION_UID":"1000","KDE_SESSION_VERSION":"5","LANG":"zh_TW.UTF-8","LANGUAGE":"zh_TW:zh","LESSCLOSE":"/usr/bin/lesspipe %s %s","LESSOPEN":"| /usr/bin/lesspipe %s","LOCPATH":"/snap/code/156/usr/lib/locale","LOGNAME":"hwhsu1231","NO_AT_BRIDGE":"1","NVM_BIN":"/home/hwhsu1231/.nvm/versions/node/v20.12.1/bin","NVM_DIR":"/home/hwhsu1231/.nvm","NVM_INC":"/home/hwhsu1231/.nvm/versions/node/v20.12.1/include/node","ORIGINAL_XDG_CURRENT_DESKTOP":"KDE","PAM_KWALLET5_LOGIN":"/run/user/1000/kwallet5.socket","PATH":"/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts","PERL5LIB":"/home/hwhsu1231/perl5/lib/perl5","PERL_LOCAL_LIB_ROOT":"/home/hwhsu1231/perl5","PERL_MB_OPT":"--install_base \"/home/hwhsu1231/perl5\"","PERL_MM_OPT":"INSTALL_BASE=/home/hwhsu1231/perl5","PWD":"/home/hwhsu1231","QT_ACCESSIBILITY":"1","QT_AUTO_SCREEN_SCALE_FACTOR":"0","QT_IM_MODULE":"fcitx","QT_SCREEN_SCALE_FACTORS":"eDP-1=1.25;HDMI-1=1.25;","SESSION_MANAGER":"local/vb-kubuntu:@/tmp/.ICE-unix/1664,unix/vb-kubuntu:/tmp/.ICE-unix/1664","SHELL":"/bin/bash","SHLVL":"0","SNAP":"/snap/code/156","SNAP_ARCH":"amd64","SNAP_COMMON":"/var/snap/code/common","SNAP_CONTEXT":"kijkWCs7JnmzDCTDq05aweyAhfPjHP0MF6wiP3AvTp7QFro8uO9M","SNAP_COOKIE":"kijkWCs7JnmzDCTDq05aweyAhfPjHP0MF6wiP3AvTp7QFro8uO9M","SNAP_DATA":"/var/snap/code/156","SNAP_EUID":"1000","SNAP_INSTANCE_NAME":"code","SNAP_LAUNCHER_ARCH_TRIPLET":"x86_64-linux-gnu","SNAP_LIBRARY_PATH":"/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void","SNAP_NAME":"code","SNAP_REAL_HOME":"/home/hwhsu1231","SNAP_REVISION":"156","SNAP_UID":"1000","SNAP_USER_COMMON":"/home/hwhsu1231/snap/code/common","SNAP_USER_DATA":"/home/hwhsu1231/snap/code/156","SNAP_VERSION":"5c3e652f","SSH_AGENT_PID":"1542","SSH_AUTH_SOCK":"/tmp/ssh-XXXXXXmiD05n/agent.1482","SYSTEMD_EXEC_PID":"1465","USER":"hwhsu1231","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CLI":"1","VSCODE_CODE_CACHE_PATH":"/home/hwhsu1231/.config/Code/CachedData/5c3e652f63e798a5ac2f31ffd0d863669328dc4c","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"/home/hwhsu1231","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"/run/user/1000/vscode-6090bad7-1.88-main.sock","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"zh-tw\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_PID":"2563455","XAUTHORITY":"/home/hwhsu1231/.Xauthority","XCURSOR_SIZE":"24","XCURSOR_THEME":"breeze_cursors","XDG_CONFIG_DIRS":"/home/hwhsu1231/.config/kdedefaults:/etc/xdg/xdg-plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings","XDG_CONFIG_DIRS_VSCODE_SNAP_ORIG":"/home/hwhsu1231/.config/kdedefaults:/etc/xdg/xdg-plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings","XDG_CURRENT_DESKTOP":"KDE","XDG_DATA_DIRS":"/home/hwhsu1231/snap/code/156/.local/share:/home/hwhsu1231/snap/code/156:/snap/code/156/usr/share:/usr/share/plasma:/usr/local/share:/usr/share:/var/lib/snapd/desktop","XDG_DATA_DIRS_VSCODE_SNAP_ORIG":"/usr/share/plasma:/usr/local/share:/usr/share:/var/lib/snapd/desktop","XDG_RUNTIME_DIR":"/run/user/1000","XDG_SEAT":"seat0","XDG_SEAT_PATH":"/org/freedesktop/DisplayManager/Seat0","XDG_SESSION_CLASS":"user","XDG_SESSION_DESKTOP":"KDE","XDG_SESSION_ID":"3","XDG_SESSION_PATH":"/org/freedesktop/DisplayManager/Session1","XDG_SESSION_TYPE":"x11","XDG_VTNR":"1","XMODIFIERS":"@im=fcitx","_":"/snap/code/156/usr/share/code/code","ELECTRON_RUN_AS_NODE":"1","VSCODE_L10N_BUNDLE_LOCATION":"","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"1"}
[cmake] -- ----------------------------------------
[cmake] -- JEKYLL_EXECUTABLE   = JEKYLL_EXECUTABLE-NOTFOUND
[cmake] -- NODE_EXECUTABLE     = NODE_EXECUTABLE-NOTFOUND
[cmake] -- PO4A_EXECUTABLE     = PO4A_EXECUTABLE-NOTFOUND
[cmake] -- MDBOOK_EXECUTABLE   = MDBOOK_EXECUTABLE-NOTFOUND
[cmake] -- CROWDIN_EXECUTABLE  = CROWDIN_EXECUTABLE-NOTFOUND
[cmake] -- ENV{SHELL}          = /bin/bash
[cmake] -- ENV{BASH_VERSION}   = 
[cmake] -- ENV{PATH}           = /home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts
[cmake] -- File "/home/hwhsu1231/.bashrc" exists.
[cmake] -- ----------------------------------------
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default
[cmakefileapi-parser] Read reply folder: /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-1cab305b0ac598f51502.json","cmakeFiles-v1-433ee4f7cbd39281ace5.json","codemodel-v2-3efc49006ed6009c1bfe.json","directory-.-f5ebdc15457944623624.json","index-2024-04-13T15-05-01-0846.json","toolchains-v1-7096c62e23c342eb06a8.json"]
[expand] expanding cmake
[cache] Reading CMake cache file /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default/CMakeCache.txt
[expand] expanding cmake
[cache] Parsing CMake cache string
[expand] expanding cmake
[extension] [4482] cmake.configure finished (returned 0)
[expand] expanding cmake
[cache] Reading CMake cache file /home/hwhsu1231/Repo/testing/demo-cmake-tools-bashrc/out/build/default/CMakeCache.txt
[cache] Parsing CMake cache string
Additional Information

my-bashrc-and-profile.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CMake Tools configure path shown in the debug log and compare the environment passed to /usr/bin/cmake with the command-line environment. Use the linked demo-cmake-tools-bashrc project to investigate the intermittent PATH difference around .bashrc and VS Code restarts. Done means the cause is reproducible and the extension consistently supplies the expected environment, with coverage or documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, linux, typescript, vscode
Domain
build-system, developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.