none
PreLaunch task for VS2019 CMake Linux projects RRS feed

  • Question

  • Hello MSDN Community,

    We recently started to move one of our big CMake Linux projects to remote compilation using VS2019. It is an awesome feature for sure.

    However we are facing an issue I have already raised on this page (https://docs.microsoft.com/en-us/cpp/linux/deploy-run-and-debug-your-linux-project?view=vs-2019).

    Our project is enormous and requires a lot of environment variables to be set before being launched as well as argument values to be computed before being passed to our program at startup (for instance ./myProgram arg1 arg2 arg3 where some of argX needs to be computed on the spot at launch time). Both the env variables and the arguments can only be computed on Linux side.

    We were thinking there would be a kind of PreLaunch tasks which are available in VS Code if I am not wrong (https://stackoverflow.com/questions/35975641/could-not-find-the-prelaunch-task-build). Could they be used to run a script which sets the env variables and then would VS run gdb and our program in the same session where the env variables are still available? We could them have the env variables set properly and the arguments could just be computed and stored in env variables too. But we were not able to find those PreLaunch tasks in VS2019. Are they available or is there and way to achieve what we want to do?

    We ended up doing something hacky which was to change the pipeProgram in the launch.vs.json to run a script which in turns execute the script which set all the env variables and then launch gdb with the arguments it expects from VS (--tty and --interpreter). For instance:

    {
      "version": "0.2.1",
      "defaults": {},
      "configurations": [
        {
          "cwd": "${debugInfo.defaultWorkingDirectory}",
          "externalConsole": true,
          "MIMode": "gdb",
          "name": "OMS",
          "pipeTransport": {
            "debuggerPath": "${debugInfo.defaultWorkingDirectory}/../../scripts/myProgram arg1 arg2 arg3 -g -y --tty=${debugInfo.tty} -i ${debuggerCommand}",
            "pipeArgs": [
              "/s",
              "${debugInfo.remoteMachineId}",
              "/p",
              "${debugInfo.parentProcessId}",
              "/c"
            ],
            "pipeProgram": "${debugInfo.shellexecPath}"
          },.......}

    It is hacky and I am sure having a better support of this feature would help other big Linux projects to be migrated to VS which is a wonderful platform. If it is already supported then maybe have the how-to properly documented in some pages like the one mentioned above.

    Thank you in advance.

    Kind regards,

    Guillaume.

    Friday, September 27, 2019 1:25 PM

All replies

  • Hi gzorlee,

    Sorry for delay in reply.

    For your requirement, we recommend you could define custom environment variables globally or per-configuration in the environments property.

    // The "environments" property is an array of key value pairs of the form
    // { "EnvVar1": "Value1", "EnvVar2": "Value2" }
    "environments": [
        {
          "BuildDir": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build",
        }
      ],
    
    "configurations": [
        {
          "name": "x86-Debug",
          "generator": "Ninja",
          "configurationType": "Debug",
          // Inherit the defaults for using the MSVC x86 compiler.
          "inheritEnvironments": [ "msvc_x86" ],
          "buildRoot": "${env.BuildDir}\\${name}"    },
        {
          "name": "x64-Debug",
          "generator": "Ninja",
          "configurationType": "Debug",
          // Inherit the defaults for using the MSVC x64 compiler.
          "inheritEnvironments": [ "msvc_x64" ],
          "buildRoot": "${env.BuildDir}\\${name}"
        }
      ]

    Please refer more here: Environment variables for Cmake settings

    Hope it could help you.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, September 30, 2019 8:10 AM
  • Hello Dylan,

    Thank you for your answer. The problem still is that when Visual Studio runs I have no way to know the value of those env variable. They are determined by a script which is run dynamically on the Linux host where the program and gdb will be executed.

    Then after the execution of this script, which happens each time we run the program, the program is going to use the computed value stored in the env variables. For this is what I would like to do:

    1) You edit and do everything in VS on windows side (machine W). All good this works well :)

    2) You start the debug functionality on Visual Studio side (machine W). Again it works well.

    3) You store in TIME the time of the Linux system (machine L). Here I don't know how to do. There are a lot of env variables that need to be set. We are using a 500+ lines of code script full of if, read from file and from various locations.

    4) VS is launching and running the program (VS runs on machine W and run the program on machine L). The program running on L should have access to all the env variables set in 3) to start.

    5) The program on machine L is using the value of the TIME env which is now set.

    You see what I mean?

    Kind regards,

    Guillaume.

    Monday, September 30, 2019 9:07 PM
  • Hello,

    Just wanted to follow up on this query. This is a blocker for us unlike the other point I raised. Is there any way you could have a look at it please?

    Kind regards,

    Guillaume.

    Monday, October 7, 2019 1:49 PM
  • Hi gzorlee,

    Sorry for delay in reply.

    For your requirement, I'm sorry that there is no appropriate methods to implement it. I have asked MS c++ engineer, if there is any update, I will post it here.

    BTW, you could also post it to Github, and product team will provide support there.

    Thank you for understanding.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Tuesday, October 8, 2019 7:10 AM
  • Hey,

    Sorry I didn't see this before asking you the github thing on the other thread. Thank you for your answer.

    Kind regards,

    Guillaume.

    Tuesday, October 8, 2019 3:45 PM
  • Hi gzlorlee,

    Thank you for reply.

    For Cmake project getting env variables which are set in linux remote system, we recommend you could use environments array in CMakeSettings or use them in your CMake scripts by using the syntax $ENV{VAR}.

    Cheers,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, October 9, 2019 7:17 AM
  • Hey Dylan,

    Thank you very much. This is what I was looking for.

    Could you please let me know where this is documented. I should be able to find other interesting information around those pages.

    Kind regards,

    Guillaume.

    Wednesday, October 16, 2019 8:14 PM
  • Hi gzorlee,

    Thank you for reply.

    The documents I refer, is mainly from Microsoft doc and Cmake doc

    Hope it could help you.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Thursday, October 17, 2019 9:00 AM