aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mdevenv.py
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2022-02-04 20:37:56 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2022-02-20 14:25:18 +0200
commit5d64a15be7e66cfa5573924efeff5dc1e3a39b3e (patch)
tree216673a8f4558b7ec1c60af087e63ce38984603d /mesonbuild/mdevenv.py
parente8e7fd98e280baa346a13a75c337832a4fd7f66a (diff)
downloadmeson-5d64a15be7e66cfa5573924efeff5dc1e3a39b3e.zip
meson-5d64a15be7e66cfa5573924efeff5dc1e3a39b3e.tar.gz
meson-5d64a15be7e66cfa5573924efeff5dc1e3a39b3e.tar.bz2
devenv: support bash under MSYS2 by default
Currently it tries to run "cmd" by default in a MSYS2 bash. Passing "bash" doesn't work since that defaults to WSL and one has to pass an absolute path to bash instead, and even then one misses out on the PS1 override. In case $SHELL is set and the contained path exists prefer it even if we are on Windows. To make the PS1 override work we can't use Unix paths in Python since we might be on Windows, so move the .bashrc check into the temporary bash script itself. This makes "meson devenv" work the same under MSYS2 as on Linux.
Diffstat (limited to 'mesonbuild/mdevenv.py')
-rw-r--r--mesonbuild/mdevenv.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py
index eb05020..3c522a6 100644
--- a/mesonbuild/mdevenv.py
+++ b/mesonbuild/mdevenv.py
@@ -48,7 +48,11 @@ def run(options: argparse.Namespace) -> int:
args = options.command
if not args:
prompt_prefix = f'[{b.project_name}]'
- if is_windows():
+ shell_env = os.environ.get("SHELL")
+ # Prefer $SHELL in a MSYS2 bash despite it being Windows
+ if shell_env and os.path.exists(shell_env):
+ args = [shell_env]
+ elif is_windows():
shell = get_windows_shell()
if shell == 'powershell.exe':
args = ['powershell.exe']
@@ -62,9 +66,7 @@ def run(options: argparse.Namespace) -> int:
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
if "bash" in args[0] and not os.environ.get("MESON_DISABLE_PS1_OVERRIDE"):
tmprc = tempfile.NamedTemporaryFile(mode='w')
- bashrc = os.path.expanduser('~/.bashrc')
- if os.path.exists(bashrc):
- tmprc.write(f'. {bashrc}\n')
+ tmprc.write('[ -e ~/.bashrc ] && . ~/.bashrc\n')
tmprc.write(f'export PS1="{prompt_prefix} $PS1"')
tmprc.flush()
# Let the GC remove the tmp file