Skip to content

Commit

Permalink
build: Add options to override the locations for the shell completions
Browse files Browse the repository at this point in the history
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#1123
containers#840
  • Loading branch information
debarshiray committed Sep 12, 2022
1 parent 299fab4 commit 459acab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 33 deletions.
52 changes: 21 additions & 31 deletions completion/meson.build
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
generate_completions_program = find_program('generate_completions.py')

if bash_completion_dep.found()
bashcompletionsdir = bash_completion_dep.get_variable(pkgconfig: 'completionsdir')
else
bashcompletionsdir = get_option('datadir') / 'bash-completion' / 'completions'
message('bash-completion not found: using', get_option('prefix') / bashcompletionsdir, 'as a falback install directory')
endif

if fish_dep.found()
fishcompletionsdir = fish_dep.get_variable(pkgconfig: 'completionsdir')
else
fishcompletionsdir = get_option('datadir') / 'fish' / 'completions'
message('fish not found: using', get_option('prefix') / fishcompletionsdir, 'as a fallback install directory')
if bashcompletionsdir != ''
custom_target(
'bash-completion',
capture: true,
command: [generate_completions_program, meson.global_source_root() / 'src', 'bash'],
depends: [toolbox_go],
install: true,
install_dir: bashcompletionsdir,
output: 'toolbox'
)
endif

custom_target(
'bash-completion',
capture: true,
command: [generate_completions_program, meson.global_source_root() / 'src', 'bash'],
depends: [toolbox_go],
install: true,
install_dir: bashcompletionsdir,
output: 'toolbox'
if fishcompletionsdir != ''
custom_target(
'fish-completion',
capture: true,
command: [generate_completions_program, meson.global_source_root() / 'src', 'fish'],
depends: [toolbox_go],
install: true,
install_dir: fishcompletionsdir,
output: 'toolbox.fish'
)
endif

custom_target(
'zsh-completion',
capture: true,
command: [generate_completions_program, meson.global_source_root() / 'src', 'zsh'],
depends: [toolbox_go],
install: true,
install_dir: get_option('datadir') / 'zsh' / 'site-functions',
install_dir: zshcompletionsdir,
output: '_toolbox'
)

custom_target(
'fish-completion',
capture: true,
command: [generate_completions_program, meson.global_source_root() / 'src', 'fish'],
depends: [toolbox_go],
install: true,
install_dir: fishcompletionsdir,
output: 'toolbox.fish'
)
22 changes: 20 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@ go_md2man = find_program('go-md2man')
shellcheck = find_program('shellcheck', required: false)
skopeo = find_program('skopeo', required: false)

bash_completion_dep = dependency('bash-completion', required: false)
fish_dep = dependency('fish', required: false)
bashcompletionsdir = get_option('bash_completions_dir')
if bashcompletionsdir == ''
bash_completion_dep = dependency('bash-completion', required: false)
if bash_completion_dep.found()
bashcompletionsdir = bash_completion_dep.get_variable(pkgconfig: 'completionsdir')
endif
endif

fishcompletionsdir = get_option('fish_completions_dir')
if fishcompletionsdir == ''
fish_completion_dep = dependency('fish', required: false)
if fish_completion_dep.found()
fishcompletionsdir = fish_completion_dep.get_variable(pkgconfig: 'completionsdir')
endif
endif

migration_path_for_coreos_toolbox = get_option('migration_path_for_coreos_toolbox')
profiledir = get_option('profile_dir')
Expand All @@ -33,6 +46,11 @@ if tmpfilesdir == '' or not fs.exists('/run/.containerenv')
endif
endif

zshcompletionsdir = get_option('zsh_completions_dir')
if zshcompletionsdir == ''
zshcompletionsdir = join_paths(get_option('datadir'), 'zsh', 'site-functions')
endif

toolbox_sh = files('toolbox')

if shellcheck.found()
Expand Down
18 changes: 18 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
option(
'bash_completions_dir',
description: 'Directory for Bash completion scripts',
type: 'string',
)

option(
'fish_completions_dir',
description: 'Directory for fish completion scripts',
type: 'string',
)

option(
'migration_path_for_coreos_toolbox',
description: 'Offer a migration path to users of github.com/coreos/toolbox',
Expand All @@ -17,3 +29,9 @@ option(
description: 'Directory for system-wide tmpfiles.d(5) files',
type: 'string',
)

option(
'zsh_completions_dir',
description: 'Directory for Z shell completion scripts (default=$datadir/zsh/site-functions)',
type: 'string',
)

0 comments on commit 459acab

Please sign in to comment.