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

presets: setting cmake.buildToolArgs in configuration leads to build failures #3754

Closed
JeremieA opened this issue May 13, 2024 · 7 comments · Fixed by #3755
Closed

presets: setting cmake.buildToolArgs in configuration leads to build failures #3754

JeremieA opened this issue May 13, 2024 · 7 comments · Fixed by #3755
Labels
bug a bug in the product

Comments

@JeremieA
Copy link
Contributor

Brief Issue Summary

-- is missing in the cmake build command line.
Simple repro case attached (cmake-presets-build-tool-args.tar.gz)
Steps to reproduce:

  1. uncompress the archive
  2. open the folder with vscode
  3. configure & try to build with cmake => FAIL (see log below)
  4. remove either CMakePresets.json or .vscode/settings.json and try again => SUCCESS

CMake Tools Diagnostics

No response

Debug Log

[main] Building folder: cmake-presets-build-tool-args 
[main] Configuring project: cmake-presets-build-tool-args 
[driver] NOTE: You are configuring with preset Default Config, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: /usr/bin/cmake -S/home/jallard/cmake-presets-build-tool-args -B/home/jallard/cmake-presets-build-tool-args/build/default -G Ninja
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /home/jallard/cmake-presets-build-tool-args/build/default
[build] Starting build
[driver] NOTE: You are building with preset default, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: /usr/bin/cmake --build /home/jallard/cmake-presets-build-tool-args/build/default -n
[build] Unknown argument -n
[build] Usage: cmake --build <dir>             [options] [-- [native-options]]
[build]        cmake --build --preset <preset> [options] [-- [native-options]]
[build] Options:
[build]   <dir>          = Project binary directory to be built.
[build]   --preset <preset>, --preset=<preset>
[build]                  = Specify a build preset.
[build]   --list-presets[=<type>]
[build]                  = List available build presets.
[build]   --parallel [<jobs>], -j [<jobs>]
[build]                  = Build in parallel using the given number of jobs. 
[build]                    If <jobs> is omitted the native build tool's 
[build]                    default number is used.
[build]                    The CMAKE_BUILD_PARALLEL_LEVEL environment variable
[build]                    specifies a default parallel level when this option
[build]                    is not given.
[build]   -t <tgt>..., --target <tgt>...
[build]                  = Build <tgt> instead of default targets.
[build]   --config <cfg> = For multi-configuration tools, choose <cfg>.
[build]   --clean-first  = Build target 'clean' first, then build.
[build]                    (To clean only, use --target 'clean'.)
[build]   --resolve-package-references={on|only|off}
[build]                  = Restore/resolve package references during build.
[build]   -v, --verbose  = Enable verbose output - if supported - including
[build]                    the build commands to be executed. 
[build]   --             = Pass remaining options to the native tool.
[proc] The command: /usr/bin/cmake --build /home/jallard/cmake-presets-build-tool-args/build/default -n exited with code: 1
[driver] Build completed: 00:00:00.012
[build] Build finished with exit code 1

Additional Information

I already have a simple fix, will submit a PR...

JeremieA added a commit to JeremieA/vscode-cmake-tools that referenced this issue May 13, 2024
Fixes microsoft#3754.
This issue was introduced in microsoft#3537 (cmake.buildToolsArgs was ignored for presets before).
@Yingzi1234 Yingzi1234 added bug a bug in the product and removed triage labels May 16, 2024
@Yingzi1234
Copy link
Collaborator

@JeremieA Thank you for your GitHub issue! We are trying to reproduce your issue, but in the process we have the following problem and we wanted to check with you, is this the expected result?

Repro steps:

  1. Download and open this project(cmake-presets-build-tool-args.tar.gz) by VSCode
  2. Click F1 to run "CMake: Build" command
  3. Re-run "CMake: Build" command

Actual result:
Both builds fail with the following error in the output window

Output window:
[main] Building folder: cmake-presets-build-tool-args
[main] Configuring project: cmake-presets-build-tool-args
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" -SC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args -BC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args/build/default -G Ninja
[cmake] CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
[cmake] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" -SC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args -BC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args/build/default -G Ninja exited with code: 1
image

@JeremieA
Copy link
Contributor Author

@Yingzi1234 thanks for trying to reproduce it.
I should have mentioned that my repro case was only tested on Linux.

It should work on Windows by replacing the presets file with this version: CMakePresets.json
After updating the file and opening the folder in VSCode, the "Ninja/MSVC v143" configure preset needs to be selected.

Here is the output in this case:

[main] Building folder: cmake-presets-build-tool-args 
[main] Configuring project: cmake-presets-build-tool-args 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_C_COMPILER=cl -SF:/cmake-presets-build-tool-args -BF:/cmake-presets-build-tool-args/build/ninja_msvc -G "Ninja Multi-Config"
[cmake] -- The C compiler identification is MSVC 19.36.32534.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (1.5s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: F:/cmake-presets-build-tool-args/build/ninja_msvc
[build] Starting build
[driver] NOTE: You are building with preset ninja_msvc, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build F:/cmake-presets-build-tool-args/build/ninja_msvc -n
[build] Unknown argument -n
[build] Usage: cmake --build <dir>             [options] [-- [native-options]]
[build]        cmake --build --preset <preset> [options] [-- [native-options]]
[build] Options:
[build]   <dir>          = Project binary directory to be built.
[build]   --preset <preset>, --preset=<preset>
[build]                  = Specify a build preset.
[build]   --list-presets[=<type>]
[build]                  = List available build presets.
[build]   --parallel [<jobs>], -j [<jobs>]
[build]                  = Build in parallel using the given number of jobs. 
[build]                    If <jobs> is omitted the native build tool's 
[build]                    default number is used.
[build]                    The CMAKE_BUILD_PARALLEL_LEVEL environment variable
[build]                    specifies a default parallel level when this option
[build]                    is not given.
[build]   -t <tgt>..., --target <tgt>...
[build]                  = Build <tgt> instead of default targets.
[build]   --config <cfg> = For multi-configuration tools, choose <cfg>.
[build]   --clean-first  = Build target 'clean' first, then build.
[build]                    (To clean only, use --target 'clean'.)
[build]   --resolve-package-references={on|only|off}
[build]                  = Restore/resolve package references during build.
[build]   -v, --verbose  = Enable verbose output - if supported - including
[build]                    the build commands to be executed. 
[build]   --             = Pass remaining options to the native tool.
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build F:/cmake-presets-build-tool-args/build/ninja_msvc -n exited with code: 1
[driver] Build completed: 00:00:00.065
[build] Build finished with exit code 1

@Yingzi1234
Copy link
Collaborator

@gcampbell-msft @JeremieA We can reproduce this issue on latest version, you can get the details below.

ENV:
VSCode version: 1.89.1
CMake tools version: v1.18.39(pre-release)
C/C++ version: v1.20.5

Repro steps:

  1. Open this project cmake-presets-build-tool-args.zip with VSCode
  2. Click F1 to run "CMake: Build" command
  3. Select the configure preset "Ninja/MSVC v143"

Actual result:
The build will fail.

Output window:

[proc] The command: C:\Windows\System32\where.exe cl exited with code: 1
[preset] Configure preset ninja_msvc: No toolset version specified for cl.exe, using latest by default
[preset] Using developer environment from Visual Studio (instance fafbec2e, version 17.9.34902.65, installed at "C:\Program Files\Microsoft Visual Studio\2022\Community")
[proc] Executing command: chcp
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
[proc] The command: C:\Windows\System32\where.exe ninja exited with code: 1
[preset] Ninja is not set on PATH, trying to use C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe
[main] Configuring project: cmake-presets-build-tool-args 
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" -DCMAKE_C_COMPILER=cl "-SC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args" "-BC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc" -G "Ninja Multi-Config"
[cmake] -- The C compiler identification is MSVC 19.39.33523.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (10.4s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: C:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc
[main] Building folder: cmake-presets-build-tool-args 
[build] Starting build
[driver] NOTE: You are building with preset ninja_msvc, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --build "C:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc" -n
[build] Unknown argument -n
[build] Usage: cmake --build <dir>             [options] [-- [native-options]]
[build]        cmake --build --preset <preset> [options] [-- [native-options]]
[build] Options:
[build]   <dir>          = Project binary directory to be built.
[build]   --preset <preset>, --preset=<preset>
[build]                  = Specify a build preset.
[build]   --list-presets[=<type>]
[build]                  = List available build presets.
[build]   --parallel [<jobs>], -j [<jobs>]
[build]                  = Build in parallel using the given number of jobs. 
[build]                    If <jobs> is omitted the native build tool's 
[build]                    default number is used.
[build]                    The CMAKE_BUILD_PARALLEL_LEVEL environment variable
[build]                    specifies a default parallel level when this option
[build]                    is not given.
[build]   -t <tgt>..., --target <tgt>...
[build]                  = Build <tgt> instead of default targets.
[build]   --config <cfg> = For multi-configuration tools, choose <cfg>.
[build]   --clean-first  = Build target 'clean' first, then build.
[build]                    (To clean only, use --target 'clean'.)
[build]   --resolve-package-references={on|only|off}
[build]                  = Restore/resolve package references during build.
[build]   -v, --verbose  = Enable verbose output - if supported - including
[build]                    the build commands to be executed. 
[build]   --             = Pass remaining options to the native tool.
[proc] The command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --build "C:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc" -n exited with code: 1
[driver] Build completed: 00:00:00.431
[build] Build finished with exit code 1

gcampbell-msft added a commit that referenced this issue Jun 24, 2024
…3755)

* presets + cmake.buildToolArgs: make sure `--` is added in all cases

Fixes #3754.
This issue was introduced in #3537 (cmake.buildToolsArgs was ignored for presets before).

* Update changelog

---------

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>
gcampbell-msft added a commit that referenced this issue Jul 3, 2024
* reversed order of creating workspace browse configurations (#3758)

* reversed order of creating workspace browse configurations

* updated tests

* minimized change by only reversing fileGroups, and reverted tests

* Add clarity in the build log when builds are out of source (#3778)

* Add chesscc to the allow-list of compilers. (#3777)

Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>

* Fix doubling of cpack args passed by package preset (#3766)

* Remove unnecessary logging about string expansion (#3761)

* Remove unnecessary logging about string expansion

* Fix typo in var name

---------

Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>

* Fix UI for settings override of package presets (#3770)

* Fix UI for settings override of package presets

* Fix linter errors

* Skip full configure on variant change for multi-config generators (#3763)

* Don't fully configure after variant change for multi-config generators. Only change parameter for build and refresh IntelliSense.

* Added missing return on 'if else'

* Removed unnecessary log. No previous configure message was printed before it.'

* Run clean-configure when workflow has different configure preset than project (#3768)

* Let cmake.configureArgs overwrite the default cmake args (#3762)

Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>

* Handle "~" in binaryDir path (#3764)

* File system APIs don't recognize ~ in paths and because of this the extension cannot properly interpret cmake file-api jsons to list targets.

* Fix path typo

---------

Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>

* Warning when VS installation instance not found (#3775)

* Add warning about not found VS installation instance and suggestion to re-scan kits, at the request of developers in the community.

* Fix linter errors

---------

Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>

* Fix GitHub 3602, mention --build-config even for default test preset (#3779)

* Better validations that validate before running.  (#3774)

* initial commit

* add better values

* check notice and changelog before release version

* Update kits-variants doc with unsupported commands that are specific for presets (#3784)

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* colorization support in pre-release (#3794)

* colorization support in pre-release

* update changelog

* Sort CMakeLists.txt by depth (#3789)

* Sort CMakeLists.txt by depth

* Add changes to CHANGELOG.md

---------

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* Fixed string parameters and added clarification to the log message (#3787)

* Localization - Translated Strings (#3753)

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* fix schema field in v8 schema (#3809)

* Add check that limits when we -R a regex of all tests (#3814)

* fix ctest

* only try to be smart about this in the test explorer entry points

* updating comment

* add try catch in debug createRunProfile

* Localization - Translated Strings (#3816)

* Update CHANGELOG.md

* update localization for project status view and quick pick (#3810)

* fix issue with test results not found (#3823)

* update braces dependency (#3839)

* Fixes #3725 - user presets not read correctly (#3826)

* get all presets to show in inherit

* if new configure preset inherits from a user preset add to the user presets file

* todo: finish update for different types of presets

* checks for configure inherit and inherit. todo - check workflow

* cleanup + mark as isUserPreset

* undo use isuserpreset field

* cleanup and changelog

* cleanup

* rename interface

* update workflow preset to not extend preset + refactor inheritsfromuserpreset func

* remove preset class fields from workflow preset

* more workflow preset cleanup

* Fixes #3811 - checks for cmake.exe again if it wasnt present the previous time  (#3840)

checks for exe again if it wasn't present the previous time

* Tree view for tests using test suite delimiter (#3759)

* Implement treeview for tests using test suite delimiter

* Support regular expressions for delimiters

* Improve UI string

* Improve UI string

* Address CR comments

* Fix spacing

* make sure to pass entry point through

---------

Co-authored-by: Garrett Campbell <gcampbell@microsoft.com>
Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* Update telemetry API to latest version. (#3843)

* presets + cmake.buildToolArgs: make sure `--` is added in all cases (#3755)

* presets + cmake.buildToolArgs: make sure `--` is added in all cases

Fixes #3754.
This issue was introduced in #3537 (cmake.buildToolsArgs was ignored for presets before).

* Update changelog

---------

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* Update CHANGELOG.md

* Fixes #3140 - Test log unavailable (#3752)

* Using \r\n as line ending

Seems like \r\n is the line ending characters in the Test Output even on systems different from win32

* Specify the test item in the call to appendOutput

Doing so allows to have the output of the test to be printed out in the left part of the "TEST RESULTS" pane when clicking on the desired test in the right part of the same pane.
Before this change we get "The test case did not report any output"

* Adds location information in the call to appendOutput.

The test object may have uri and ranges that can help localization

* Adds entry in the CHANGELOG

---------

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* Upgrade cmake_minimum_required version 3.0.0 -> 3.5.0 (#3805)

* Update cmakeProject.ts

Upgrade cmake_minimum_required version 3.0.0 -> 3.5.0

* Update CHANGELOG.md

---------

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* Add setting for deleting whole build dir when clean configuring (#3783)

* Add setting for deleting whole build dir when clean configuring

* Remove unnecessary tag in new setting in package.json

* Add changelog entry. Remove unnecessary | null from new boolean setting.

---------

Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com>

* log error for cmake exe not found (#3847)

* Fixed how we use our '--warn-unused-cli' flag (#3860)

* '--warn-unused-cli' is now used to remove the default '--no-warn-unused-cli' command instead of removing and also adding itself to the arguments

* only removed '--warn--unused-cli' instead of all initial_common_flgs

* Set useCMakePresets context after quick start (#3853)

update active proj to set userpreset context

* remove from pre-release (#3861)

* clean configures when platform differs between old and new selected kit (#3859)

* clean configures when only platform changes between kits

* updated changelog

* check toolset too

* changelog

* update changelog

* add rel to branches (#3867)

---------

Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>
Co-authored-by: Andreea Isac <48239328+andreeis@users.noreply.github.com>
Co-authored-by: Joan Marcè i Igual <jmigual@users.noreply.github.com>
Co-authored-by: CSIGS@microsoft.com <csigs@users.noreply.github.com>
Co-authored-by: Fatima Qarni <fatimaqarni@microsoft.com>
Co-authored-by: vinocher-bc <160914867+vinocher-bc@users.noreply.github.com>
Co-authored-by: Bob Brown <bobbrow@users.noreply.github.com>
Co-authored-by: Jeremie Allard <jeremie.allard@insimo.fr>
Co-authored-by: hippo91 <guillaume.peillex@gmail.com>
Co-authored-by: LiuZengqiang <74355935+LiuZengqiang@users.noreply.github.com>
@Ashley-Li
Copy link
Collaborator

Ashley-Li commented Jul 9, 2024

Verified on CMake Tools v1.18.43(release), this issue was fixed:
image

@blackworm27
Copy link

FYI: This "fix" broke our build. In order to pass command line options to ninja, we were adding "--" to the command line using the setting "CMake: Build Tool Args". Now it is added twice, causing the build to fail. Perhaps it was a bug not to include it in the first place, but some users whose configuration worked around the issue may be left wondering why their builds suddenly fail.

@gcampbell-msft
Copy link
Collaborator

@blackworm27 Could you show me what you have as arguments in your "CMake: Build Tool Args"? Couldn't you simply remove the "--" from your defined arguments?

@blackworm27
Copy link

Couldn't you simply remove the "--" from your defined arguments?

Sorry if I was unclear. I have no current issue; I did indeed remove the extra "--" from the arguments when I diagnosed my broken build, and now can build without any problems. I only wanted to flag the fact that those who previously worked around this issue by manually adding "--" to the arguments, now face broken builds with the update, without necessarily understanding the cause. Perhaps the fix could be improved by checking for the presence of a manually-added "--" before automatically adding the "--".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

5 participants