aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mdevenv.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-02-22 15:14:58 -0500
committerXavier Claessens <xclaesse@gmail.com>2022-02-28 09:03:27 -0500
commit6fafeb13b3b115b5fddf371b6b7624801559b99f (patch)
treef07d6d7546a19c07c6963774c585ab70ca5656f6 /mesonbuild/mdevenv.py
parent79c6075b560dbf1c3e4e0b30f1c472dc2086421e (diff)
downloadmeson-6fafeb13b3b115b5fddf371b6b7624801559b99f.zip
meson-6fafeb13b3b115b5fddf371b6b7624801559b99f.tar.gz
meson-6fafeb13b3b115b5fddf371b6b7624801559b99f.tar.bz2
devenv: Source bash completion scripts
Diffstat (limited to 'mesonbuild/mdevenv.py')
-rw-r--r--mesonbuild/mdevenv.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py
index 3c522a6..3bd66ef 100644
--- a/mesonbuild/mdevenv.py
+++ b/mesonbuild/mdevenv.py
@@ -3,10 +3,12 @@ import argparse
import tempfile
from pathlib import Path
-from . import build
-from .mesonlib import MesonException, RealPathAction, is_windows, setup_vsenv
+from . import build, minstall, dependencies
+from .mesonlib import MesonException, RealPathAction, is_windows, setup_vsenv, OptionKey
import typing as T
+if T.TYPE_CHECKING:
+ from .backends import InstallData
def add_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument('-C', dest='wd', action=RealPathAction,
@@ -36,11 +38,30 @@ def get_env(b: build.Build, build_dir: str) -> T.Dict[str, str]:
return extra_env.get_env(env)
+def bash_completion_files(b: build.Build, install_data: 'InstallData') -> T.List[str]:
+ result = []
+ dep = dependencies.PkgConfigDependency('bash-completion', b.environment,
+ {'silent': True, 'version': '>=2.10'})
+ if dep.found():
+ prefix = b.environment.coredata.get_option(OptionKey('prefix'))
+ assert isinstance(prefix, str), 'for mypy'
+ datadir = b.environment.coredata.get_option(OptionKey('datadir'))
+ assert isinstance(datadir, str), 'for mypy'
+ datadir_abs = os.path.join(prefix, datadir)
+ completionsdir = dep.get_variable(pkgconfig='completionsdir', pkgconfig_define=['datadir', datadir_abs])
+ assert isinstance(completionsdir, str), 'for mypy'
+ completionsdir_path = Path(completionsdir)
+ for f in install_data.data:
+ if completionsdir_path in Path(f.install_path).parents:
+ result.append(f.path)
+ return result
+
def run(options: argparse.Namespace) -> int:
buildfile = Path(options.wd) / 'meson-private' / 'build.dat'
if not buildfile.is_file():
raise MesonException(f'Directory {options.wd!r} does not seem to be a Meson build directory.')
b = build.load(options.wd)
+ install_data = minstall.load_install_data(str(buildfile.parent / 'install.dat'))
setup_vsenv(b.need_vsenv)
devenv = get_env(b, options.wd)
@@ -64,12 +85,15 @@ def run(options: argparse.Namespace) -> int:
args += ['/k', f'prompt {prompt_prefix} $P$G']
else:
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
- if "bash" in args[0] and not os.environ.get("MESON_DISABLE_PS1_OVERRIDE"):
+ if "bash" in args[0]:
+ # Let the GC remove the tmp file
tmprc = tempfile.NamedTemporaryFile(mode='w')
tmprc.write('[ -e ~/.bashrc ] && . ~/.bashrc\n')
- tmprc.write(f'export PS1="{prompt_prefix} $PS1"')
+ if not os.environ.get("MESON_DISABLE_PS1_OVERRIDE"):
+ tmprc.write(f'export PS1="{prompt_prefix} $PS1"\n')
+ for f in bash_completion_files(b, install_data):
+ tmprc.write(f'. "{f}"\n')
tmprc.flush()
- # Let the GC remove the tmp file
args.append("--rcfile")
args.append(tmprc.name)