Skip to content

Commit

Permalink
Generate & install completion scripts in build system
Browse files Browse the repository at this point in the history
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().

#840
  • Loading branch information
HarryMichal committed Nov 21, 2021
1 parent 717c53e commit e4e4783
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 109 deletions.
100 changes: 0 additions & 100 deletions completion/bash/toolbox

This file was deleted.

34 changes: 34 additions & 0 deletions completion/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if bash_completion.found()
bash_comp_dir = bash_completion.get_pkgconfig_variable('completionsdir')
else
bash_comp_dir = get_option('datadir') / 'bash-completion' / 'completions'
message('bash-completion not found: using', get_option('prefix') / bash_comp_dir, 'as a falback install directory')
endif

if fish.found()
fish_comp_dir = fish.get_pkgconfig_variable('completionsdir')
else
fish_comp_dir = get_option('datadir') / 'fish' / 'completions'
message('fish not found: using', get_option('prefix') / fish_comp_dir, 'as a fallback install directory')
endif

completion_bash = custom_target('bash-completion',
output: 'toolbox',
command: [toolbox_bin, 'completion', 'bash'],
capture: true,
install: true,
install_dir: bash_comp_dir)

completion_zsh = custom_target('zsh-completion',
output: '_toolbox',
command: [toolbox_bin, 'completion', 'zsh'],
capture: true,
install: true,
install_dir: get_option('datadir') / 'zsh' / 'site_functions')

completion_fish = custom_target('fish-completion',
output: 'toolbox.fish',
command: [toolbox_bin, 'completion', 'fish'],
capture: true,
install: true,
install_dir: fish_comp_dir)
13 changes: 5 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project(
'toolbox',
version: '0.0.99.2',
license: 'ASL 2.0',
meson_version: '>= 0.53.0',
meson_version: '>= 0.54.0',
)

go = find_program('go')
Expand All @@ -12,6 +12,7 @@ shellcheck = find_program('shellcheck', required: false)
skopeo = find_program('skopeo', required: false)

bash_completion = dependency('bash-completion', required: false)
fish = dependency('fish', required: false)

profiledir = get_option('profile_dir')

Expand All @@ -21,13 +22,6 @@ if tmpfilesdir == ''
tmpfilesdir = systemd_dep.get_pkgconfig_variable('tmpfilesdir')
endif

if bash_completion.found()
install_data(
'completion/bash/toolbox',
install_dir: bash_completion.get_pkgconfig_variable('completionsdir')
)
endif

if not skopeo.found()
message('Running system tests requires Skopeo for OCI image manipulation.')
endif
Expand Down Expand Up @@ -59,3 +53,6 @@ subdir('data')
subdir('doc')
subdir('profile.d')
subdir('src')
if get_option('install_completions')
subdir('completion')
endif
7 changes: 7 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ option(
description: 'Directory for system-wide tmpfiles.d(5) files',
type: 'string',
)

option(
'install_completions',
description: 'Install bash, zsh and fish command completions',
type: 'boolean',
value: true,
)
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sources = files(
'pkg/version/version.go',
)

custom_target(
toolbox_bin = custom_target(
'toolbox',
build_by_default: true,
command: [
Expand Down

0 comments on commit e4e4783

Please sign in to comment.