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 '(--maxfail -k)'{'--maxfail','-k'}'=[number of failing tests before aborting]:number of failing tests: '
186 '--repeat[number of times to run the tests]:number of times to repeat: '
187 '--no-rebuild[do not rebuild before running tests]'
188 '--gdb[run tests under gdb]'
189 '--gdb-path=[program to run for gdb (can be wrapper or compatible program)]:program:_path_commands'
190 '(--interactive -i)'{'--interactive','-i'}'[run tests with interactive input/output]'
191 '--list[list available tests]'
192 '(--wrapper --wrap)'{'--wrapper','--wrap'}='[wrapper to run tests with]:wrapper program:_path_commands'
193 "$__meson_cd"
194 '(--suite)--no-suite[do not run tests from this suite]:test suite: '
195 '(--no-suite)--suite[only run tests from this suite]:test suite: '
196 '--no-stdsplit[do not split stderr and stdout in logs]'
197 '--print-errorlogs[print logs for failing tests]'
198 '--benchmark[run benchmarks instead of tests]'
199 '--logbase[base name for log file]:filename: '
200 '(--num-processes -j)'{'--num-processes','-j'}'=[how many threads to use]:number of processes: '
201 '(--verbose -v)'{'--verbose','-v'}'[do not redirect stdout and stderr]'
202 '(--quiet -q)'{'--quiet','-q'}'[produce less output to the terminal]'
203 '(--timeout-multiplier -t)'{'--timeout-multiplier','-t'}='[a multiplier for test timeouts]:Python floating-point number: '
204 '--setup[which test setup to use]:test setup: '
205 '--max-lines[Maximum number of lines to show from a long test log]:Python integer number: '
206 '--test-args[arguments to pass to the tests]: : '
207 '*:Meson tests:__meson_test_names'
208 )
209
210 _arguments \
211 '(: -)'{'--help','-h'}'[show a help message and quit]' \
212 "${(@)specs}"
213 }
214
215 (( $+functions[_meson-install] )) || _meson-install() {
216 local curcontext="$curcontext"
217 local -a specs=(
218 "$__meson_cd"
219 '--no-rebuild[do not rebuild before installing]'
220 '--only-changed[do not overwrite files that are older than the copied file]'
221 '(--quiet -q)'{'--quiet','-q'}'[do not print every file that was installed]'
222 '--destdir[set or override DESTDIR environment]: :_directories'
223 '(--dry-run -d)'{'--dry-run','-d'}'[do not actually install, only print logs]'
224 '--skip-subprojects[do not install files from given subprojects]: : '
225 '--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'
226 '--strip[strip targets even if strip option was not set during configure]'
227 )
228 _arguments \
229 '(: -)'{'--help','-h'}'[show a help message and quit]' \
230 "${(@)specs}"
231 }
232
233 (( $+functions[_meson-introspect] )) || _meson-introspect() {
234 local curcontext="$curcontext"
235 local -a specs=(
236 '--ast[dump the ASK of the meson file]'
237 '--benchmarks[list all benchmarks]'
238 '--buildoptions[list all build options]'
239 '--buildsystem-files[list files that belong to the build system]'
240 '--dependencies[list external dependencies]'
241 '--installed[list all installed files and directories]'
242 '--projectinfo[show project information]'
243 '--targets[list top level targets]'
244 '--tests[list all unit tests]'
245 '--backend=[backend to use]:Meson backend:'"$__meson_backends"
246 '::build directory:_directories'
247 )
248 _arguments \
249 '(: -)'{'--help','-h'}'[show a help message and quit]' \
250 "${(@)specs}"
251 }
252
253 (( $+functions[_meson-init] )) || _meson-init() {
254 local curcontext="$curcontext"
255 local -a specs=(
256 "$__meson_cd"
257 '(-n --name)'{'-n','--name'}'=[the name of the project (defaults to directory name)]'
258 '(-e --executable)'{'-e','--executable'}'=[the name of the executable target to create (defaults to project name)]'
259 '(-d --deps)'{'-d','--deps'}'=[comma separated list of dependencies]'
260 '(-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'
261 '(-b --build)'{'-b','--build'}'[build the project immediately after generation]'
262 '--builddir=[directory for building]:directory:_directories'
263 '(-f --force)'{'-f','--force'}'[overwrite any existing files and directories]'
264 '(-t --type)'{'-t','--type'}'=[project type, defaults to executable]:type:(executable library)'
265 '(-v --version)'{'-v','--version'}'[print the meson version and exit]'
266 )
267 _arguments \
268 '(: -)'{'--help','-h'}'[show a help message and quit]' \
269 "${(@)specs}"
270 }
271
272 (( $+functions[_meson-wrap] )) || _meson-wrap() {
273 local -a commands=(
274 'list:list all available wraps'
275 'search:search the db by name'
276 'install:install the specified project'
277 'update:Update a project to its newest available version'
278 'info:Show info about a wrap'
279 'status:Show the status of your subprojects'
280 )
281
282 if (( CURRENT == 2 )); then
283 _describe -t commands "Meson wrap subcommands" commands
284 else
285 local curcontext="$curcontext"
286 cmd="${${commands[(r)$words[2]:*]%%:*}}"
287 if (( $#cmd )); then
288 if [[ $cmd == status ]]; then
289 _message "no options"
290 elif [[ $cmd == "list" ]]; then
291 _arguments '*:meson wraps'
292 elif [[ $cmd == "search" ]]; then
293 _arguments '*:meson wraps'
294 elif [[ $cmd == "install" ]]; then
295 _arguments '*:meson wraps:__meson_wrap_names'
296 elif [[ $cmd == "update" ]]; then
297 _arguments '*:meson wraps:__meson_installed_wraps'
298 elif [[ $cmd == "info" ]]; then
299 _arguments '*:meson wraps:__meson_wrap_name'
300 elif [[ $cmd == "status" ]]; then
301 _arguments '*:'
302 elif [[ $cmd == "promote" ]]; then
303 # TODO: how do you figure out what wraps are provided by subprojects if
304 # they haven't been fetched yet?
305 _arguments '*:'
306 fi
307 else
308 _message "unknown meson wrap command: $words[2]"
309 fi
310 fi
311
312 }
313
314 (( $+functions[_meson-dist] )) || _meson-dist() {
315 local curcontext="$curcontext"
316 local -a specs=(
317 '--allow-dirty[Allow even when repository contains uncommitted changes]'
318 '--formats=[comma separated list of archive types to create]:archive formats:_values -s , format '"$__meson_dist_formats"
319 '--include-subprojects[Include source code of subprojects that have been used for the build]'
320 '--no-tests[Do not build and test generated packages]'
321 '(--num-processes -j)'{'--num-processes','-j'}'=[how many threads to use]:number of processes: '
322 "$__meson_cd"
323 )
324 _arguments \
325 '(: -)'{'--help','-h'}'[show a help message and quit]' \
326 "${(@)specs}"
327 }
328
329 (( $+functions[_meson-subprojects-update] )) || _meson-subprojects-update() {
330 local curcontext="$curcontext"
331 local -a specs=(
332 "--rebase[rebase your branch on top of wrap's revision (git only)]"
333 '--sourcedir=[path to source directory]:_directories'
334 '*:subprojects:__meson_installed_wraps'
335 )
336 _arguments \
337 '(: -)'{'--help','-h'}'[show a help message and quit]' \
338 "${(@)specs}"
339 }
340
341 (( $+functions[_meson-subprojects-checkout] )) || _meson-subprojects-checkout() {
342 local curcontext="$curcontext"
343 local -a specs=(
344 '-b[create a new branch]'
345 '--sourcedir=[path to source directory]:_directories'
346 # FIXME: this doesn't work exactly right, but I can't figure it out
347 ':branch name'
348 '*:subprojects:__meson_installed_wraps'
349 )
350 _arguments \
351 '(: -)'{'--help','-h'}'[show a help message and quit]' \
352 "${(@)specs}"
353 }
354
355 (( $+functions[_meson-subprojects-download] )) || _meson-subprojects-download() {
356 local curcontext="$curcontext"
357 local -a specs=(
358 '--sourcedir=[path to source directory]:_directories'
359 )
360 _arguments \
361 '(: -)'{'--help','-h'}'[show a help message and quit]' \
362 "${(@)specs}"
363 }
364
365 (( $+functions[_meson-subprojects-foreach] )) || _meson-subprojects-foreach() {
366 local curcontext="$curcontext"
367 local -a specs=(
368 '--sourcedir=[path to source directory]:_directories'
369 '*:command:_command_names -e'
370 )
371 _arguments \
372 '(: -)'{'--help','-h'}'[show a help message and quit]' \
373 "${(@)specs}"
374 }
375
376 (( $+functions[_meson-subprojects] )) || _meson-subprojects() {
377 local -a commands=(
378 'update:update all subprojects from wrap files'
379 'checkout:checkout a branch (git only)'
380 'download:ensure subprojects are fetched, even if not in use. Already downloaded subprojects are not modified.'
381 'foreach:execute a command in each subproject directory'
382 )
383
384 if (( CURRENT == 2 )); then
385 _describe -t commands "Meson subprojects subcommands" commands
386 else
387 local curcontext="$curcontext"
388 cmd="${${commands[(r)$words[2]:*]%%:*}}"
389 if (( $#cmd )); then
390 if [[ $cmd == status ]]; then
391 _message "no options"
392 else
393 _meson-subprojects-$cmd
394 fi
395 else
396 _message "unknown meson subprojects command: $words[2]"
397 fi
398 fi
399
400 }
401
402 (( $+functions[_meson-compile] )) || _meson-compile() {
403 local curcontext="$curcontext"
404 local -a specs=(
405 "$__meson_cd"
406 '--clean[Clean the build directory]'
407 '(-j --jobs)'{'-j','--jobs'}'=[the number of work jobs to run (if supported)]:_guard "[0-9]#" "number of jobs"'
408 '(-l --load-average)'{'-l','--load-average'}'=[the system load average to try to maintain (if supported)]:_guard "[0-9]#" "load average"'
409 '(-v --verbose)'{'-v','--verbose'}'[Show more output]'
410 '--ninja-args=[Arguments to pass to ninja (only when using ninja)]'
411 '--vs-args=[Arguments to pass to vs (only when using msbuild)]'
412 )
413 _arguments \
414 '(: -)'{'--help','-h'}'[show a help message and quit]' \
415 "${(@)specs}"
416 }
417
418 # TODO: implement rewrite sub-commands properly
419 (( $+functions[_meson-rewrite-target] )) || _meson-rewrite-target() {
420 _arguments \
421 '(: -)'{'--help','-h'}'[show a help message and quit]' \
422 }
423
424 (( $+functions[_meson-rewrite-kwargs] )) || _meson-rewrite-kwargs() {
425 _arguments \
426 '(: -)'{'--help','-h'}'[show a help message and quit]' \
427 }
428
429 (( $+functions[_meson-rewrite-default-options] )) || _meson-rewrite-default-options() {
430 _arguments \
431 '(: -)'{'--help','-h'}'[show a help message and quit]' \
432 }
433
434 (( $+functions[_meson-rewrite-command] )) || _meson-rewrite-command() {
435 _arguments \
436 '(: -)'{'--help','-h'}'[show a help message and quit]' \
437 }
438
439 (( $+functions[_meson-rewrite] )) || _meson-rewrite() {
440 local -a commands=(
441 'target:Modify a target'
442 'kwargs:Modify keyword arguments'
443 'default-options:Modify the project default options'
444 'command:Execute a JSON array of commands'
445 )
446
447 if (( CURRENT == 2 )); then
448 _describe -t commands "Meson rewrite subcommands" commands
449 else
450 local curcontext="$curcontext"
451 cmd="${${commands[(r)$words[2]:*]%%:*}}"
452 if [[ $cmd == status ]]; then
453 _message "no options"
454 else
455 _meson-rewrite-$cmd
456 fi
457 fi
458
459 }
460
461 (( $+functions[_meson-devenv] )) || _meson-devenv() {
462 local curcontext="$curcontext"
463 local -a specs=(
464 "$__meson_cd"
465 '--clean=[Clean the build directory]'
466 '(-w workdir)'{'-w','--workdir'}'=[Directory to cd into before running (default: builddir, Since 1.0.0)]:target dir:_directories'
467 '--dump=[Only print required environment (Since 0.62.0) Takes an optional file path (Since 1.1.0)]:dump path:_files'
468 '--dump-format=[Format used with --dump (Since 1.1.0)]:format:(sh export vscode)'
469 )
470 _arguments \
471 '(: -)'{'--help','-h'}'[show a help message and quit]' \
472 "${(@)specs}"
473 }
474
475 (( $+functions[_meson-env2mfile] )) || _meson-env2mfile() {
476 local curcontext="$curcontext"
477 local -a specs=(
478 '--debarch=[The dpkg architecture to generate.]'
479 '--gccsuffix=[A particular gcc version suffix if necessary.]'
480 '-o=[The output file.]:file:_files'
481 '--cross=[Generate a cross compilation file.]'
482 '--native=[Generate a native compilation file.]'
483 '--system=[Define system for cross compilation.]'
484 '--subsystem=[Define subsystem for cross compilation.]'
485 '--kernel=[Define kernel for cross compilation.]'
486 '--cpu=[Define cpu for cross compilation.]'
487 '--cpu-family=[Define cpu family for cross compilation.]'
488 '--endian=[Define endianness for cross compilation.]:endianness:(big little)'
489 )
490 _arguments \
491 '(: -)'{'--help','-h'}'[show a help message and quit]' \
492 "${(@)specs}"
493 }
494
495 (( $+functions[_meson-format] )) || _meson-format() {
496 local curcontext="$curcontext"
497 local -a specs=(
498 '(-q --check-only)'{'-q','--check-only'}'=[exit with 1 if files would be modified by meson format]'
499 '(-i --inplace)'{'-i','--inplace'}'=[format files in-place]'
500 '(-r --recursive)'{'-r','--recursive'}'=[recurse subdirs (requires --check-only or --inplace option)]'
501 '(-c --configuration)'{'-c','--configuration'}'=[read configuration from meson.format]'
502 '(-e --editor-config)'{'-e','--editor-config'}'=[try to read configuration from .editorconfig]'
503 '(-o --output)'{'-o','--output'}'=[output file (implies having exactly one input)]'
504 )
505 _arguments \
506 '(: -)'{'--help','-h'}'[show a help message and quit]' \
507 "${(@)specs}"
508 }
509
510 if [[ $service != meson ]]; then
511 _call_function ret _$service
512 return ret
513 fi
514
515 _arguments -C -R \
516 '(: -)'{'--help','-h'}'[show a help message and quit]' \
517 '(: -)'{'--version','-v'}'[show version information and quit]' \
518 '(-): :_meson_commands' \
519 '*:: :->post-command' \
520 #
521 ret=$?
522
523 [[ $ret = 300 ]] && case "$state" in
524 post-command)
525 service="meson-$words[1]"
526 curcontext=${curcontext%:*:*}:$service:
527 _call_function ret _$service
528 ;;
529 esac
530
531 return ret