As pre the documentation specifies, the "environmentSetupScript" option only accepts absolute paths. When I would like to access a setup script with ${workspaceFolder} variable, the script is neglected. If I replace the variable to hardcoded path, the setup script runs successfully. If I use the ${workspaceFolder} variable in any other option in the same file (for example in "toolchainFile"), the variable in expanded successfully.
${workspaceFolder} and other variables are expanded successfully in the "environmentSetupScript" option in the project cmake-kits.json file.
If I use the ${workspaceFolder} variable, the setup script does not run. If I replace the variable with a hardcoded path, the setup script runs successfully.
The "environmentSetupScript" option does not provide any logs, just fails.
Thank you!
This appears to have been an oversight. Tagging this for the next release.
`diff --git a/src/kit.ts b/src/kit.ts
index 6720255..af2d668 100644
--- a/src/kit.ts
+++ b/src/kit.ts
@@ -578,7 +578,7 @@ async function collectDevBatVars(devbat: string, args: string[], major_version:
* Gets the environment variables set by a shell script.
* @param kit The kit to get the environment variables for
*/
-export async function getShellScriptEnvironment(kit: Kit): Promise<Map<string, string>|undefined> {
+export async function getShellScriptEnvironment(kit: Kit, opts?: expand.ExpansionOptions): Promise<Map<string, string>|undefined> {
console.assert(kit.environmentSetupScript);
const filename = Math.random().toString() + (process.platform == 'win32' ? '.bat' : '.sh');
const script_filename = `vs-cmt-${filename}`;
@@ -588,12 +588,19 @@ export async function getShellScriptEnvironment(kit: Kit): Promise<Map<string, s
let script = '';
let run_command = '';
+
+ let environmentSetupScript = kit.environmentSetupScript + '';
+ if (opts) {
+ environmentSetupScript = await expand.expandString(environmentSetupScript, opts);
+ }
+
+ // environmentSetupScript = await expand.expandString(${kit.environmentSetupScript}, CMakeDriver.expansionOptions);
if (process.platform == 'win32') { // windows
- script += `call "${kit.environmentSetupScript}"\r\n`; // call the user batch script
+ script += `call "${environmentSetupScript}"\r\n`; // call the user batch script
script += `set >> ${environment_path}`; // write env vars to temp file
run_command = `call ${script_path}`;
} else { // non-windows
- script += `source "${kit.environmentSetupScript}"\n`; // run the user shell script
+ script += `source "${environmentSetupScript}"\n`; // run the user shell script
script +=`printenv >> ${environment_path}`; // write env vars to temp file
run_command = `/bin/bash -c "source ${script_path}"`; // run script in bash to enable bash-builtin commands like 'source'
}
@@ -864,7 +871,7 @@ export async function effectiveKitEnvironment(kit: Kit, opts?: expand.ExpansionO
}
}
if (kit.environmentSetupScript) {
- const shell_vars = await getShellScriptEnvironment(kit);
+ const shell_vars = await getShellScriptEnvironment(kit, opts);
if (shell_vars) {
host_env = util.map(shell_vars, ([k, v]): [string, string] => [k.toLocaleUpperCase(), v]) as [string, string][];
}
`
Hi @alan-wr
I have a similar problem to the one described by @Yaxley123 and I was wondering if your fix is also going to address my problem?
I'm using the Remote-SSH extension, and in my .vscode folder on the Linux remote host I have a cmake-kits.json file that contains:
[
{
"name" : "Tegra X1 Cross Compile",
"toolchainFile" : "${WorkspaceFolder}/TX1_toolchain.cmake"
}
]
This is the output I get at start-up:
[variant] Loaded new set of variants
[kit] Successfully loaded 5 kits from /home/pdulimov/.local/share/CMakeTools/cmake-tools-kits.json
[kit] Successfully loaded 1 kits from /home/dev/build/ASP/ASP/.vscode/cmake-kits.json
[main] Configuring folder: ASP
[proc] Executing command: /snap/bin/cmake -H/home/dev/build/ASP/ASP -B/home/dev/build/ASP/ASP/build -G "Unix Makefiles"
[expand] Invalid variable reference ${WorkspaceFolder} in string: -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${WorkspaceFolder}/TX1_toolchain.cmake
[proc] Executing command: /snap/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${WorkspaceFolder}/TX1_toolchain.cmake -H/home/dev/build/ASP/ASP -B/home/dev/build/ASP/ASP/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at /snap/cmake/513/share/cmake-3.18/Modules/CMakeDetermineSystem.cmake:99 (message):
[cmake] Could not find toolchain file: ${WorkspaceFolder}/TX1_toolchain.cmake
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:4 (project)
[cmake]
[cmake]
[cmake] CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
[cmake] CMake Error: CMAKE_CUDA_COMPILER not set, after EnableLanguage
[cmake] -- Configuring incomplete, errors occurred!
I guess I'm asking whether I need to file a separate bug report, or whether your change will address this.
Thank you for your time.
Regards,
Peter.
@amazingmo
Hi Peter,
The extension support workspaceFolder variable on kit's property toolchain file.
I see you use WorkspaceFolder, it should be workspaceFolder. ( The first char 'W' is a lowercase letter.)
I test it on local host, it is fine.
If there exists problem still, you can ping me.
I took out the ${WorkspaceFolder} variable and I can see that the toolchain file value is just being passed directly to CMake's -DCMAKE_TOOLCHAIN_FILE.
I'm assuming that this is the expected behaviour?
https://code.visualstudio.com/docs/editor/variables-reference
Predefined variables#
The following predefined variables are supported:
${workspaceFolder} - the path of the folder opened in VS Code
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${relativeFile} - the current opened file relative to workspaceFolder
${relativeFileDirname} - the current opened file's dirname relative to workspaceFolder
${fileBasename} - the current opened file's basename
${fileBasenameNoExtension} - the current opened file's basename with no file extension
${fileDirname} - the current opened file's dirname
${fileExtname} - the current opened file's extension
${cwd} - the task runner's current working directory on startup
${lineNumber} - the current selected line number in the active file
${selectedText} - the current selected text in the active file
${execPath} - the path to the running VS Code executable
${defaultBuildTask} - the name of the default build task
@alan-wr Thank you. I see it now.
Regards,
Peter.
@amazingmo
Hi Peter,
You are welcome.
This should be fixed in CMake Tools 1.5.0 which was published today.
Let us know if you encounter any issues with this release.