Skip to content

Commit 5b0a54d

Browse files
committed
build: Enable changing the completion paths & drop install_completions
The bash-completion and fish dependencies were already optional - the shell completions for Bash and fish won't be generated and installed if they are absent; and there's no dependency required for Z shell. So the install_completions build option wasn't reducing the dependency burden. The build option was a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. The only use-case for this is when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, because the locations for the completions advertised by the shells' APIs might not be accessible. Being able to disable the completions prevents the installation from failing. A different way of ensuring a smooth developer experience for a Toolbx hacker is to offer a way to change the locations where the shell completions are installed, which is necessary and beneficial for other use-cases. Z shell, unlike Bash's bash-completion.pc and fish's fish.pc, doesn't offer an API to detect the location for the shell completions. This means that 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.pc as a build dependency [3]. Fallout from bafbbe8 [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#1123 containers#840
1 parent a6d7104 commit 5b0a54d

File tree

3 files changed

+60
-43
lines changed

3 files changed

+60
-43
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

+21-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,26 @@ 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
36+
37+
zshcompletionsdir = get_option('zsh_completions_dir')
38+
if zshcompletionsdir == ''
39+
zshcompletionsdir = join_paths(get_option('datadir'), 'zsh', 'site-functions')
40+
endif
2341

2442
migration_path_for_coreos_toolbox = get_option('migration_path_for_coreos_toolbox')
2543
profiledir = get_option('profile_dir')
@@ -66,12 +84,10 @@ install_subdir(
6684
]
6785
)
6886

87+
subdir('completion')
6988
subdir('data')
7089
subdir('doc')
7190
subdir('profile.d')
7291
subdir('src')
73-
if get_option('install_completions')
74-
subdir('completion')
75-
endif
7692

7793
meson.add_install_script('meson_post_install.py')

meson_options.txt

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
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+
13+
option(
14+
'zsh_completions_dir',
15+
description: 'Directory for Z shell completion scripts (default=$datadir/zsh/site-functions)',
16+
type: 'string',
17+
)
18+
119
option(
220
'migration_path_for_coreos_toolbox',
321
description: 'Offer a migration path to users of github.com/coreos/toolbox',
@@ -17,10 +35,3 @@ option(
1735
description: 'Directory for system-wide tmpfiles.d(5) files',
1836
type: 'string',
1937
)
20-
21-
option(
22-
'install_completions',
23-
description: 'Install bash, zsh and fish command completions',
24-
type: 'boolean',
25-
value: true,
26-
)

0 commit comments

Comments
 (0)