vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Propagates selected target from one VSCode instance into another VSCode instance even if there is no such target there

Open MartinsSmirnovs opened this issue 1 year ago • 9 comments

Brief Issue Summary

If you have two different projects opened in two different VSCode instances, using dev containers, and both of these projects have same exact absolute path, then selected CMake target in first VSCode instance will be propagated into second VSCode instance, usually breaking next build, as there is no such target in the second instance.

Prerequisites

ms-vscode-remote.remote-containers extension installed in VSCode.

Steps to reproduce

I have created repository to reproduce this bug.

  1. $ git clone https://github.com/MartinsSmirnovs/cmake_tools_same_path_bug.git
  2. $ code dir1 && code dir2
  3. In both VSCode instances execute >Dev Containers: Rebuild and Reopen in Container to open the projects in Docker containers.
  4. In both VSCode instances execute >CMake: Configure and select Debug configuration if such question pops up.
  5. In one of VSCode instances select available example* CMake target.
  6. Now go to the second VSCode instance and press Build.
  7. Observe the error that CMake cannot build the target you have selected in another VSCode instance, e.g.:
[main] Building folder: code 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /code/out/build/Debug --target example_2
[build] gmake: *** No rule to make target 'example_2'.  Stop.
[proc] The command: /usr/bin/cmake --build /code/out/build/Debug --target example_2 exited with code: 2
[driver] Build completed: 00:00:00.015
[build] Build finished with exit code 2

despite the fact that there is no such target in the project you were trying to build. You can see it in respective CMakeLists.txt file.

What is known

I believe that the bug comes from the fact that in .devcontainer/devcontainer.json configuration both projects use same absolute path /code as workspace directory.

CMake Tools Diagnostics

From example_2 instance:

{
  "os": "linux",
  "vscodeVersion": "1.84.2",
  "cmtVersion": "1.15.31",
  "configurations": [
    {
      "folder": "/code",
      "cmakeVersion": "3.22.1",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": true,
      "compilers": {
        "C": "/usr/bin/cc",
        "CXX": "/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "example_2",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

From example instance:

{
  "os": "linux",
  "vscodeVersion": "1.84.2",
  "cmtVersion": "1.15.31",
  "configurations": [
    {
      "folder": "/code",
      "cmakeVersion": "3.22.1",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": true,
      "compilers": {
        "C": "/usr/bin/cc",
        "CXX": "/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "example",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

From example_2 instance:

[main] Building folder: code 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build example_2
[proc] Executing command: /usr/bin/cmake --build /code/out/build/Debug --target example_2
[proc]   with environment: {"HOSTNAME":"65cf6799b24a","HOME":"/home/developer","PATH":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","VSCODE_AGENT_FOLDER":"/home/developer/.vscode-server","SHELL":"/bin/bash","PWD":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e","VSCODE_HANDLES_SIGPIPE":"true","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","REMOTE_CONTAINERS_IPC":"/tmp/vscode-remote-containers-ipc-6338bcd1-0095-4b40-9d2a-e8e22de28dc5.sock","LS_COLORS":"","REMOTE_CONTAINERS_SOCKETS":"[\"/tmp/vscode-ssh-auth-6338bcd1-0095-4b40-9d2a-e8e22de28dc5.sock\",\"/tmp/.X11-unix/X0\"]","SHLVL":"1","_":"/usr/bin/cat","SSH_AUTH_SOCK":"/tmp/vscode-ssh-auth-6338bcd1-0095-4b40-9d2a-e8e22de28dc5.sock","DISPLAY":":0","REMOTE_CONTAINERS_DISPLAY_SOCK":"/tmp/.X11-unix/X0","XDG_RUNTIME_DIR":"/tmp/user/1000","WAYLAND_DISPLAY":"vscode-wayland-4fad9280-21dc-4896-a6ef-d30dd666b31d.sock","REMOTE_CONTAINERS":"true","BROWSER":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/helpers/browser.sh","VSCODE_CWD":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/tmp/user/1000/vscode-ipc-16c7cb9d-19bb-4a5c-9e13-85e64347bf66.sock","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"1","VSCODE_L10N_BUNDLE_LOCATION":""}
[build] [100%] Built target example_2
[driver] Build completed: 00:00:00.039
[cmakefileapi-parser] Read reply folder: /code/out/build/Debug/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-148bf883f59bf292b4ab.json","cmakeFiles-v1-f4d8f676b5e1a771884a.json","codemodel-v2-eebfe514908abb96c35f.json","directory-.-Debug-f5ebdc15457944623624.json","index-2023-11-13T10-53-52-0697.json","target-example_2-Debug-35324a15e8a1a7dade9f.json","toolchains-v1-99265b04de7ada3aac9e.json"]
[build] Build finished with exit code 0
[cache] Reading CMake cache file /code/out/build/Debug/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [7514] cmake.build finished (returned 0)
[cache] Reading CMake cache file /code/out/build/Debug/CMakeCache.txt
[cache] Parsing CMake cache string

From example instance:

[main] Building folder: code 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build example_2
[proc] Executing command: /usr/bin/cmake --build /code/out/build/Debug --target example_2
[proc]   with environment: {"HOSTNAME":"2ce4bf2a90bb","HOME":"/home/developer","PATH":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","VSCODE_AGENT_FOLDER":"/home/developer/.vscode-server","SHELL":"/bin/bash","PWD":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e","VSCODE_HANDLES_SIGPIPE":"true","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","REMOTE_CONTAINERS_IPC":"/tmp/vscode-remote-containers-ipc-db906aae-8766-4bba-82c2-c11cb2afc739.sock","LS_COLORS":"","REMOTE_CONTAINERS_SOCKETS":"[\"/tmp/vscode-ssh-auth-db906aae-8766-4bba-82c2-c11cb2afc739.sock\",\"/tmp/.X11-unix/X0\"]","SHLVL":"1","_":"/usr/bin/cat","SSH_AUTH_SOCK":"/tmp/vscode-ssh-auth-db906aae-8766-4bba-82c2-c11cb2afc739.sock","DISPLAY":":0","REMOTE_CONTAINERS_DISPLAY_SOCK":"/tmp/.X11-unix/X0","XDG_RUNTIME_DIR":"/tmp/user/1000","WAYLAND_DISPLAY":"vscode-wayland-07505f61-3439-4acf-ae26-32ffa9db704b.sock","REMOTE_CONTAINERS":"true","BROWSER":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/helpers/browser.sh","VSCODE_CWD":"/vscode/vscode-server/bin/linux-x64/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/tmp/user/1000/vscode-ipc-94349287-f52b-45dd-a994-1867b90215e7.sock","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"1","VSCODE_L10N_BUNDLE_LOCATION":""}
[build] gmake: *** No rule to make target 'example_2'.  Stop.
[proc] The command: /usr/bin/cmake --build /code/out/build/Debug --target example_2 exited with code: 2
[driver] Build completed: 00:00:00.011
[cmakefileapi-parser] Read reply folder: /code/out/build/Debug/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-755b24404b0b30eae0db.json","cmakeFiles-v1-e7d7c80ca50f5bae85ea.json","codemodel-v2-94beba8399fdbdab1378.json","directory-.-Debug-f5ebdc15457944623624.json","index-2023-11-13T10-54-14-0789.json","target-example-Debug-8a40020c94575c3e626b.json","toolchains-v1-99265b04de7ada3aac9e.json"]
[build] Build finished with exit code 2
[cache] Reading CMake cache file /code/out/build/Debug/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [4721] cmake.build finished (returned 2)
[cache] Reading CMake cache file /code/out/build/Debug/CMakeCache.txt
[cache] Parsing CMake cache string

Additional Information

If you close the second instance and then reopen it again, and press Build, the build will fail, and you will see that both instances will have the same target displayed on taskbars, despite such target not existing in the second instance.

image

MartinsSmirnovs avatar Nov 13 '23 11:11 MartinsSmirnovs