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

Error when ninja is not in PATH (but ninja can be executed by cmake) #4042

Closed
emmenlau opened this issue Sep 4, 2024 · 15 comments · May be fixed by #4044
Closed

Error when ninja is not in PATH (but ninja can be executed by cmake) #4042

emmenlau opened this issue Sep 4, 2024 · 15 comments · May be fixed by #4044
Labels
more info needed More info is needed from the community for us to properly triage and investigate.

Comments

@emmenlau
Copy link

emmenlau commented Sep 4, 2024

Brief Issue Summary

We have a slightly special setup, where we wrap cmake in a wrapper script (via cmake.cmakePath). The wrapper script helps us to isolate certain parts of the build system that should be configured in a specific way. All that is working well, however in recent versions of this extension, we started to get errors of the form:

[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT

Indeed we do not have ninja in the path. When our wrapper script is called with arguments for the build, it will put ninja on the path, so it can be found. But on a plain shell, ninja is not available.

Is that something that can be considered, or worked around?

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.92.2",
  "cmtVersion": "1.19.50",
  "configurations": [
    {
      "folder": "/home/memmenlauer/BDA/Src/BDAPipelineProcessing",
      "cmakeVersion": "3.30.2",
      "configured": false,
      "generator": "",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log

No response

Additional Information

No response

@github-actions github-actions bot added the triage label Sep 4, 2024
@gcampbell-msft
Copy link
Collaborator

@emmenlau What does this result in? Is it blocking the use of your scenario?

What do you have set for cmake.generator and cmake.preferredGenerators?

@gcampbell-msft
Copy link
Collaborator

@emmenlau Additionally, what version does this start to happen on ?

To investigate, we'd need the version that this started happening on, and then some way to reproduce this, whether it's an example project or detailed repro steps.

@gcampbell-msft
Copy link
Collaborator

@JVApen @emmenlau If you could provide some more information about this issue, that would be great. For example, repro steps to reproduce this, or a small exacmple of a script you're using.

Looking at the code, nothing between version 1.18.44 and 1.19.50 was changed when checking the cmake.exe, so I wouldn't expect that it's causing an issue. Therefore, more investigation may be needed and any repro steps can help with that. Thanks!

Copied from #4037

@Yingzi1234
Copy link
Collaborator

@emmenlau Could you follow the steps below step-by-step to check if your settings are working? If the problem is still reproduced can you provide us with the exact steps and documentation of the reproduction, it would be very beneficial to our investigation. Thank you!

  1. Check the PATH environment variables
    Make sure that the and commands are available in the shell you are using. You can check this by running the following command in the terminal:ninjaninja-build
which ninja
which ninja-build

If these commands do not return a path, the tools may not be installed, or their paths may not have been properly added to the environment variables.PATH

  1. Update path in the environment
    If the and tools are installed in a non-standard location, you'll need to make sure that they're set up correctly in your shell environment. You can set this by adding the following line to your wrapper script:ninjaninja-buildPATHPATH

export PATH=/path/to/ninja:$PATH
Make sure to replace with the actual path of ./path/to/ninjaninja

  1. Verify the wrapper script
    Check your wrapper script to make sure it has the environment variable set correctly, and that the script does find and when run.PATHninjaninja-build

  2. CMake configure
    Confirm that the build tool is configured correctly in the configuration file. You can use the following command to verify that Ninja is set up correctly as a generator:CMake

cmake -G Ninja
This will ensure that CMake knows to use Ninja as a build system.

  1. VSCode configure
    The CMake tool diagnostics you mentioned indicate that you're building with VSCode. Make sure that VSCode's CMake is configured correctly and that its environment is consistent with that in the terminal. You can check the path configuration of CMake in VSCode's settings:

  2. Open VSCode's Settings ().settings.json

  3. Make sure that the path in is set correctly.cmake.configureSettings
    For example:

json
Copy code
{
  "cmake.configureSettings": {
    "CMAKE_MAKE_PROGRAM": "/path/to/ninja"
  }
}

@Yingzi1234 Yingzi1234 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Sep 5, 2024
@emmenlau
Copy link
Author

emmenlau commented Sep 5, 2024

Dear @Yingzi1234 ,
thanks a lot for your super detailed reply!!!

However, some of the things you are asking is already known. Sadly, I do not have ninja in the PATH, and I can not have ninja in the PATH! This is important for my setup, because we choose certain build parameters dynamically, before cmake is invoked. I achieve this with the following steps:

  • I set cmake.cmakePath in vscode to a script C:\my\wrapper\script\for\cmake.bat.
  • In this script, we choose certain parameters for cmake dynamically, for example the target environment for the build.
  • In the same script, based on these parameters, we set up PATH so that it contains the correct build tools, including ninja
  • Then the script invokes the actual cmake with the parameters

Therefore my answers are:

  1. Check the PATH environment variables

I know that ninja is not in the PATH variable, and I can not add it to the PATH variable, because it depends on parameters that are unknown beforehand.

  1. Update path in the environment

I know that ninja is not in the PATH variable, and I can not add it to the PATH variable, because it depends on parameters that are unknown beforehand.

  1. Verify the wrapper script

The wrapper script works and builds successfully. We use it hundreds of times a day, since many months, on many different platforms and machines.

  1. CMake configure

The build works via the wrapper script, including the cmake configure step.

  1. VSCode configure
    The CMake tool diagnostics you mentioned indicate that you're building with VSCode. Make sure that VSCode's CMake is configured correctly and that its environment is consistent with that in the terminal. You can check the path configuration of CMake in VSCode's settings:
  2. Open VSCode's Settings ().settings.json
  3. Make sure that the path in is set correctly.cmake.configureSettings
    For example:
json
Copy code
{
  "cmake.configureSettings": {
    "CMAKE_MAKE_PROGRAM": "/path/to/ninja"
  }
}

We do indeed work with VSCode. But we can not set the path to ninja in a hard-coded way. We put ninja on the PATH only in the moment when cmake is executed.

@emmenlau
Copy link
Author

emmenlau commented Sep 5, 2024

A simple reproducer is something like this:

  • Set cmake.cmakePath to C:\my\wrapper\script\for\cmake.bat
  • Create C:\my\wrapper\script\for\cmake.bat with the following content:
@ECHO OFF

REM Change PATH according to certain build parameters, to put the correct tools in PATH.
REM This makes the one or other version of ninja available.
REM Then execute cmake:

C:\path\to\cmake.exe %*

@gcampbell-msft
Copy link
Collaborator

@emmenlau When trying to reproduce with these steps: #4042 (comment), I notice that the "Bad CMake executable" popup appears in 1.18.44 as well. Do you also see this?

@gcampbell-msft
Copy link
Collaborator

@emmenlau I've tracked the issue down. This didn't come from a CMake Tools update, but rather a VS Code update. In July, VS Code updated to 1.92 which now uses Node 20. This contains a breaking change for spawn, which we weren't aware of.

Could you please test the vsix (after modifying the file extension from .zip to .vsix) from here?
#4044 (comment)

@emmenlau
Copy link
Author

emmenlau commented Sep 5, 2024

I'll test it later today, thanks a lot for the great investigation!!!

@emmenlau
Copy link
Author

emmenlau commented Sep 5, 2024

With #4037 out of the way, this small issue remains: I'm still getting the error (or warning):

[driver] Trying to detect generator supported by system
[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT

Aside from that, the build works fine, and I do not know if this error/warning has a high significance? It would be nice if you could check that there is no underlying problem when ninja can not be detected, so basically, make sure that checking for ninja is optional?

Or does cmake-tools need to know about ninja?

@gcampbell-msft
Copy link
Collaborator

@emmenlau That issue is coming from the fact that it's trying to detect a preferred generator, possibly with default preferredgenerators, if you haven't set this setting and you're not using the unspecified kit. Then, it shows this if it can't find it.

However, this can be worked around by setting the cmake.generator setting if you know you'll be using Ninja

@emmenlau
Copy link
Author

emmenlau commented Sep 5, 2024

However, this can be worked around by setting the cmake.generator setting if you know you'll be using Ninja

That sounds like a very suitable workaround! However I fail to get this to work. I'm setting

"cmake.generator": "Ninja",

in my VSCode user settings, but after closing and re-opening VSCode, the error message persists :-(
Also, adding cmake.preferredGenerators does not help. Am I doing something wrong?

@gcampbell-msft
Copy link
Collaborator

@emmenlau Ah, I hadn't created the vsix on the most recent code, please re-download the vsix from the PR and try again. THanks!

@emmenlau
Copy link
Author

emmenlau commented Sep 5, 2024

All issues fixed!!! Great work!!!

Should we close the issues, or do you want to wait for the release of the PR?

@gcampbell-msft
Copy link
Collaborator

They should close when the PR gets merged. Then, @emmenlau @JVApen, you should switch to the pre-release version in order to get the fix approximately one day after the PR merges. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed More info is needed from the community for us to properly triage and investigate.
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

3 participants