Skip to content

Commit 333dbfa

Browse files
committed
Generate & install completion scripts in build system
The previous commit added a means to generating the completion scripts and this one plugs that into the build system. A new build option 'install_completions' has been introduced. Completions for bash and fish use pkg-config for getting the preferred install locations for the completions. If the packages are not available, fallbacks are in-place. The 'completion' subdir has been kept to work around the ideology of Meson that does not allow creating/outputing files in subdirectories nor using the output of custom_target() in install_data(). containers#840
1 parent b3e4bde commit 333dbfa

File tree

6 files changed

+49
-110
lines changed

6 files changed

+49
-110
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ The following dependencies are required to build it:
7979
- ninja
8080
- patchelf
8181

82-
The following dependencies enable various optional features:
82+
The following dependencies provide information on where to install shell completions:
8383
- bash-completion
84+
- fish
8485

8586
It can be built and installed as any other typical Meson-based project:
8687
```console

completion/bash/toolbox

-100
This file was deleted.

completion/meson.build

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if bash_completion.found()
2+
bash_comp_dir = bash_completion.get_pkgconfig_variable('completionsdir')
3+
else
4+
bash_comp_dir = get_option('datadir') / 'bash-completion' / 'completions'
5+
message('bash-completion not found: using', get_option('prefix') / bash_comp_dir, 'as a falback install directory')
6+
endif
7+
8+
if fish.found()
9+
fish_comp_dir = fish.get_pkgconfig_variable('completionsdir')
10+
else
11+
fish_comp_dir = get_option('datadir') / 'fish' / 'completions'
12+
message('fish not found: using', get_option('prefix') / fish_comp_dir, 'as a fallback install directory')
13+
endif
14+
15+
completion_bash = custom_target('bash-completion',
16+
capture: true,
17+
command: [toolbox_bin, 'completion', 'bash'],
18+
install: true,
19+
install_dir: bash_comp_dir,
20+
output: 'toolbox')
21+
22+
completion_zsh = custom_target('zsh-completion',
23+
capture: true,
24+
command: [toolbox_bin, 'completion', 'zsh'],
25+
install: true,
26+
install_dir: get_option('datadir') / 'zsh' / 'site_functions',
27+
output: '_toolbox')
28+
29+
completion_fish = custom_target('fish-completion',
30+
capture: true,
31+
command: [toolbox_bin, 'completion', 'fish'],
32+
install: true,
33+
install_dir: fish_comp_dir,
34+
output: 'toolbox.fish')

meson.build

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project(
22
'toolbox',
33
version: '0.0.99.2',
44
license: 'ASL 2.0',
5-
meson_version: '>= 0.53.0',
5+
meson_version: '>= 0.54.0',
66
)
77

88
go = find_program('go')
@@ -12,6 +12,7 @@ shellcheck = find_program('shellcheck', required: false)
1212
skopeo = find_program('skopeo', required: false)
1313

1414
bash_completion = dependency('bash-completion', required: false)
15+
fish = dependency('fish', required: false)
1516

1617
profiledir = get_option('profile_dir')
1718

@@ -21,13 +22,6 @@ if tmpfilesdir == ''
2122
tmpfilesdir = systemd_dep.get_pkgconfig_variable('tmpfilesdir')
2223
endif
2324

24-
if bash_completion.found()
25-
install_data(
26-
'completion/bash/toolbox',
27-
install_dir: bash_completion.get_pkgconfig_variable('completionsdir')
28-
)
29-
endif
30-
3125
if not skopeo.found()
3226
message('Running system tests requires Skopeo for OCI image manipulation.')
3327
endif
@@ -59,3 +53,6 @@ subdir('data')
5953
subdir('doc')
6054
subdir('profile.d')
6155
subdir('src')
56+
if get_option('install_completions')
57+
subdir('completion')
58+
endif

meson_options.txt

+7
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ option(
1010
description: 'Directory for system-wide tmpfiles.d(5) files',
1111
type: 'string',
1212
)
13+
14+
option(
15+
'install_completions',
16+
description: 'Install bash, zsh and fish command completions',
17+
type: 'boolean',
18+
value: true,
19+
)

src/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sources = files(
2020
'pkg/version/version.go',
2121
)
2222

23-
custom_target(
23+
toolbox_bin = custom_target(
2424
'toolbox',
2525
build_by_default: true,
2626
command: [

0 commit comments

Comments
 (0)