forked from containers/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Set to 'True' by default. 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
- Loading branch information
1 parent
d69ce67
commit bafbbe8
Showing
6 changed files
with
89 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright © 2022 Ondřej Míchal | ||
# Copyright © 2022 Red Hat Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
if len(sys.argv) != 3: | ||
print('{}: wrong arguments'.format(sys.argv[0]), file=sys.stderr) | ||
print('Usage: {} [SOURCE DIR] [COMPLETION TYPE]'.format(sys.argv[0]), file=sys.stderr) | ||
print() | ||
print("SOURCE DIR is path to the Toolbox Go source code") | ||
print("COMPLETION TYPE is either 'bash', 'zsh' or 'fish'") | ||
sys.exit(1) | ||
|
||
source_dir = sys.argv[1] | ||
completion_type = sys.argv[2] | ||
|
||
try: | ||
os.chdir(source_dir) | ||
output = subprocess.run(['go', 'run', '.', 'completion', completion_type], check=True) | ||
except subprocess.CalledProcessError as e: | ||
print('{}: go run returned non-zero exit status {}'.format(sys.argv[0], e.returncode), file=sys.stderr) | ||
sys.exit(e.returncode) | ||
|
||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
generate_completions_program = find_program('generate_completions.py') | ||
|
||
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', | ||
capture: true, | ||
command: [generate_completions_program, meson.global_source_root() / 'src', 'bash'], | ||
install: true, | ||
install_dir: bash_comp_dir, | ||
output: 'toolbox') | ||
|
||
completion_zsh = custom_target('zsh-completion', | ||
capture: true, | ||
command: [generate_completions_program, meson.global_source_root() / 'src', 'zsh'], | ||
install: true, | ||
install_dir: get_option('datadir') / 'zsh' / 'site_functions', | ||
output: '_toolbox') | ||
|
||
completion_fish = custom_target('fish-completion', | ||
capture: true, | ||
command: [generate_completions_program, meson.global_source_root() / 'src', 'fish'], | ||
install: true, | ||
install_dir: fish_comp_dir, | ||
output: 'toolbox.fish') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters