microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.47k stars 450 forks source link

CMake build from task not working after Open Folder #1595

Open stlkr opened 3 years ago

stlkr commented 3 years ago

Brief Issue Summary

As of fixing bug #1234, running CMake build from task is basically working, but not right after Open Folder command.

  1. Have a project with CMakeLists.txt in it's root directory.
  2. Have this in tasks.json:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CMake Build",
            "type": "cmake",
            "command": "build",
            "group": "build"
        }
    ]
}
  1. In launch.json:
    {
    "version": "0.2.0",
    "configurations": [
        {
            ...
            "preLaunchTask": "CMake Build"
            ...
        }
    ]
    }
  2. After opening the project using Open Folder command(also, in case it opens automatically at VSCode start), I press F5 key to build project and run it.

Expected:

Project to be built and run.

Apparent Behavior:

Got an error in output tab:

Error: The cmake task detection didn't contribute a task for the following configuration:
{
    "label": "CMake Build",
    "type": "cmake",
    "command": "build",
    "group": "build"
}
The task will be ignored.

But after I modify somehow tasks.json(e.g. enter space, delete it and save file), launch works as expected, task found successfully. If then I open some other folder, and then reopen the project folder again, CMake Build task recognition fail again.

Platform and Versions

Other Notes/Information

andreeis commented 3 years ago

Thank you for opening this report. Do you happen to have this setting cmake.configureOnOpen as false somewhere? At project, workspace or user level? Try again your scenario but make sure you configure before F5. You can configure either manually after opening the folder (via the cmake.configure command) or make sure you don't set configureOnOpen to false and it should happen automatically at project load time. But wait for configure to finish before pressing F5. Let us know. If it doesn't work this way either, then it's a bug and we will investigate.

stlkr commented 3 years ago

Well, you were right: cmake.configureOnOpen was not set. When I set it and after configuration finished, task worked properly.

But this is not very expected behaviour. Because project opening consists of two steps:

  1. Parse tasks.json in order to make tasks accessible;
  2. Configure project with "cmake ..." command.

Expected behaviour, in my opinion, is to run step 1 unconditionally on project open, and cmake.configureOnOpen must control the step 2.

andreeis commented 3 years ago

I totally see your point. That is why I am reactivating this report and triaging it with lower importance. The reason for needing a configure before having tasks available is in the implementation details (we need some APIs to be up and running and they are only after the first configure) and can be fixed with some redesign. Sometime we'll get to it.