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 454 forks source link

cmake.buildTask does not warn when there is no default build task available #2417

Open ingomueller-net opened 2 years ago

ingomueller-net commented 2 years ago

Brief Issue Summary

I have just set up VSCode and CMake tools for a relatively complex project (LLVM). When I run "CMake: Build Target" (for any target), I get the following output but nothing is actually built:

[main] Building folder: XXX
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build YYY/build --config Debug --target all -j 98 --
[build] Build finished with exit code 0

To find out what is happening, I have replaced /usr/bin/cmake with a script that records each invocation including its command line parameters to a new file and then calls the original CMake binary with the same parameters:

#!/usr/bin/bash

stamp=$(date +%M%S%N)

echo -- "$@" > /tmp/cmake-cmd-$stamp
env > /tmp/cmake-env-$stamp

/usr/bin/cmake.bak "$@"

In that complex project, the only calls to cmake have the parameters -- --version -- no actual build is run (which confirms what I observe in the output window). If I run the command that is said is run manually, it build the project as expected. Also, if I use VSCode+CMake tools with a smaller project, everything works fine, including the tracing to my wrapper script (i.e., I observe calls to CMake that invoke the build target).

I do not know how to debug this further.

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.65.0",
  "cmtVersion": "1.9.2",
  "configurations": [
    {
      "folder": "XXX",
      "cmakeVersion": "3.22.1",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/usr/bin/cc",
        "CXX": "/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///XXX/AAA/Main.cpp"
    ],
    "responses": [
      {
        "uri": "file:///XXX/AAA/Main.cpp",
        "configuration": {
          "defines": [
            "BUILD_EXAMPLES",
            "GTEST_HAS_RTTI=0",
            "_DEBUG",
            "_GNU_SOURCE",
            "__STDC_CONSTANT_MACROS",
            "__STDC_FORMAT_MACROS",
            "__STDC_LIMIT_MACROS"
          ],
          "standard": "c++17",
          "includePath": [
            "ZZZ"
          ],
          "compilerPath": "/usr/bin/c++",
          "compilerArgs": [
            "-fPIC",
            "-fno-semantic-interposition",
            "-fvisibility-inlines-hidden",
            "-Werror=date-time",
            "-Wall",
            "-Wextra",
            "-Wno-unused-parameter",
            "-Wwrite-strings",
            "-Wcast-qual",
            "-Wno-missing-field-initializers",
            "-pedantic",
            "-Wno-long-long",
            "-Wimplicit-fallthrough",
            "-Wno-maybe-uninitialized",
            "-Wno-class-memaccess",
            "-Wno-redundant-move",
            "-Wno-pessimizing-move",
            "-Wno-noexcept-type",
            "-Wdelete-non-virtual-dtor",
            "-Wsuggest-override",
            "-Wno-comment",
            "-Wmisleading-indentation",
            "-fdiagnostics-color",
            "-g",
            "-fno-exceptions",
            "-fno-rtti",
            "-std=c++17"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 4450,
    "executablesCount": 298,
    "librariesCount": 830,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "never",
      "configureOnOpen": false
    }
  ]
}

Debug Log

Also with CMake tracing, we see that the command should be called but isn't. (Note that I shortened the output after Found index files.)

[extension] [4190] cmake.build started
[main] Building folder: iree-llvm-sandbox 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build IteratorsUnitTests
[proc] Executing command: /usr/bin/cmake --build /XXX/build --config Debug --target IteratorsUnitTests -j 98 --
[cmakefileapi-parser] Read reply folder: /XXX/build/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["very", "very" "long", "list"]
[driver] Run _refreshExpansions
[driver] Run _refreshExpansions cb
[cache] Reading CMake cache file /XXX/build/CMakeCache.txt
[cache] Parsing CMake cache string
[build] Build finished with exit code 0
bobbrow commented 2 years ago

What happens when you execute that same command in the terminal? /usr/bin/cmake --build /XXX/build --config Debug --target IteratorsUnitTests -j 98 --

ingomueller-net commented 2 years ago

It compiles as intended (and my wrapper script traces the execution as expected).

bobbrow commented 2 years ago

Where are you getting LLVM from? I don't see IteratorsUnitTests in LLVM-project. I'd like to make sure I'm using the same project as you so we can try to reproduce this.

ingomueller-net commented 2 years ago

That target is from a small project I started working on. I am still in the middle of integrating it into the CMake infrastructure. However, any target from that repo is affected, i.e., if I build all, or any other target, I run into the same problem.

bobbrow commented 2 years ago

I'm not super familiar with how external projects hook into LLVM. Do I just need to add the two args mentioned in the error text to my configuration (starting at the root of llvm-project)?

Do any of the targets in llvm-project build correctly for you?

EDIT: I see I missed the build instructions a few folders up. Do you build with or without IREE?

ingomueller-net commented 2 years ago

I have checked out llvm-project in a separate directory and then run the configure.py script, which sets up CMake to combine the two repos as described in the [README]. I don't understand the exact mechanisms of how this "combining" works, though.

bobbrow commented 2 years ago

Is there a special way to configure python to make this work that's not documented in the readme? I cloned your project and llvm-project, ran the python commands in the readme to set up the venv, then ran configure, and it seems that my verison of argparse is incompatible?

image

Any hints as to how to configure this?

ingomueller-net commented 2 years ago

What Python version are you using? BooleanOptionalAction seems to have been introduced in Python 3.9 (see here), so if that attribute is not found, chances are that you are using an older version. If you don't want to upgrade, you can probably just delete the corresponding line (or replace with action="store_true",).

ingomueller-net commented 2 years ago

I just found out that my problem disappears if I remove the line "cmake.buildTask": true from settings.json. I also found that somebody else reported a similar behavior here. To be honest, I don't know how that line ended up in my config.

Looking at the translation of some UI strings (where does that UI show up?), I am guessing that that option disables the use of the CMake build process. So, if not running cmake is intentional, the output should also not say that it will run it...

bobbrow commented 2 years ago

I was on vacation last week and am slowly catching back up. I had whatever version of python matches the Ubuntu 20.04 LTS. I didn't attempt to upgrade it. Good to know for future issues.

cmake.buildTask will tell VS Code to run your default build task (which runs in the Terminal panel) instead of having us spawn the process and pipe the output into the Output panel. If you do not have a default build task configured, that would explain why nothing happened. I think we should do some investigation into whether we can detect that there is no default build task and provide a warning of some kind for this case. Thank you for following up.

ingomueller-net commented 2 years ago

What is also really weird is that the following line shows up in the log even though that command isn't actually run:

[proc] Executing command: /usr/bin/cmake --build /XXX/build --config Debug --target IteratorsUnitTests -j 98 --