Compare commits

...

4 Commits

Author SHA1 Message Date
Armin Veres dfdaab8f26
Merge 020b714faa into 4b23ecd62a 2026-06-17 12:07:53 +02:00
Shohei YOSHIDA 4b23ecd62a
Merge pull request #1275 from zsh-users/support_cppcheck_reporter
Support cppcheck-htmlreport
2026-06-15 09:07:51 +09:00
Shohei YOSHIDA 349ddcb4c0
Support cppcheck-htmlreport 2026-06-12 19:31:52 +09:00
Armin Richard Veres 020b714faa feat: add support for build-presets
When running `cmake --build --preset=*` the preset would not complete.
Additionally fix `cmake --build --preset=* --target=*` target completion
too, by looking for the first CMakeCache.txt in five levels of
directories.
2026-06-11 16:35:03 +02:00
2 changed files with 141 additions and 81 deletions

View File

@ -144,6 +144,29 @@ _cmake_generator_options() {
fi
}
# ----------------------
# _cmake_build_presets
# ----------------------
(( $+functions[_cmake_build_presets] )) ||
_cmake_build_presets() {
local list_presets=(${(f)"$(cmake --list-presets=build 2>/dev/null |
sed -n -e 's,^[[:space:]]*"\([^"]*\)"[[:space:]]*-[[:space:]]*\(.*\),\1:\2,p' \
-e 's,^[[:space:]]*"\([^"]*\)"[[:space:]]*$,\1,p')"})
_describe 'build presets' list_presets
}
# --------------------------
# _cmake_preset_build_dir
#
# Finds the build directory by locating the nearest CMakeCache.txt.
# --------------------------
(( $+functions[_cmake_preset_build_dir] )) ||
_cmake_preset_build_dir() {
find . -maxdepth 5 -name CMakeCache.txt -print -quit | xargs -I{} dirname {}
}
# --------------
# _cmake_presets
# --------------
@ -194,6 +217,8 @@ _cmake_on_build() {
'--config[For multi-configuration tools]'
'--parallel[maximum number of build processes]'
'--use-stderr'
'--preset[Specify a build preset]:preset:_cmake_build_presets'
'--list-presets[List available build presets]'
)
local -a undescribed_build_extras
local i=1
@ -226,23 +251,41 @@ _cmake_on_build() {
if [[ $words[(($i - 1))] == --target ]]; then continue ; fi
if [[ $words[(($i - 1))] == --config ]]; then continue ; fi
if [[ $words[(($i - 1))] == --parallel ]] ; then continue ; fi
if [[ $words[(($i - 1))] == --preset ]] ; then continue ; fi
out_of_build=true
done
if (( $dash_dash_position > 0 )) ; then
_cmake_generator_options $words[(($build_at + 1))] $dash_dash_position && return 0
local _build_first=$words[(($build_at + 1))]
[[ $_build_first != --* ]] && _cmake_generator_options $_build_first $dash_dash_position && return 0
fi
if [[ "$in_build" == false || "$difference" -eq 1 ]] ; then
# either there is no --build or completing the directory after --build
if [[ "$in_build" == false ]] ; then
# no --build seen, complete normally
_arguments -s \
- build_opts \
"$cmake_build_options[@]" \
- build_cmds \
"$cmake_suggest_build[@]" && return 0
elif [[ "$difference" -eq 1 ]] ; then
# completing first arg after --build: dir, --preset, or --list-presets
_alternative \
':current directory:(.)' \
'directory::_directories' \
'preset-flags:flag:((--preset\:"Specify a build preset" --list-presets\:"List available build presets"))' && return 0
elif [[ $words[(($CURRENT - 1))] == --preset ]] ; then
# after --build --preset, complete build presets
_cmake_build_presets && return 0
elif [[ $words[(($CURRENT - 1))] == --target ]] ; then
# after --build <dir> --target, suggest targets
_cmake_targets $words[(($build_at + 1))] && return 0
# after --build <dir|--preset name> --target, suggest targets
local _tgt_first=$words[(($build_at + 1))]
if [[ $_tgt_first == --preset ]]; then
local _tgt_dir=$(_cmake_preset_build_dir "$words[(($build_at + 2))]")
[[ -n "$_tgt_dir" ]] && _cmake_targets "$_tgt_dir"
elif [[ $_tgt_first != --* ]]; then
_cmake_targets "$_tgt_first"
fi
return 0
elif [[ $words[(($CURRENT - 1))] == --config ]] ; then
# after --build <dir> --config, no idea
return 0

View File

@ -1,4 +1,4 @@
#compdef cppcheck
#compdef cppcheck cppcheck-htmlreport
# ------------------------------------------------------------------------------
# Copyright (c) 2019 Github zsh-users - https://github.com/zsh-users
# All rights reserved.
@ -48,83 +48,100 @@ _cppcheck_files() {
_path_files -/ -g "*.(c|cpp|cxx|h|hpp|C)"
}
_cppcheck() {
local -a check_ids=(
all warning style performance portability information unusedFunction missingInclude
)
local -a platforms=(
unix32 unix64 win32A win32W win64 avr8 elbrus-e1cp pic8 pic8-enhanced pic16 mips32 native unspecified
)
local -a coding_standards=(
normal autosar cert-c-2016 cert-cpp-2016 misra-c-2012 misra-c-2023 misra-c-2025
misra-cpp-2008 misra-cpp-2023
)
_arguments \
"--addon=[Execute addon]" \
"--addon-python=[Specify the python interpreter]: :_files" \
"--cppcheck-build-dir=[Analysis output directory]:directory:_files -/" \
"--check-config[Check cppcheck configuration]" \
"--check-level=[Configure how much valueflow analysis you want]:level:(reduced normal exhaustive)" \
"--check-library[Show information when library files have incomplete info]" \
"--checkers-report=[Write a report of all the active checkers to the given file]:file:_files" \
"--clang=[Use clang parser instead of the builtin Cppcheck parser]: :_files" \
"--config-exclude=[Path to be excluded from configuration checking]:directory:_files -/" \
"--config-exclude-files=[A file that contains a list of config-excludes]:file:_files" \
"--doc[Print a list of all available checks]" \
'*--disable=[Disable individual checks]:id:($check_ids)' \
"--dump[Dump xml data for each translation unit]" \
"*-D[Define preprocessor symbol]:symbol" \
"-E[Print preprocessor output on stdout and don't do any further processing]" \
'--enable=[Enable additional checks]:id:($check_ids)' \
"--error-exitcode=[Integer to return if errors are found]" \
"--errorlist[Print a list of all the error messages in XML format]" \
"--exitcode-suppressions=[Used when certain messages should be displayed but should not cause a non-zero exitcode]:_files" \
"*--file-filter=[Analyze only those files matching the given filter str]:filter" \
"--file-list=[Specify the files to check in a text file]:file:_files" \
"(-f --force)"{-f,--force}"[Force checking of all configurations in files]" \
"(--fsigned-char --funsigned-char)--fsigned-char[Treat char type as signed]" \
"(--fsigned-char --funsigned-char)--funsigned-char[Treat char type as unsigned]" \
"(- 1 *)"{-h,--help}"[Print help]" \
"*-I[A file that contains a list of config-excludes]:directory:_files -/" \
"--include-file=[Specify directory paths to search for included header files in a text file]:file:_files" \
"--include=[Force inclusion of a file before the checked file]:file:_files" \
"-i[Give a source file or source file directory to exclude from the check]:directory or file:_files" \
"--inconclusive[Report even though the analysis is inconclusive]" \
"--inline-suppr[Enable inline suppressions]" \
"-j[Number of threads to do the checking simultaneously]::num" \
"-l[No new threads should be started if the load average is exceeds this value]::load_avg" \
{-x,--language=}"[Forces cppcheck to check all files as the given language]:language:(c c++)" \
"--library=[Load config file that contains information about types and functions]:config:_files" \
"--max-configs=[Maximum number of configurations to check in a file]" \
"--max-ctu-depth=[Maximum depth in whole program analysis]:num" \
"--output-file=[File to save results]:file:_files" \
"--output-format=[Specify the output format]:format:(text sarif xml xmlv2 xmlv3)" \
'--platform=[Specified platform specific types and sizes]:platform:($platforms)' \
"--plist-output=[Generate Clang-plist output files in folder]:file:_files" \
"--project=[Run Cppcheck on project]:file:_files" \
"--project-configuration=[Limit the configuration cppcheck should check]:configuration" \
"(-q --quiet)"{-q,--quiet}"[Do not show progress reports]" \
{-rp,--relative-paths}"=[Use relative paths in output (separated with ;)]:file:_files" \
"--report-progress[Report progress messages while checking a file]" \
'--report-type=[Add guideline and classification fields for specified coding standard]:standard:($coding_standards)' \
"--rule=[Match regular expression]:rule" \
"--rule-file=[Use given rule file]:file:_files" \
"--showtime=[show timing information]:type:(none file file-total summary top5_file top5_summary)" \
"--std=[Set standard]:std:(c89 c99 c11 c++03 c++11 c++14 c++17 c++20)" \
"--suppress=[Suppress warnings (format: \[error id\]:\[filename\]:\[line\])]" \
"--suppressions-list=[Suppress warnings listed in the file]:file:_files" \
"--suppress-xml=[Suppress warnings listed in a xml file]:file:_files" \
"--template=[Format the error messages]:text" \
"--template-location=[Format the error message location]:text" \
"*-U[Undefine preprocessor symbol]:symbol" \
"(-v --verbose)"{-v,--verbose}"[Output more detailed error information]" \
"--version[Print out version number]" \
"--xml[Write results in xml format to stderr]" \
"*: :_cppcheck_files"
_cppcheck_author_information() {
local -a info=(name email date)
_values -s ',' 'info' $info
}
_cppcheck "$@"
local -a check_ids=(
all warning style performance portability information unusedFunction missingInclude
)
local -a platforms=(
unix32 unix64 win32A win32W win64 avr8 elbrus-e1cp pic8 pic8-enhanced pic16 mips32 native unspecified
)
local -a coding_standards=(
normal autosar cert-c-2016 cert-cpp-2016 misra-c-2012 misra-c-2023 misra-c-2025
misra-cpp-2008 misra-cpp-2023
)
case $service in
(cppcheck-htmlreport)
_arguments \
'(- *)'{-h,--help}'[show help message and exit]' \
'--title[Title of the project]:title' \
'*--file[cppcheck xml output file to read defects from(default stdin)]:file:_files' \
'--checkers-report-file[cppcheck checkers report file]:file:_files' \
'--report-dir[Directory where the HTML report content is written]:dir:_files -/' \
'--source-dir[Base directory where source code files can be found or a URL to a remote]:dir:_files -/' \
'--add-author-information[Blame information to include(default "name,email,date")]:info:_cppcheck_author_information' \
'--source-encoding[Encoding of source code]:encoding' \
'--blame-options[Blame options which you can use to get author and author mail]:options'
;;
(cppcheck)
_arguments \
"--addon=[Execute addon]" \
"--addon-python=[Specify the python interpreter]: :_files" \
"--cppcheck-build-dir=[Analysis output directory]:directory:_files -/" \
"--check-config[Check cppcheck configuration]" \
"--check-level=[Configure how much valueflow analysis you want]:level:(reduced normal exhaustive)" \
"--check-library[Show information when library files have incomplete info]" \
"--checkers-report=[Write a report of all the active checkers to the given file]:file:_files" \
"--clang=[Use clang parser instead of the builtin Cppcheck parser]: :_files" \
"--config-exclude=[Path to be excluded from configuration checking]:directory:_files -/" \
"--config-exclude-files=[A file that contains a list of config-excludes]:file:_files" \
"--doc[Print a list of all available checks]" \
'*--disable=[Disable individual checks]:id:($check_ids)' \
"--dump[Dump xml data for each translation unit]" \
"*-D[Define preprocessor symbol]:symbol" \
"-E[Print preprocessor output on stdout and don't do any further processing]" \
'--enable=[Enable additional checks]:id:($check_ids)' \
"--error-exitcode=[Integer to return if errors are found]" \
"--errorlist[Print a list of all the error messages in XML format]" \
"--exitcode-suppressions=[Used when certain messages should be displayed but should not cause a non-zero exitcode]:_files" \
"*--file-filter=[Analyze only those files matching the given filter str]:filter" \
"--file-list=[Specify the files to check in a text file]:file:_files" \
"(-f --force)"{-f,--force}"[Force checking of all configurations in files]" \
"(--fsigned-char --funsigned-char)--fsigned-char[Treat char type as signed]" \
"(--fsigned-char --funsigned-char)--funsigned-char[Treat char type as unsigned]" \
"(- 1 *)"{-h,--help}"[Print help]" \
"*-I[A file that contains a list of config-excludes]:directory:_files -/" \
"--include-file=[Specify directory paths to search for included header files in a text file]:file:_files" \
"--include=[Force inclusion of a file before the checked file]:file:_files" \
"-i[Give a source file or source file directory to exclude from the check]:directory or file:_files" \
"--inconclusive[Report even though the analysis is inconclusive]" \
"--inline-suppr[Enable inline suppressions]" \
"-j[Number of threads to do the checking simultaneously]::num" \
"-l[No new threads should be started if the load average is exceeds this value]::load_avg" \
{-x,--language=}"[Forces cppcheck to check all files as the given language]:language:(c c++)" \
"--library=[Load config file that contains information about types and functions]:config:_files" \
"--max-configs=[Maximum number of configurations to check in a file]" \
"--max-ctu-depth=[Maximum depth in whole program analysis]:num" \
"--output-file=[File to save results]:file:_files" \
"--output-format=[Specify the output format]:format:(text sarif xml xmlv2 xmlv3)" \
'--platform=[Specified platform specific types and sizes]:platform:($platforms)' \
"--plist-output=[Generate Clang-plist output files in folder]:file:_files" \
"--project=[Run Cppcheck on project]:file:_files" \
"--project-configuration=[Limit the configuration cppcheck should check]:configuration" \
"(-q --quiet)"{-q,--quiet}"[Do not show progress reports]" \
{-rp,--relative-paths}"=[Use relative paths in output (separated with ;)]:file:_files" \
"--report-progress[Report progress messages while checking a file]" \
'--report-type=[Add guideline and classification fields for specified coding standard]:standard:($coding_standards)' \
"--rule=[Match regular expression]:rule" \
"--rule-file=[Use given rule file]:file:_files" \
"--showtime=[show timing information]:type:(none file file-total summary top5_file top5_summary)" \
"--std=[Set standard]:std:(c89 c99 c11 c++03 c++11 c++14 c++17 c++20)" \
"--suppress=[Suppress warnings (format: \[error id\]:\[filename\]:\[line\])]" \
"--suppressions-list=[Suppress warnings listed in the file]:file:_files" \
"--suppress-xml=[Suppress warnings listed in a xml file]:file:_files" \
"--template=[Format the error messages]:text" \
"--template-location=[Format the error message location]:text" \
"*-U[Undefine preprocessor symbol]:symbol" \
"(-v --verbose)"{-v,--verbose}"[Output more detailed error information]" \
"--version[Print out version number]" \
"--xml[Write results in xml format to stderr]" \
"*: :_cppcheck_files"
;;
esac
# Local Variables:
# mode: Shell-Script