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

${workspaceFolder} is not working for "environmentSetupScript" option in project cmake-kits.json file #1309

Closed
Yaxley123 opened this issue Jun 15, 2020 · 9 comments
Labels
bug a bug in the product Feature: kits
Milestone

Comments

@Yaxley123
Copy link

Brief Issue Summary

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.

Expected:

${workspaceFolder} and other variables are expanded successfully in the "environmentSetupScript" option in the project cmake-kits.json file.

Apparent Behavior:

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.

CMake Tools Log

The "environmentSetupScript" option does not provide any logs, just fails.

Platform and Versions

  • Operating System: Windows 10
  • CMake Version: 3.12
  • VSCode Version: 1.46.0
  • CMake Tools Extension Version: 1.4.0
  • Compiler/Toolchain: GCC + MinGW

Thank you!

@bobbrow bobbrow added bug a bug in the product Feature: kits quick fix the fix is estimated to be quick labels Jun 29, 2020
@bobbrow bobbrow added this to the 1.5.0 milestone Jun 29, 2020
@bobbrow
Copy link
Member

bobbrow commented Jun 29, 2020

This appears to have been an oversight. Tagging this for the next release.

@alan-wr
Copy link
Contributor

alan-wr commented Aug 10, 2020

`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][];
     }
`

alan-wr added a commit to alan-wr/vscode-cmake-tools that referenced this issue Aug 10, 2020
… in project cmake-kits.json file microsoft#1309

Signed-off-by: alan-wr <aijun.shi@windriver.com>
@amazingmo
Copy link

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.

@alan-wr
Copy link
Contributor

alan-wr commented Aug 12, 2020

@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.

@amazingmo
Copy link

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?

@alan-wr
Copy link
Contributor

alan-wr commented Aug 12, 2020

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

@amazingmo
Copy link

@alan-wr Thank you. I see it now.
Regards,
Peter.

@alan-wr
Copy link
Contributor

alan-wr commented Aug 12, 2020

@amazingmo
Hi Peter,

You are welcome.

alan-wr added a commit to alan-wr/vscode-cmake-tools that referenced this issue Aug 22, 2020
… in project cmake-kits.json file microsoft#1309

Signed-off-by: alan-wr <aijun.shi@windriver.com>
andreeis added a commit that referenced this issue Oct 8, 2020
#1406)

* ${workspaceFolder} is not working for "environmentSetupScript" option in project cmake-kits.json file #1309

Signed-off-by: alan-wr <aijun.shi@windriver.com>

* Tool kit not update after create .vscode/cmake-kits.json on new workspace/folder. #1416

Signed-off-by: alan-wr <aijun.shi@windriver.com>

* ${workspaceFolder} is not working for "environmentSetupScript" option in project cmake-kits.json file #1309

Signed-off-by: alan-wr <aijun.shi@windriver.com>

* Fix string|undefined error

Co-authored-by: Andreea Isac <48239328+andreeis@users.noreply.github.com>
Co-authored-by: Andreea Isac <andris@microsoft.com>
@andreeis andreeis added fixed (release pending) and removed quick fix the fix is estimated to be quick labels Oct 8, 2020
@bobbrow bobbrow modified the milestones: 1.6.0, 1.5.0 Nov 5, 2020
@andreeis
Copy link
Contributor

andreeis commented Nov 5, 2020

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.

@andreeis andreeis closed this as completed Nov 5, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug a bug in the product Feature: kits
Projects
None yet
Development

No branches or pull requests

5 participants