microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.43k stars 429 forks source link

XDG_SESSION_ID and XDG_SESSION_TYPE environment in debugConfig.environment or console's environment are overrided by getConfigureEnvironment #3806

Open upcliujie opened 4 weeks ago

upcliujie commented 4 weeks ago

Brief Issue Summary

Problem 1: The workspace vcode settings : 图片

The code to get XDG_SESSION_ID and XDG_SESSION_TYPE environment with c++ : 图片 We can't get the XDG_SESSION_ID and XDG_SESSION_TYPE in debugConfig.environment.

Problem 2: Delete the worksapce vscode settings. Use tmux connect to another tty. Run the code in Problem 1: 图片

We can't get the same XDG_SESSION_ID and XDG_SESSION_TYPE environment value with tmux

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

v-frankwang commented 3 weeks ago

@upcliujie I tried the problem you described on my machine, but I was not able to reproduce the problem you described, can you give me some advice?

image

upcliujie commented 2 weeks ago

@v-frankwang The terminal on win don't set XDGSESSION* to env so don't have this problem.

Using a win PC to connect a linux PC by ssh-remote can reproduce this problem

upcliujie commented 2 weeks ago

@v-frankwang This is a relevant code from the cmakeProject.ts file

    /**
     * Both debugTarget and launchTarget called this funciton, so it's refactored out
     * Array.concat's performance would not beat the Dict.merge a lot.
     * This is also the point to fixing the issue #1987
     */
    async getTargetLaunchEnvironment(drv: CMakeDriver | null, debugEnv?: DebuggerEnvironmentVariable[]): Promise<Environment> {
        const env = util.fromDebuggerEnvironmentVars(debugEnv);

        // Add environment variables from ConfigureEnvironment.
        const configureEnv = await drv?.getConfigureEnvironment();

        if ((drv?.useCMakePresets ?? false) && (checkConfigureOverridesPresent(this.workspaceContext.config) ?? false)) {
            log.info(localize('launch.with.overrides', `NOTE: You are launching a target and there are some environment overrides being applied from your VS Code settings.`));
        }

        return EnvironmentUtils.merge([env, configureEnv]);
    }

XDFSESSION* is set in ConfigureEnvironment on linux so it will overwrite the environment we set in debugConfig.environment.

v-frankwang commented 2 weeks ago

@upcliujie Thank you very much for your reply, I have retried the problem as you have given advice, does this reproduce the problem you have described?

image

upcliujie commented 2 weeks ago

@v-frankwang Yes,it's the problem I described.

v-frankwang commented 1 week ago

@gcampbell-msft I reproduced the issue based on the user's prompts and here are the steps I took to reproduce it:

ENV: VS code version: 1.90.0 CMake Extension version: 1.18.42 Remote-ssh: v0.112.0

  1. Create a folder named Test on the remote linux machine.
  2. Using the Remote-ssh extension to connect to Linux machines in vscode.
  3. Open the folder named Test.
  4. Add the CMakeLists.txt file and add the following code:
    cmake_minimum_required(VERSION 3.8)
    project(test)
    add_executable(test main.cpp) 
  5. Add the main.cpp file and add the following code:
    
    #include <iostream>
    #include <cstdlib>

int main() { char xdgSessionId = getenv("XXDG_SESSION_ID"); if (xdgSessionId != nullptr) { std::cout << "XXDG_SESSION_ID: " << xdgSessionId << std::endl; } else { std::cout << "XXDG_SESSION_ID not set" << std::endl; } char xdgSessionType = getenv("XDG_SESSION_TYPE"); if (xdgSessionType != nullptr) { std::cout << "XDG_SESSION_TYPE: " << xdgSessionType << std::endl; } else { std::cout << "XDG_SESSION_TYPE not set" << std::endl; }

return 0;

}

6. Search for Cmake:debug Config in settings, then click Edit in settings.json and add the following code:

{ "cmake.debugConfig": { "environment": [ { "name": "XXDG_SESSION_ID", "value": "2" }, { "name": "XDG_SESSION_TYPE", "value": "wayland" } ] } }


7. Click on "**Launch the selected target in the terminal window**" in the navigation bar below.

Actual result:
![image](https://github.com/microsoft/vscode-cmake-tools/assets/160998958/202ae870-386d-4748-8c4c-f1eb48b51046)
v-frankwang commented 1 week ago

@upcliujie @gcampbell-msft If I manually set the value of XDG_SESSION_TYPE to "wayland" in the terminal using the command: export XDG_SESSION_TYPE=wayland, and then click the "Launch the selected target in the terminal window" in the navigation bar below, the correct result is displayed. image