Debian Codegraph @

data/shell-completions/zsh/_meson

raw
1 #compdef meson
2
3 # vim:ts=2 sw=2
4
5 # Copyright (c) 2017 Arseny Maslennikov
6 # All rights reserved. Individual authors, whether or not
7 # specifically named, retain copyright in all changes; in what follows, they
8 # are referred to as `the Meson development team'. This is for convenience
9 # only and this body has no legal status. This file is distributed under
10 # the following licence.
11 #
12 # Permission is hereby granted, without written agreement and without
13 # licence or royalty fees, to use, copy, modify, and distribute this
14 # software and to distribute modified versions of this software for any
15 # purpose, provided that the above copyright notice and the following
16 # two paragraphs appear in all copies of this software.
17 #
18 # In no event shall the Meson development team be liable to any party for
19 # direct, indirect, special, incidental, or consequential damages arising out
20 # of the use of this software and its documentation, even if the Meson
21 # development team have been advised of the possibility of such damage.
22 #
23 # The Meson development team specifically disclaim any warranties, including,
24 # but not limited to, the implied warranties of merchantability and fitness
25 # for a particular purpose. The software provided hereunder is on an "as is"
26 # basis, and the Meson development team have no obligation to provide
27 # maintenance, support, updates, enhancements, or modifications.
28
29 local curcontext="$curcontext" state line
30 local -i ret
31
32 local __meson_backends="(ninja "${(j. .)${:-vs{,2010,2015,2017,2019,2022}}}" xcode none)"
33 local __meson_build_types="(plain debug debugoptimized minsize release)"
34 local __meson_wrap_modes="(default nofallback nodownload forcefallback nopromote)"
35 local __meson_dist_formats=("xztar" "bztar" "gztar" "zip")
36 local __meson_cd='-C[change into this directory before running]:target dir:_directories'
37 local -a __meson_common=(
38 '--prefix=[installation prefix]: :_directories'
39 '--bindir=[executable directory]: :_directories'
40 '--datadir=[data file directory]: :_directories'
41 '--includedir=[header file directory]: :_directories'
42 '--infodir=[info page directory]: :_directories'
43 '--libdir=[library directory]: :_directories'
44 '--libexecdir=[library executable directory]: :_directories'
45 '--localedir=[locale data directory]: :_directories'
46 '--localstatedir=[local state data directory]: :_directories'
47 '--mandir=[manual page directory]: :_directories'
48 '--sbindir=[system executable directory]: :_directories'
49 '--sharedstatedir=[arch-independent data directory]: :_directories'
50 '--sysconfdir=[system configuration directory]: :_directories'
51 '--auto-features=[default value for auto features]:auto features types:(auto disabled enabled)'
52 '--backend=[backend to use]:Meson backend:'"$__meson_backends"
53 '--buildtype=[build type to use]:Meson build type:'"$__meson_build_types"
54 '--debug[turn on building with debug]'
55 '--default-library=[default library type]:default library type:(shared static both)'
56 '--errorlogs[prints the logs from failing tests]'
57 '--install-umask=[default umask for permissions of all installed files]'
58 '--layout=[build directory layout]:build directory layout:(flat mirror)'
59 '--optimization=[optimization level for compiled targets]:optimization:(0 g 1 2 3 s)'
60 '--stdsplit=[split stdout and stderr in test logs]'
61 '--strip[strip targets on install]'
62 '--unity=[unity builds on/off]:whether to do unity builds:(on off subprojects)'
63 '--warnlevel=[compiler warning level]:compiler warning level:warning level:(1 2 3)'
64 '--werror[treat warnings as errors]'
65 '--wrap-mode=[special wrap mode]:wrap mode:'"$__meson_wrap_modes"
66 '--force-fallback-for=[force fallback for listed subprojects]'
67 '--pkg-config-path=[extra paths for HOST pkg-config to search]:paths:_dir_list -s ,'
68 '--build.pkg-config-path=[extra paths for BUILD pkg-config to search]:paths:_dir_list -s ,'
69 '--cmake-prefix-path=[extra prefixes for HOST cmake to search]:paths:_dir_list -s ,'
70 '--build.cmake-prefix-path=[extra prefix for BUILD cmake to search]:paths:_dir_list -s ,'
71 )
72
73 local -a meson_commands=(
74 'configure:configure a project'
75 'dist:generate release archive'
76 'init:create a new project'
77 'install:install one or more targets'
78 'introspect:query project properties'
79 'setup:set up a build directory'
80 'test:run tests'
81 'wrap:manage source dependencies'
82 'subprojects:manage subprojects'
83 'compile:Build the project'
84 'rewrite:Modify the project definition'
85 'devenv:Run commands in developer environment'
86 'env2mfile:Convert current environment to a cross or native file'
87 'format:Format meson source file'
88 'help:Print help of a subcommand'
89 )
90
91 (( $+functions[__meson_is_build_dir] )) || __meson_is_build_dir() {
92 local mpd="${1:-$PWD}/meson-private"
93 [[ -f "$mpd/build.dat" && -f "$mpd/coredata.dat" ]]
94 return $?
95 }
96
97 # TODO: implement build option completion
98 (( $+functions[__meson_build_options] )) || __meson_build_options() {}
99
100 # `meson introspect` currently can provide that information in JSON.
101 # We can:
102 # 1) pipe its output to python3 -m json.tool | grep "$alovelyregex" | cut <...>
103 # 2) teach mintro.py to use a different output format
104 # (or perhaps just to select the fields printed)
105
106 (( $+functions[__meson_test_names] )) || __meson_test_names() {
107 local rtests
108 if rtests="$(_call_program meson meson test ${opt_args[-C]:+-C "$opt_args[-C]"} --list)";
109 then
110 local -a tests=(${(@f)rtests})
111 _describe -t "tests" "Meson tests" tests
112 else
113 _message -r "current working directory is not a build directory"
114 _message -r 'use -C $build_dir or cd $build_dir'
115 fi
116 }
117
118 (( $+functions[__meson_wrap_names] )) || __meson_wrap_names() {
119 local rwraps
120 rwraps="$(_call_program meson meson wrap list)"
121 local -a wraps=(${(@f)rwraps})
122 _describe -t wraps "Meson wraps" wraps
123 }
124
125 (( $+functions[__meson_installed_wraps] )) || __meson_installed_wraps() {
126 local rwraps
127 if rwraps="$(ls subprojects/ | grep '\.wrap$' | cut -d . -f 1)"; then
128 local -a wraps=(${(@f)rwraps})
129 _describe -t wraps "Meson wraps" wraps
130 fi
131 }
132
133 (( $+functions[_meson_commands] )) || _meson_commands() {
134 _describe -t commands "Meson subcommands" meson_commands
135 }
136
137 (( $+functions[_meson-setup] )) || _meson-setup() {
138 local firstd secondd
139 if [[ -f "meson.build" ]]; then
140 # if there's no second argument on the command line
141 # cwd will implicitly be substituted:
142 # - as the source directory if it has a file with the name "meson.build";
143 # - as the build directory otherwise
144 # more info in mesonbuild/mesonmain.py
145 firstd="build"
146 secondd="source"
147 else
148 firstd="source"
149 secondd="build"
150 fi
151
152 _arguments \
153 '*-D-[set the value of a build option]:build option:__meson_build_options' \
154 '--cross-file=[cross-compilation environment description]:cross file:_files' \
155 '--native-file=[build machine compilation environment description]:native file:_files' \
156 '--clearcache[clear cached state]' \
157 '--fatal-meson-warnings=[exit when any meson warnings are encountered]' \
158 '(-v --version)'{'-v','--version'}'[print the meson version and exit]' \
159 '--reconfigure=[re-run build configuration]' \
160 '--wipe=[delete saved state and restart using saved command line options]' \
161 ":$firstd directory:_directories" \
162 "::$secondd directory:_directories" \
163 "${(@)__meson_common}"
164 }
165
166 (( $+functions[_meson-configure] )) || _meson-configure() {
167 local curcontext="$curcontext"
168 # TODO: implement 'mesonconf @file'
169 local -a specs=(
170 '*-D-[set the value of a build option]:build option:__meson_build_options'
171 '::build directory:_directories'
172 )
173
174 _arguments \
175 '(: -)'{'--help','-h'}'[show a help message and quit]' \
176 "${(@)specs}" \
177 "${(@)__meson_common}"
178 }
179
180 (( $+functions[_meson-test] )) || _meson-test() {
181 local curcontext="$curcontext"
182
183 # TODO: complete test suites
184 local -a specs=(
185 '--repeat[number of times to run the tests]:number of times to repeat: '
186 '--no-rebuild[do not rebuild before running tests]'
187 '--gdb[run tests under gdb]'
188 '--gdb-path=[program to run for gdb (can be wrapper or compatible program)]:program:_path_commands'
189 '(--interactive -i)'{'--interactive','-i'}'[run tests with interactive input/output]'
190 '--list[list available tests]'
191 '(--wrapper --wrap)'{'--wrapper','--wrap'}='[wrapper to run tests with]:wrapper program:_path_commands'
192 "$__meson_cd"
193 '(--suite)--no-suite[do not run tests from this suite]:test suite: '
194 '(--no-suite)--suite[only run tests from this suite]:test suite: '
195 '--no-stdsplit[do not split stderr and stdout in logs]'
196 '--print-errorlogs[print logs for failing tests]'
197 '--benchmark[run benchmarks instead of tests]'
198 '--logbase[base name for log file]:filename: '
199 '(--num-processes -j)'{'--num-processes','-j'}'=[how many threads to use]:number of processes: '
200 '(--verbose -v)'{'--verbose','-v'}'[do not redirect stdout and stderr]'
201 '(--quiet -q)'{'--quiet','-q'}'[produce less output to the terminal]'
202 '(--timeout-multiplier -t)'{'--timeout-multiplier','-t'}='[a multiplier for test timeouts]:Python floating-point number: '
203 '--setup[which test setup to use]:test setup: '
204 '--max-lines[Maximum number of lines to show from a long test log]:Python integer number: '
205 '--test-args[arguments to pass to the tests]: : '
206 '*:Meson tests:__meson_test_names'
207 )
208
209 _arguments \
210 '(: -)'{'--help','-h'}'[show a help message and quit]' \
211 "${(@)specs}"
212 }
213
214 (( $+functions[_meson-install] )) || _meson-install() {
215 local curcontext="$curcontext"
216 local -a specs=(
217 "$__meson_cd"
218 '--no-rebuild[do not rebuild before installing]'
219 '--only-changed[do not overwrite files that are older than the copied file]'
220 '(--quiet -q)'{'--quiet','-q'}'[do not print every file that was installed]'
221 '--destdir[set or override DESTDIR environment]: :_directories'
222 '(--dry-run -d)'{'--dry-run','-d'}'[do not actually install, only print logs]'
223 '--skip-subprojects[do not install files from given subprojects]: : '
224 '--tags[install only targets having one of the given tags]: :_values -s , tag devel runtime python-runtime man doc i18n typelib bin bin-devel tests systemtap'
225 '--strip[strip targets even if strip option was not set during configure]'
226 )
227 _arguments \
228 '(: -)'{'--help','-h'}'[show a help message and quit]' \
229 "${(@)specs}"
230 }
231
232 (( $+functions[_meson-introspect] )) || _meson-introspect() {
233 local curcontext="$curcontext"
234 local -a specs=(
235 '--ast[dump the ASK of the meson file]'
236 '--benchmarks[list all benchmarks]'
237 '--buildoptions[list all build options]'
238 '--buildsystem-files[list files that belong to the build system]'
239 '--dependencies[list external dependencies]'
240 '--installed[list all installed files and directories]'
241 '--projectinfo[show project information]'
242 '--targets[list top level targets]'
243 '--tests[list all unit tests]'
244 '--backend=[backend to use]:Meson backend:'"$__meson_backends"
245 '::build directory:_directories'
246 )
247 _arguments \
248 '(: -)'{'--help','-h'}'[show a help message and quit]' \
249 "${(@)specs}"
250 }
251
252 (( $+functions[_meson-init] )) || _meson-init() {
253 local curcontext="$curcontext"
254 local -a specs=(
255 "$__meson_cd"
256 '(-n --name)'{'-n','--name'}'=[the name of the project (defaults to directory name)]'
257 '(-e --executable)'{'-e','--executable'}'=[the name of the executable target to create (defaults to project name)]'
258 '(-d --deps)'{'-d','--deps'}'=[comma separated list of dependencies]'
259 '(-l --language)'{'-l','--language'}'=[comma separated list of languages (autodetected based on sources if unset)]:languages:_values -s , language c cpp cs cuda d fortran java objc objcpp rust'
260 '(-b --build)'{'-b','--build'}'[build the project immediately after generation]'
261 '--builddir=[directory for building]:directory:_directories'
262 '(-f --force)'{'-f','--force'}'[overwrite any existing files and directories]'
263 '(-t --type)'{'-t','--type'}'=[project type, defaults to executable]:type:(executable library)'
264 '(-v --version)'{'-v','--version'}'[print the meson version and exit]'
265 )
266 _arguments \
267 '(: -)'{'--help','-h'}'[show a help message and quit]' \
268 "${(@)specs}"
269 }
270
271 (( $+functions[_meson-wrap] )) || _meson-wrap() {
272 local -a commands=(
273 'list:list all available wraps'
274 'search:search the db by name'
275 'install:install the specified project'
276 'update:Update a project to its newest available version'
277 'info:Show info about a wrap'
278 'status:Show the status of your subprojects'
279 )
280
281 if (( CURRENT == 2 )); then
282 _describe -t commands "Meson wrap subcommands" commands
283 else
284 local curcontext="$curcontext"
285 cmd="${${commands[(r)$words[2]:*]%%:*}}"
286 if (( $#cmd )); then
287 if [[ $cmd == status ]]; then
288 _message "no options"
289 elif [[ $cmd == "list" ]]; then
290 _arguments '*:meson wraps'
291 elif [[ $cmd == "search" ]]; then
292 _arguments '*:meson wraps'
293 elif [[ $cmd == "install" ]]; then
294 _arguments '*:meson wraps:__meson_wrap_names'
295 elif [[ $cmd == "update" ]]; then
296 _arguments '*:meson wraps:__meson_installed_wraps'
297 elif [[ $cmd == "info" ]]; then
298 _arguments '*:meson wraps:__meson_wrap_name'
299 elif [[ $cmd == "status" ]]; then
300 _arguments '*:'
301 elif [[ $cmd == "promote" ]]; then
302 # TODO: how do you figure out what wraps are provided by subprojects if
303 # they haven't been fetched yet?
304 _arguments '*:'
305 fi
306 else
307 _message "unknown meson wrap command: $words[2]"
308 fi
309 fi
310
311 }
312
313 (( $+functions[_meson-dist] )) || _meson-dist() {
314 local curcontext="$curcontext"
315 local -a specs=(
316 '--allow-dirty[Allow even when repository contains uncommitted changes]'
317 '--formats=[comma separated list of archive types to create]:archive formats:_values -s , format '"$__meson_dist_formats"
318 '--include-subprojects[Include source code of subprojects that have been used for the build]'
319 '--no-tests[Do not build and test generated packages]'
320 '(--num-processes -j)'{'--num-processes','-j'}'=[how many threads to use]:number of processes: '
321 "$__meson_cd"
322 )
323 _arguments \
324 '(: -)'{'--help','-h'}'[show a help message and quit]' \
325 "${(@)specs}"
326 }
327
328 (( $+functions[_meson-subprojects-update] )) || _meson-subprojects-update() {
329 local curcontext="$curcontext"
330 local -a specs=(
331 "--rebase[rebase your branch on top of wrap's revision (git only)]"
332 '--sourcedir=[path to source directory]:_directories'
333 '*:subprojects:__meson_installed_wraps'
334 )
335 _arguments \
336 '(: -)'{'--help','-h'}'[show a help message and quit]' \
337 "${(@)specs}"
338 }
339
340 (( $+functions[_meson-subprojects-checkout] )) || _meson-subprojects-checkout() {
341 local curcontext="$curcontext"
342 local -a specs=(
343 '-b[create a new branch]'
344 '--sourcedir=[path to source directory]:_directories'
345 # FIXME: this doesn't work exactly right, but I can't figure it out
346 ':branch name'
347 '*:subprojects:__meson_installed_wraps'
348 )
349 _arguments \
350 '(: -)'{'--help','-h'}'[show a help message and quit]' \
351 "${(@)specs}"
352 }
353
354 (( $+functions[_meson-subprojects-download] )) || _meson-subprojects-download() {
355 local curcontext="$curcontext"
356 local -a specs=(
357 '--sourcedir=[path to source directory]:_directories'
358 )
359 _arguments \
360 '(: -)'{'--help','-h'}'[show a help message and quit]' \
361 "${(@)specs}"
362 }
363
364 (( $+functions[_meson-subprojects-foreach] )) || _meson-subprojects-foreach() {
365 local curcontext="$curcontext"
366 local -a specs=(
367 '--sourcedir=[path to source directory]:_directories'
368 '*:command:_command_names -e'
369 )
370 _arguments \
371 '(: -)'{'--help','-h'}'[show a help message and quit]' \
372 "${(@)specs}"
373 }
374
375 (( $+functions[_meson-subprojects] )) || _meson-subprojects() {
376 local -a commands=(
377 'update:update all subprojects from wrap files'
378 'checkout:checkout a branch (git only)'
379 'download:ensure subprojects are fetched, even if not in use. Already downloaded subprojects are not modified.'
380 'foreach:execute a command in each subproject directory'
381 )
382
383 if (( CURRENT == 2 )); then
384 _describe -t commands "Meson subprojects subcommands" commands
385 else
386 local curcontext="$curcontext"
387 cmd="${${commands[(r)$words[2]:*]%%:*}}"
388 if (( $#cmd )); then
389 if [[ $cmd == status ]]; then
390 _message "no options"
391 else
392 _meson-subprojects-$cmd
393 fi
394 else
395 _message "unknown meson subprojects command: $words[2]"
396 fi
397 fi
398
399 }
400
401 (( $+functions[_meson-compile] )) || _meson-compile() {
402 local curcontext="$curcontext"
403 local -a specs=(
404 "$__meson_cd"
405 '--clean[Clean the build directory]'
406 '(-j --jobs)'{'-j','--jobs'}'=[the number of work jobs to run (if supported)]:_guard "[0-9]#" "number of jobs"'
407 '(-l --load-average)'{'-l','--load-average'}'=[the system load average to try to maintain (if supported)]:_guard "[0-9]#" "load average"'
408 '(-v --verbose)'{'-v','--verbose'}'[Show more output]'
409 '--ninja-args=[Arguments to pass to ninja (only when using ninja)]'
410 '--vs-args=[Arguments to pass to vs (only when using msbuild)]'
411 )
412 _arguments \
413 '(: -)'{'--help','-h'}'[show a help message and quit]' \
414 "${(@)specs}"
415 }
416
417 # TODO: implement rewrite sub-commands properly
418 (( $+functions[_meson-rewrite-target] )) || _meson-rewrite-target() {
419 _arguments \
420 '(: -)'{'--help','-h'}'[show a help message and quit]' \
421 }
422
423 (( $+functions[_meson-rewrite-kwargs] )) || _meson-rewrite-kwargs() {
424 _arguments \
425 '(: -)'{'--help','-h'}'[show a help message and quit]' \
426 }
427
428 (( $+functions[_meson-rewrite-default-options] )) || _meson-rewrite-default-options() {
429 _arguments \
430 '(: -)'{'--help','-h'}'[show a help message and quit]' \
431 }
432
433 (( $+functions[_meson-rewrite-command] )) || _meson-rewrite-command() {
434 _arguments \
435 '(: -)'{'--help','-h'}'[show a help message and quit]' \
436 }
437
438 (( $+functions[_meson-rewrite] )) || _meson-rewrite() {
439 local -a commands=(
440 'target:Modify a target'
441 'kwargs:Modify keyword arguments'
442 'default-options:Modify the project default options'
443 'command:Execute a JSON array of commands'
444 )
445
446 if (( CURRENT == 2 )); then
447 _describe -t commands "Meson rewrite subcommands" commands
448 else
449 local curcontext="$curcontext"
450 cmd="${${commands[(r)$words[2]:*]%%:*}}"
451 if [[ $cmd == status ]]; then
452 _message "no options"
453 else
454 _meson-rewrite-$cmd
455 fi
456 fi
457
458 }
459
460 (( $+functions[_meson-devenv] )) || _meson-devenv() {
461 local curcontext="$curcontext"
462 local -a specs=(
463 "$__meson_cd"
464 '--clean=[Clean the build directory]'
465 '(-w workdir)'{'-w','--workdir'}'=[Directory to cd into before running (default: builddir, Since 1.0.0)]:target dir:_directories'
466 '--dump=[Only print required environment (Since 0.62.0) Takes an optional file path (Since 1.1.0)]:dump path:_files'
467 '--dump-format=[Format used with --dump (Since 1.1.0)]:format:(sh export vscode)'
468 )
469 _arguments \
470 '(: -)'{'--help','-h'}'[show a help message and quit]' \
471 "${(@)specs}"
472 }
473
474 (( $+functions[_meson-env2mfile] )) || _meson-env2mfile() {
475 local curcontext="$curcontext"
476 local -a specs=(
477 '--debarch=[The dpkg architecture to generate.]'
478 '--gccsuffix=[A particular gcc version suffix if necessary.]'
479 '-o=[The output file.]:file:_files'
480 '--cross=[Generate a cross compilation file.]'
481 '--native=[Generate a native compilation file.]'
482 '--system=[Define system for cross compilation.]'
483 '--subsystem=[Define subsystem for cross compilation.]'
484 '--kernel=[Define kernel for cross compilation.]'
485 '--cpu=[Define cpu for cross compilation.]'
486 '--cpu-family=[Define cpu family for cross compilation.]'
487 '--endian=[Define endianness for cross compilation.]:endianness:(big little)'
488 )
489 _arguments \
490 '(: -)'{'--help','-h'}'[show a help message and quit]' \
491 "${(@)specs}"
492 }
493
494 (( $+functions[_meson-format] )) || _meson-format() {
495 local curcontext="$curcontext"
496 local -a specs=(
497 '(-q --check-only)'{'-q','--check-only'}'=[exit with 1 if files would be modified by meson format]'
498 '(-i --inplace)'{'-i','--inplace'}'=[format files in-place]'
499 '(-r --recursive)'{'-r','--recursive'}'=[recurse subdirs (requires --check-only or --inplace option)]'
500 '(-c --configuration)'{'-c','--configuration'}'=[read configuration from meson.format]'
501 '(-e --editor-config)'{'-e','--editor-config'}'=[try to read configuration from .editorconfig]'
502 '(-o --output)'{'-o','--output'}'=[output file (implies having exactly one input)]'
503 )
504 _arguments \
505 '(: -)'{'--help','-h'}'[show a help message and quit]' \
506 "${(@)specs}"
507 }
508
509 if [[ $service != meson ]]; then
510 _call_function ret _$service
511 return ret
512 fi
513
514 _arguments -C -R \
515 '(: -)'{'--help','-h'}'[show a help message and quit]' \
516 '(: -)'{'--version','-v'}'[show version information and quit]' \
517 '(-): :_meson_commands' \
518 '*:: :->post-command' \
519 #
520 ret=$?
521
522 [[ $ret = 300 ]] && case "$state" in
523 post-command)
524 service="meson-$words[1]"
525 curcontext=${curcontext%:*:*}:$service:
526 _call_function ret _$service
527 ;;
528 esac
529
530 return ret