blob: d40620487617fca185a468d460e13c06b3e45411 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
|
_meson() {
command="${COMP_WORDS[1]}"
meson_subcommands=(
setup
configure
dist
install
introspect
init
test
wrap
subprojects
help
rewrite
compile
devenv
env2mfile
)
if [[ " ${meson_subcommands[*]} " =~ " ${command} " ]]; then
_meson-$command "${COMP_WORDS[@]:1}"
else
_meson-setup "${COMP_WORDS[@]}"
fi
} &&
complete -F _meson meson
_meson_complete_option() {
option_string=$1
if [[ $# -eq 2 ]] && ! [[ "$option_string" == *=* ]]; then
option_string="$option_string=$2"
fi
if [[ "$option_string" == *=* ]]; then
_meson_complete_option_value "$option_string"
else
_meson_complete_option_name "$option_string"
fi
}
_meson_complete_option_name() {
option=$1
options=($(python3 -c 'import sys, json
for option in json.load(sys.stdin):
print(option["name"])
' <<< "$(_meson_get_options)"))
compopt -o nospace
COMPREPLY=($(compgen -W '${options[@]}' -S= -- "$option"))
}
_meson_complete_option_value() {
cur=$1
option_name=${cur%%=*}
option_value=${cur#*=}
if _meson_complete_filedir "$option_name" "$option_value"; then
return
fi
# TODO: support all the option types
options=($(python3 -c 'import sys, json
for option in json.load(sys.stdin):
if option["name"] != "'$option_name'":
continue
choices = []
if option["type"] == "boolean":
choices.append("true")
choices.append("false")
elif option["type"] == "combo":
for choice in option["choices"]:
choices.append(choice)
for choice in choices:
if choice.startswith("'$cur'"):
print(choice)
' <<< "$(_meson_get_options)"))
COMPREPLY=("${options[@]}")
}
_meson_get_options() {
local options
for builddir in "${COMP_WORDS[@]}"; do
if [ -d "$builddir" ]; then
break
fi
builddir=.
done
options=$(meson introspect "$builddir" --buildoptions 2>/dev/null) &&
echo "$options" ||
echo '[]'
}
_meson_complete_filedir() {
_filedir_in() {
pushd "$1" &>/dev/null
local COMPREPLY=()
_filedir
echo "${COMPREPLY[@]}"
popd &>/dev/null
}
option=$1
cur=$2
case $option in
prefix |\
bindir |\
datadir |\
includedir |\
infodir |\
libdir |\
licensedir |\
libexecdir |\
localedir |\
localstatedir |\
mandir |\
sbindir |\
sharedstatedir |\
sysconfdir |\
python.platlibdir |\
python.purelibdir |\
pkg-config-path |\
build.pkg-config-path |\
cmake-prefix-path |\
build.cmake-prefix-path)
_filedir -d
;;
cross-file)
_filedir
COMPREPLY+=($(_filedir_in "$XDG_DATA_DIRS"/meson/cross))
COMPREPLY+=($(_filedir_in /usr/local/share/meson/cross))
COMPREPLY+=($(_filedir_in /usr/share/meson/cross))
COMPREPLY+=($(_filedir_in "$XDG_DATA_HOME"/meson/cross))
COMPREPLY+=($(_filedir_in ~/.local/share/meson/cross))
;;
native-file)
_filedir
COMPREPLY+=($(_filedir_in "$XDG_DATA_DIRS"/meson/native))
COMPREPLY+=($(_filedir_in /usr/local/share/meson/native))
COMPREPLY+=($(_filedir_in /usr/share/meson/native))
COMPREPLY+=($(_filedir_in "$XDG_DATA_HOME"/meson/native))
COMPREPLY+=($(_filedir_in ~/.local/share/meson/native))
;;
*)
return 1;;
esac
return 0
}
_meson_compgen_options() {
local -r cur=$1
if [[ ${cur:0:2} == -- ]]; then
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}' -- "${cur:2}"))
elif [[ ${cur:0:1} == - ]]; then
if [[ ${#cur} == 1 ]]; then
# Only add longopts if cur not "-something"
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}' -- ""))
fi
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}' -- "${cur:1}"))
else
return 1
fi
return 0
}
_meson-setup() {
shortopts=(
h
D
v
)
# backend-startup-project is currently VS backend only.
longopts=(
help
prefix
bindir
datadir
includedir
infodir
libdir
libexecdir
licensedir
localedir
localstatedir
mandir
sbindir
sharedstatedir
sysconfdir
auto-features
backend
buildtype
debug
default-library
errorlogs
install-umask
layout
optimization
prefer-static
stdsplit
strip
unity
unity-size
warnlevel
werror
wrap-mode
force-fallback-for
pkgconfig.relocatable
python.install-env
python.platlibdir
python.purelibdir
pkg-config-path
build.pkg-config-path
cmake-prefix-path
build.cmake-prefix-path
native-file
cross-file
vsenv
version
fatal-meson-warnings
reconfigure
wipe
)
local cur prev
if _get_comp_words_by_ref cur prev &>/dev/null; then
if [[ ${prev:0:2} == -- ]] && _meson_complete_option "${prev:2}" "$cur"; then
return
elif [[ ${prev:0:1} == - ]] && [[ ${prev:1:2} != - ]] && _meson_complete_option "${prev:1}"; then
return
fi
fi
if _get_comp_words_by_ref -n '=' cur prev &>/dev/null; then
if [[ $prev == -D ]]; then
_meson_complete_option "$cur"
return
fi
else
cur="${COMP_WORDS[COMP_CWORD]}"
fi
if ! _meson_compgen_options "$cur"; then
_filedir -d
if [[ -z $cur ]]; then
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}'))
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}'))
fi
if [[ $COMP_CWORD == 1 ]]; then
COMPREPLY+=($(compgen -W "${meson_subcommands[*]}" -- "$cur"))
fi
fi
}
_meson-configure() {
shortopts=(
h
D
)
longopts=(
help
prefix
bindir
datadir
includedir
infodir
libdir
libexecdir
licensedir
localedir
localstatedir
mandir
sbindir
sharedstatedir
sysconfdir
auto-features
backend
buildtype
debug
default-library
errorlogs
install-umask
layout
optimization
prefer-static
stdsplit
strip
unity
unity-size
warnlevel
werror
wrap-mode
force-fallback-for
backend-startup-project
pkgconfig.relocatable
python.install-env
python.platlibdir
python.purelibdir
pkg-config-path
build.pkg-config-path
cmake-prefix-path
build.cmake-prefix-path
clearcache
no-pager
)
local cur prev
if _get_comp_words_by_ref -n '=' cur prev &>/dev/null; then
if [[ $prev == -D ]]; then
_meson_complete_option "$cur"
return
fi
else
cur="${COMP_WORDS[COMP_CWORD]}"
fi
if ! _meson_compgen_options "$cur"; then
for dir in "${COMP_WORDS[@]}"; do
if [[ -d "$dir" ]]; then
break
fi
dir=.
done
if [[ ! -d "$dir/meson-private" ]]; then
_filedir -d
fi
if [[ -z $cur ]]; then
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}'))
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}'))
fi
fi
}
_meson-dist() {
: TODO
}
_meson-install() {
: TODO
}
_meson-introspect() {
shortopts=(
h
a
i
f
)
longopts=(
ast
benchmarks
buildoptions
buildsystem-files
dependencies
scan-dependencies
installed
install-plan
projectinfo
targets
tests
backend
all
indent
force-object-output
)
local cur prev
if ! _get_comp_words_by_ref cur prev &>/dev/null; then
cur="${COMP_WORDS[COMP_CWORD]}"
fi
if ! _meson_compgen_options "$cur"; then
for dir in "${COMP_WORDS[@]}"; do
if [ -d "$dir" ]; then
break
fi
dir=.
done
if [ ! -d "$dir/meson-private" ]; then
_filedir -d
fi
if [ -z "$cur" ]; then
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}'))
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}'))
fi
fi
}
_meson-init() {
shortopts=(
h
C
n
e
d
l
b
f
)
longopts=(
help
name
executable
deps
language
build
builddir
force
type
version
)
if ! _meson_compgen_options "$cur"; then
if [[ -z $cur ]]; then
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}'))
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}'))
fi
fi
}
_meson-test() {
shortopts=(
h
q
v
t
C
)
longopts=(
help
maxfail
repeat
no-rebuild
gdb
gdb-path
list
wrapper
suite
no-suite
no-stdsplit
print-errorlogs
benchmark
logbase
num-processes
verbose
quiet
timeout-multiplier
setup
test-args
)
local cur prev
if _get_comp_words_by_ref -n ':' cur prev &>/dev/null; then
case $prev in
--maxfail | --repeat)
# number, can't be completed
return
;;
--wrapper)
_command_offset $COMP_CWORD
return
;;
--gdb-path | -C)
_filedir -d
return
;;
--suite | --no-suite)
for i in "${!COMP_WORDS[@]}"; do
opt="${COMP_WORDS[i]}"
dir="${COMP_WORDS[i+1]}"
case "$opt" in
-C)
break
;;
esac
dir=.
done
suites=($(python3 -c 'import sys, json;
for test in json.load(sys.stdin):
for suite in test["suite"]:
print(suite)
' <<< "$(meson introspect "$dir" --tests)"))
# TODO
COMPREPLY+=($(compgen -W "${suites[*]}" -- "$cur"))
return
;;
--logbase)
# free string, can't be completed
return
;;
--num-processes)
# number, can't be completed
return
;;
-t | --timeout-multiplier)
# number, can't be completed
return
;;
--setup)
# TODO
return
;;
--test-args)
return
;;
esac
else
cur="${COMP_WORDS[COMP_CWORD]}"
fi
if ! _meson_compgen_options "$cur"; then
for dir in "${COMP_WORDS[@]}"; do
if [ -d "$dir" ]; then
break
fi
dir=.
done
if [ ! -d "$dir/meson-private" ]; then
_filedir -d
fi
for i in "${!COMP_WORDS[@]}"; do
opt="${COMP_WORDS[i]}"
dir="${COMP_WORDS[i+1]}"
case "$opt" in
-C)
break
;;
esac
dir=.
done
tests=($(python3 -c 'import sys, json;
for test in json.load(sys.stdin):
print(test["name"])
' <<< "$(meson introspect "$dir" --tests)"))
COMPREPLY+=($(compgen -W "${tests[*]}" -- "$cur"))
if [ -z "$cur" ]; then
COMPREPLY+=($(compgen -P '--' -W '${longopts[*]}' -- "${cur:2}"))
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}' -- "${cur:1}"))
fi
fi
}
_meson-wrap() {
: TODO
}
_meson-subprojects() {
: TODO
}
_meson-help() {
: # Nothing to do
}
_meson-rewrite() {
: TODO
}
_meson-compile() {
: TODO
}
_meson-devenv() {
: TODO
}
_meson-env2mfile() {
: TODO
}
|