Skip to content

Commit a3f93ea

Browse files
committed
build: Add options to override the locations for the shell completions
This is particularly relevant for Z shell, because, unlike Bash's bash-completion.pc and fish's fish.pc, it doesn't have an API to detect the location for the shell completions and Debian and Fedora use different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions and /usr/share/zsh/site-functions. An option to specify the locations for the shell completions can optimize the build if there's an alternate API for the location that doesn't involve using bash-completion.pc and fish.pc as build dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to specify the location for vendor-supplied tmpfiles.d(5) files, which makes it possible to avoid having systemd as a build dependency [3]. Finally, when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, the locations for the completions in the shells' APIs might not be accessible. Being able to override the locations prevents the installation from failing. [1] Debian zsh commit bf0a44a8744469b5 https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452 [2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec [3] Fedora toolbox commit 9bebde5bb60f36e3 https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3 containers#840
1 parent 942eb70 commit a3f93ea

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

completion/meson.build

+21-31
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,35 @@
11
generate_completions_program = find_program('generate_completions.py')
22

3-
if bash_completion_dep.found()
4-
bashcompletionsdir = bash_completion_dep.get_variable(pkgconfig: 'completionsdir')
5-
else
6-
bashcompletionsdir = get_option('datadir') / 'bash-completion' / 'completions'
7-
message('bash-completion not found: using', get_option('prefix') / bashcompletionsdir, 'as a falback install directory')
8-
endif
9-
10-
if fish_dep.found()
11-
fishcompletionsdir = fish_dep.get_variable(pkgconfig: 'completionsdir')
12-
else
13-
fishcompletionsdir = get_option('datadir') / 'fish' / 'completions'
14-
message('fish not found: using', get_option('prefix') / fishcompletionsdir, 'as a fallback install directory')
3+
if bashcompletionsdir != ''
4+
custom_target(
5+
'bash-completion',
6+
capture: true,
7+
command: [generate_completions_program, meson.global_source_root() / 'src', 'bash'],
8+
depends: [toolbox_go],
9+
install: true,
10+
install_dir: bashcompletionsdir,
11+
output: 'toolbox'
12+
)
1513
endif
1614

17-
custom_target(
18-
'bash-completion',
19-
capture: true,
20-
command: [generate_completions_program, meson.global_source_root() / 'src', 'bash'],
21-
depends: [toolbox_go],
22-
install: true,
23-
install_dir: bashcompletionsdir,
24-
output: 'toolbox'
15+
if fishcompletionsdir != ''
16+
custom_target(
17+
'fish-completion',
18+
capture: true,
19+
command: [generate_completions_program, meson.global_source_root() / 'src', 'fish'],
20+
depends: [toolbox_go],
21+
install: true,
22+
install_dir: fishcompletionsdir,
23+
output: 'toolbox.fish'
2524
)
25+
endif
2626

2727
custom_target(
2828
'zsh-completion',
2929
capture: true,
3030
command: [generate_completions_program, meson.global_source_root() / 'src', 'zsh'],
3131
depends: [toolbox_go],
3232
install: true,
33-
install_dir: get_option('datadir') / 'zsh' / 'site-functions',
33+
install_dir: zshcompletionsdir,
3434
output: '_toolbox'
3535
)
36-
37-
custom_target(
38-
'fish-completion',
39-
capture: true,
40-
command: [generate_completions_program, meson.global_source_root() / 'src', 'fish'],
41-
depends: [toolbox_go],
42-
install: true,
43-
install_dir: fishcompletionsdir,
44-
output: 'toolbox.fish'
45-
)

meson.build

+20-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@ go_md2man = find_program('go-md2man')
1818
shellcheck = find_program('shellcheck', required: false)
1919
skopeo = find_program('skopeo', required: false)
2020

21-
bash_completion_dep = dependency('bash-completion', required: false)
22-
fish_dep = dependency('fish', required: false)
21+
bashcompletionsdir = get_option('bash_completions_dir')
22+
if bashcompletionsdir == ''
23+
bash_completion_dep = dependency('bash-completion', required: false)
24+
if bash_completion_dep.found()
25+
bashcompletionsdir = bash_completion_dep.get_variable(pkgconfig: 'completionsdir')
26+
endif
27+
endif
28+
29+
fishcompletionsdir = get_option('fish_completions_dir')
30+
if fishcompletionsdir == ''
31+
fish_completion_dep = dependency('fish', required: false)
32+
if fish_completion_dep.found()
33+
fishcompletionsdir = fish_completion_dep.get_variable(pkgconfig: 'completionsdir')
34+
endif
35+
endif
2336

2437
migration_path_for_coreos_toolbox = get_option('migration_path_for_coreos_toolbox')
2538
profiledir = get_option('profile_dir')
@@ -33,6 +46,11 @@ if tmpfilesdir == '' or not fs.exists('/run/.containerenv')
3346
endif
3447
endif
3548

49+
zshcompletionsdir = get_option('zsh_completions_dir')
50+
if zshcompletionsdir == ''
51+
zshcompletionsdir = join_paths(get_option('datadir'), 'zsh', 'site-functions')
52+
endif
53+
3654
toolbox_sh = files('toolbox')
3755

3856
if shellcheck.found()

meson_options.txt

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
option(
2+
'bash_completions_dir',
3+
description: 'Directory for Bash completion scripts',
4+
type: 'string',
5+
)
6+
7+
option(
8+
'fish_completions_dir',
9+
description: 'Directory for fish completion scripts',
10+
type: 'string',
11+
)
12+
113
option(
214
'migration_path_for_coreos_toolbox',
315
description: 'Offer a migration path to users of github.com/coreos/toolbox',
@@ -17,3 +29,9 @@ option(
1729
description: 'Directory for system-wide tmpfiles.d(5) files',
1830
type: 'string',
1931
)
32+
33+
option(
34+
'zsh_completions_dir',
35+
description: 'Directory for Z shell completion scripts (default=$datadir/zsh/site-functions)',
36+
type: 'string',
37+
)

0 commit comments

Comments
 (0)