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

Allow alterations to the $PATH in an environmentSetupScript to take effect before searching for the CMake executable

Open bobbrow opened this issue 3 years ago • 3 comments

Discussed in https://github.com/microsoft/vscode-cmake-tools/discussions/2299

Currently the extension searches for the CMake executable before environmentSetupScript is evaluated. In the event that the setup script alters the $PATH, those changes won't be in effect when looking for the CMake binary.

bobbrow avatar Dec 27 '21 16:12 bobbrow

+1 for this feature -- I use a python virtual environment to install my desired cmake version, and I'd either need to activate that virtual environment (preferred) or modify the path to point cmake-tools at the correct binary.

wKavey avatar Jan 25 '22 05:01 wKavey

+1, There's unfortunately no documentation on environmentSetupScript and I expected it to run before the first call to cmake.

EmilVogt avatar Jul 08 '22 09:07 EmilVogt

I would not call this a clean solution, but this work for me on both Windows and Linux : I created a single script that can act both as batch and bash script. This script activate my virtual environment then call CMake.

.vsode/settings.json

  "cmake.cmakePath": "${workspaceFolder}/.vscode/run-cmake.cmd",

.vscode/run-cmake.cmd

:<<BATCH
    @echo off
    set SOURCE=%~dp0
    call %SOURCE%..\activate.bat
    @echo on
    call cmake %*
    @echo off
    exit /b
BATCH

SOURCE=$( realpath $( dirname -- "${BASH_SOURCE[0]}"; ); )
source $SOURCE/../activate.sh
cmake "$@"

jfchenier avatar Aug 05 '22 04:08 jfchenier

@jfchenier Thanks for you workaround. But I still get problem.

Now I create .vscode/run-cmake.cmd, just same as you and

linux-64 - ssh /buildarea/ashi/tmp_ws/z_cmake_failed_prj1/.vscode> /buildarea/ashi/tmp_ws/z_cmake_failed_prj1/.vscode/run-cmake.cmd Usage

cmake [options] cmake [options] cmake [options] -S -B

Specify a source directory to (re-)generate a build system for it in the current working directory. Specify an existing build directory to re-generate its build system.

Run 'cmake --help' for more information.

linux-64 - ssh /buildarea/ashi/tmp_ws/z_cmake_failed_prj1/.vscode> ./run-cmake.cmd -version cmake version 3.23.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Seems fine now, But still get error like

Bad CMake executable: "/buildarea/ashi/tmp_ws/z_cmake_failed_prj1/.vscode/run_cmake.cmd". Check to make sure it is installed or the value of the "cmake.cmakePath" setting contains the correct path

alan-wr avatar Oct 25 '22 07:10 alan-wr

+1, It is better to support environmentSetupScript and then call to cmake.

alan-wr avatar Oct 25 '22 07:10 alan-wr

@alan-wr

On some Linux distro, I had to add #!/bin/bash At the top of the run-cmake.cmd script. This cause an error message on Windows, but it can be ignored. Adding this might solve your issue.

jfchenier avatar Oct 25 '22 15:10 jfchenier

@jfchenier

Typo error

run_cmake.cmd from ".vscode/setting.json"

And run-cmake.cmd from ".vscode/run-cmake.cmd" file.

"_" and "-".

Anyway, fine now.

Many Thanks.

alan-wr avatar Oct 27 '22 01:10 alan-wr

Sorry @bobbrow, can I ask if there's currently any plan to support this feature?

Pesc0 avatar Jul 27 '23 22:07 Pesc0

From what I'm seeing I think this has to be modified to run environmentSetup script first: https://github.com/microsoft/vscode-cmake-tools/blob/aa2139531f2ff2bb390ab12beb56025f9efa27b4/src/paths.ts#L228

for reference here's how it's done for the kits: https://github.com/microsoft/vscode-cmake-tools/blob/aa2139531f2ff2bb390ab12beb56025f9efa27b4/src/kit.ts#L646

I don't know basically anything about typescript so I can't make a PR myself

adrianinsaval avatar Aug 02 '23 02:08 adrianinsaval

@Pesc0 @adrianinsaval and others, thanks for all of your comments. I am placing this on our backlog and we will work to prioritize this issue among our other bugs and requests. Thank you!

In the meantime, please up-vote this issue to let us know that it is important to you.

gcampbell-msft avatar Aug 02 '23 13:08 gcampbell-msft

Thank you!

Pesc0 avatar Aug 02 '23 13:08 Pesc0

@gcampbell-msft This would really simplify setting up the debugger for my VS code environment. I currently have a workaround but it is a hack.

astronomaestro avatar Aug 25 '23 23:08 astronomaestro

@benmcmorran Hey seeing you postponed this issue for the next release, can I please ask if it could get tackled for the current release cycle? Over at FreeCAD we are kinda depending on this to finally have proper integration with VSCode, and the work on that has been stalled for months now. Many thanks in advance :)

Pesc0 avatar Oct 13 '23 10:10 Pesc0