Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake-tools-kits environmentSetupScript having no effect on env.PATH variable #4091

Open
KorkiFork opened this issue Sep 23, 2024 · 8 comments
Labels
bug a bug in the product Feature: kits
Milestone

Comments

@KorkiFork
Copy link

Brief Issue Summary

Tested with: CMake Tools v1.20.10 (pre-release). All prior versions, released within the last year or two, had the same issue.

In the cmake-tools-kits file, if a kit has an environmentSetupScript which modifies the system PATH, and if in the same kit the environmentVariables object sets the variable PATH to have the value ${env.PATH}, the resulting PATH value will equal the PATH value prior to calling the environmentSetupScript.
TL;DR environmentSetupScript does not effect the value returned by ${env.PATH}.

E.g.
I used MSVC build tools 2017 v14.16, but any other MSVC build tools version can be taken (2019, 2022 etc.) and installed it on the default location.
In the kit description, I explicitly set CMAKE_MAKE_PROGRAM to the path of nmake.exe in order to simplify this example (please ignore why I had to do this, just take it as it is).

If any of the below two kits is used with the example CMakeLists.txt I provided below, during the project's build tree configuration, a STATUS message will be printed, which will contain the value of the system PATH variable.
If the "MSVC kit A" is used, the printed PATH variable will contain directories that have been added by the environmentSetupScript.
If the "MSVC kit B" is used, the printed PATH variable will NOT contain directories that should have been added by the environmentSetupScript, but it will contain the system PATH value prior to calling the environmentSetupScript.

cmake-tools-kits.json

{
  {
    "name": "MSVC kit A",
    "description": " ",
    "environmentSetupScript": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Auxiliary/Build/vcvarsall.bat",
    "preferredGenerator":
    {
      "name": "NMake Makefiles"
    },
    "cmakeSettings":
    {
      "CMAKE_MAKE_PROGRAM": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/nmake.exe"
    },
    "keep": true,
    "isTrusted": true
  },
  {
    "name": "MSVC kit B",
    "description": " ",
    "environmentSetupScript": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Auxiliary/Build/vcvarsall.bat",
    "preferredGenerator":
    {
      "name": "NMake Makefiles"
    },
    "environmentVariables":
    {
      "PATH": "${env.PATH}"
    },
    "cmakeSettings":
    {
      "CMAKE_MAKE_PROGRAM": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/nmake.exe"
    },
    "keep": true,
    "isTrusted": true
  }
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.14.0)

message(STATUS "PATH variable value is: $ENV{PATH}")

project(Test_project)

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

@Yingzi1234
Copy link
Collaborator

@KorkiFork We are trying to reproduce your issue, but have a problem finding “MSVC kit A” and “MSVC kit B”, could you provide us with a reproduction folder? This will help us a lot in reproducing and investigating the issue, thank you!
image

@Yingzi1234 Yingzi1234 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Sep 24, 2024
@KorkiFork
Copy link
Author

cmake-tools-kits.json

I attached the cmake-tools-kits.json file, please try using it.

(Sorry for closing and reopening issue, not sure how this comment system works, it is a bit strange).

@Yingzi1234
Copy link
Collaborator

Never mind I've reopened this issue, could you provide us with a project that can reproduce the issue? It's not just the cmake-tools-kits.json file, we can't reproduce the issue by adding the cmkae-tools-kits.json file to our project.

@Yingzi1234 Yingzi1234 reopened this Sep 24, 2024
@KorkiFork
Copy link
Author

I already provide you a CMake project via a CMakeLists.txt in my original post (please check my first post again, below the kits definition, there is also a CMakeLists.txt file).

@Yingzi1234 Yingzi1234 removed the triage label Sep 25, 2024
@KorkiFork
Copy link
Author

KorkiFork commented Sep 26, 2024

Hi @Yingzi1234,
Thank you very much for the effort of recording the video.

I noticed that your cmake-tools.kits.json has errors (as you can see for example on lines 2 and 16, which are underlined with red markings). Because the cmake-tools.kits.json file has errors, the CMake Tools extension can't load it, and it will still display the old kits (kits that have been loaded the last time when the cmake-tools-kits.json file was valid).

The cmake-tools-kits.json I provided you starts and ends with square brackets "[" ... "]", on line 1 and 36, but yours starts and ends with curly brackets "{" ... "}". Could you please try correcting this? I just realized that in my initial post, I also added curly brackets by mistake in lines 1 and 36, I'm sorry for that. Those should be square brackets.

@KorkiFork
Copy link
Author

@Yingzi1234 Hi again.

I'm not sure why the kits are not recognized for you. Maybe you don't edit them in you user folder?
Anyway. Here is the video that demonstrates that my VS Code and the CMake extensions does recognize them.

01.mp4

Further, I realized that my example is not correct is some cases and I won't configure the project at all.
I had to adapt it in the following way:

  • I replace the environmentSetupScript path in my kits to point to "vcvars64.bat" instead of "vcvarsall.bat".
  • I added path to nmake.exe to my system PATH, in my case this being the path "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64"
  • I removed the "cmakeSettings" property from my kits.

After I made those adaptations, I recorder the example of the PATH variable having different values with kit A and B.

02.mp4

@Yingzi1234
Copy link
Collaborator

Hi @KorkiFork , thank you very much for your reply, the reason for the failure to reproduce may be due to the name of the file. We have now been able to reproduce your issue on the latest CMake tool version v1.20.10(pre-release). You can get the detailed steps to reproduce it below.
@gcampbell-msft We were able to reproduce this issue on the latest version, and we have added the bug label to this issue, you can get the exact reproduction steps and reproduction information from below, thanks!

ENV:
C/C++: V1.21.6
CMake tools: v1.20.10(pre-release)
VSCode: 1.93.1

Repro steps:

  1. Open this folder Test.zip with VSCode
  2. Click F1 to run command "CMake: select a kit"
  3. Select "MSVC kit A" and then click F1 to run "CMake: Configrue"
  4. Go to output window to check the PATH variable value
  5. Re-select kit to "MSVC kit B" and re-run "CMake: configure"
  6. Go to output window to check the PATH variable value

Actual result:
MSVC kit A correctly reflects the impact of environment Setup Script, while MSVC kit B does not

Output log:
MSVC kit A:
[cmake] -- PATH variable value is: C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33721\bin\HostX86\x86;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\;C:\Program Files\Microsoft Visual Studio\2022\Preview\Team Tools\DiagnosticsHub\Collector;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\\x86;C:\Program Files (x86)\Windows Kits\10\bin\\x86;C:\Program Files\Microsoft Visual Studio\2022\Preview\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\msys64\mingw64\bin;C:\ProgramData\chocolatey;C:\msys64\ucrt64\bin;C:\msys64\mingw64\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe;C:\Users\v-cathyzhang\Downloads\ninja-win\ninja.exe;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Git\cmd;C:\Users\v-cathyzhang\AppData\Local\Microsoft\WindowsApps;C:\Users\v-cathyzhang\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\v-cathyzhang\.dotnet\tools;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\vcpkg

MSVC kit B:
[cmake] -- PATH variable value is: C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.40.33721/bin/HostX86/x86;C:/Program Files/Microsoft Visual Studio/2022/Preview\Common7\IDE\VC\VCPackages;C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:/Program Files/Microsoft Visual Studio/2022/Preview/MSBuild/Current/bin/Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\;C:/Program Files/Microsoft Visual Studio/2022/Preview/Team Tools/DiagnosticsHub/Collector;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console;C:/Program Files (x86)/Windows Kits/10/bin/10.0.22621.0\\x86;C:/Program Files (x86)/Windows Kits/10/bin\\x86;C:\Program Files\Microsoft Visual Studio\2022\Preview\\MSBuild\Current\Bin\amd64;C:/Windows/Microsoft.NET/Framework/v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\;C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/Tools/;C:\Windows\system32;C:/Windows;C:\Windows\System32\Wbem;C:/Windows/System32/WindowsPowerShell/v1.0/;C:\Windows\System32\OpenSSH\;C:/msys64/mingw64/bin;C:\ProgramData\chocolatey;C:/msys64/ucrt64/bin;C:\msys64\mingw64\bin;C:/ProgramData/chocolatey/bin;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe;C:\Users\v-cathyzhang\Downloads\ninja-win\ninja.exe;C:/Program Files/Microsoft SQL Server/130/Tools/Binn/;C:\Program Files\Git\cmd;C:/Users/v-cathyzhang/AppData/Local/Microsoft/WindowsApps;C:\Users\v-cathyzhang\AppData\Local\Programs\Microsoft VS Code\bin;C:/Users/v-cathyzhang/.dotnet/tools;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja;C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/vcpkg

@Yingzi1234 Yingzi1234 added bug a bug in the product and removed more info needed More info is needed from the community for us to properly triage and investigate. labels Sep 26, 2024
@KorkiFork
Copy link
Author

@Yingzi1234 Thank you very much for the support and patience.

I will be glad to see this bug being resolved in the future.

@gcampbell-msft gcampbell-msft added this to the Backlog milestone Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product Feature: kits
Projects
Status: Pending Prioritization
Development

No branches or pull requests

3 participants