Skip to content

Commit

Permalink
build: Remove the install_completions option
Browse files Browse the repository at this point in the history
The bash-completion and fish dependencies are already optional, and
there's no dependency required for Z shell.  The shell completions for
Bash and fish won't be generated and installed if they are absent.  So
the build option isn't reducing the dependency burden.

The build option is 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 in the shells' APIs might not
be accessible.  Being able to disable the completions prevents the
installation from failing.

Fallout from bafbbe8

containers#1123
containers#840

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#1123
containers#840
  • Loading branch information
debarshiray committed Sep 12, 2022
1 parent beb480b commit 837bea4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 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'
)
26 changes: 21 additions & 5 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 Expand Up @@ -70,8 +88,6 @@ subdir('data')
subdir('doc')
subdir('profile.d')
subdir('src')
if get_option('install_completions')
subdir('completion')
endif
subdir('completion')

meson.add_install_script('meson_post_install.py')
19 changes: 15 additions & 4 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 @@ -19,8 +31,7 @@ option(
)

option(
'install_completions',
description: 'Install bash, zsh and fish command completions',
type: 'boolean',
value: true,
'zsh_completions_dir',
description: 'Directory for Z shell completion scripts (default=$datadir/zsh/site-functions)',
type: 'string',
)

0 comments on commit 837bea4

Please sign in to comment.