Vscode-cmake-tools: Using command variables in task with CMake Tools

Created on 13 May 2020  路  9Comments  路  Source: microsoft/vscode-cmake-tools

Brief Issue Summary

Tried to use this in tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CMake Build",
            "command": "${command:cmake.build}",
            "type": "shell",
            "group": "build",
            "problemMatcher": []
        }
    ]
}

Or

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CMake Build All",
            "command": "${command:cmake.buildAll}",
            "type": "shell",
            "group": "build",
            "problemMatcher": []
        }
    ]
}

Expected:

CMake Tools to build project as when running "CMake: Build" or "CMake: BuildAll" command from command palette.

Apparent Behavior:

Got error:
For "CMake Build":

[rollbar] Unhandled exception: Unhandled Promise rejection: build TypeError: Cannot read property 'fsPath' of undefined {}

For "CMake Build All":

[rollbar] Unhandled exception: Unhandled Promise rejection: buildAll TypeError: str.replace is not a function {}

After "CMake Build All" task CMake tools becomes broken, and even from CMake side panel gives an error:

A CMake task is already running. Stop it before trying to build.

Platform and Versions

  • Operating System: Linux Mint 19
  • CMake Version: 3.5.1
  • VSCode Version: 1.38.1
  • CMake Tools Extension Version: 1.3.1
  • Compiler/Toolchain: arm-none-eabi-gcc 4.8
other fixed (release pending)

Most helpful comment

I think the example at the beginning of the issue (which you used) is the old way of attempting to do this.
Try to apply the below changes to your example and let us know how that works:
"command": "build",
"type": "cmake",

All 9 comments

It looks like the tasks pass in an unexpected argument to our commands.

Also, if(or when) command variable feature becomes working, it would be nice to publish the command IDs for CMake Tools somewhere in documentation. Because I wasn't able to find it anywhere except CMake Tools's sources.

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 I just tried this via:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CMake Build",
            "command": "${command:cmake.build}",
            "type": "shell",
            "group": "build",
            "problemMatcher": []
        }
    ]
} 

And it does not work. Running with CMake Tools 1.5.1. I get a notification saying:

Cannot substitute command variable 'cmake.build' because command did not return a result of type string.

The command seems to get printed, but it definitely doesn't execute:

[main] Building folder: openj9-openjdk-jdk8 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /openj9-openjdk-jdk8/build/linux-x86_64-normal-server-release/vm --config Debug --target all -- -j 18
[build] Build finished with exit code 0

Where as if I revert back to "cmake.buildTask": false I get:

[main] Building folder: openj9-openjdk-jdk8 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /openj9-openjdk-jdk8/build/linux-x86_64-normal-server-release/vm --config Debug --target all -- -j 18
[build] [  0%] Built target j9nls
[build] [  0%] Built target jpp
[build] [  0%] Built target pugixml
[build] [  1%] Built target j9vm_m4gen
[build] [  1%] Built target objectmodel
[build] [  1%] Built target trace
[build] [  2%] Built target ddrgentest
[build] [  2%] Built target j9jit_generate
[build] [  3%] Built target omr_ddr_ir
...
[build] [ 80%] Built target j9vrb
[build] [ 80%] Generating ut_j9jit.c, ut_j9jit.h, ut_j9jit.pdat
[build] [100%] Built target j9jit
[build] Build finished with exit code 0

Could we reopen this issue?

I think the example at the beginning of the issue (which you used) is the old way of attempting to do this.
Try to apply the below changes to your example and let us know how that works:
"command": "build",
"type": "cmake",

Thanks! That works great. Cheers!

I think the example at the beginning of the issue (which you used) is the old way of attempting to do this.
Try to apply the below changes to your example and let us know how that works:
"command": "build",
"type": "cmake",

Is there any list of "command" that are allowed for type "cmake"? I would like to create a configure or rebuild task but all I get is

Error: The cmake task detection didn't contribute a task for the following configuration:
{
    "label": "CMake build",
    "type": "cmake",
    "command": "configure",
    "problemMatcher": []
}

I tried to search the repo for allowed commands but no luck

I think the example at the beginning of the issue (which you used) is the old way of attempting to do this.
Try to apply the below changes to your example and let us know how that works:
"command": "build",
"type": "cmake",

Is there any list of "command" that are allowed for type "cmake"? I would like to create a configure or rebuild task but all I get is

Error: The cmake task detection didn't contribute a task for the following configuration:
{
    "label": "CMake build",
    "type": "cmake",
    "command": "configure",
    "problemMatcher": []
}

I tried to search the repo for allowed commands but no luck

@andreeis Can we use any other "command" than "build"? Is there any documentation about this feature?

No, currently only the build command. We'll look into hooking up more commands, possibly via this issue: https://github.com/microsoft/vscode-cmake-tools/issues/1601.
I'm referencing a documentation update for this in here: https://github.com/microsoft/vscode-cmake-tools/issues/1246.

Was this page helpful?
0 / 5 - 0 ratings