Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions mesonbuild/mdevenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import sys
import itertools
import signal
import typing as T

from pathlib import Path
Expand Down Expand Up @@ -201,6 +202,8 @@ def run(options: argparse.Namespace) -> int:
args = options.devcmd
if not args:
prompt_prefix = f'[{b.project_name}]'
if os.environ.get("MESON_DISABLE_PS1_OVERRIDE"):
prompt_prefix = None
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):
Expand All @@ -211,8 +214,9 @@ def run(options: argparse.Namespace) -> int:
mlog.warning('Failed to determine Windows shell, fallback to cmd.exe')
if shell in POWERSHELL_EXES:
args = [shell, '-NoLogo', '-NoExit']
prompt = f'function global:prompt {{ "{prompt_prefix} PS " + $PWD + "> "}}'
args += ['-Command', prompt]
if prompt_prefix:
prompt = f'function global:prompt {{ "{prompt_prefix} PS " + $PWD + "> "}}'
args += ['-Command', prompt]
else:
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
args += ['/k', f'prompt {prompt_prefix} $P$G']
Expand All @@ -222,13 +226,33 @@ def run(options: argparse.Namespace) -> int:
# Let the GC remove the tmp file
tmprc = tempfile.NamedTemporaryFile(mode='w')
tmprc.write('[ -e ~/.bashrc ] && . ~/.bashrc\n')
if not os.environ.get("MESON_DISABLE_PS1_OVERRIDE"):
if prompt_prefix:
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()
args.append("--rcfile")
args.append(tmprc.name)
elif args[0].endswith('fish'):
# Ignore SIGINT while using fish as the shell to make it behave
# like other shells such as bash and zsh.
# See: https://gitlab.freedesktop.org/gstreamer/gst-build/issues/18
signal.signal(signal.SIGINT, lambda _, __: True)
if prompt_prefix:
args.append('--init-command')
prompt_cmd = f'''functions --copy fish_prompt original_fish_prompt
function fish_prompt
echo -n '[{prompt_prefix}] '(original_fish_prompt)
end'''
args.append(prompt_cmd)
elif args[0].endswith('zsh'):
# Let the GC remove the tmp file
tmpdir = tempfile.TemporaryDirectory()
with open(os.path.join(tmpdir.name, '.zshrc'), 'w') as zshrc: # pylint: disable=unspecified-encoding
zshrc.write('[ -e ~/.zshrc ] && . ~/.zshrc\n')
if prompt_prefix:
zshrc.write(f'export PROMPT="[{prompt_prefix}] $PROMPT"\n')
devenv['ZDOTDIR'] = tmpdir.name
if 'DYLD_LIBRARY_PATH' in devenv and macos_sip_enabled():
mlog.warning('macOS System Integrity Protection is enabled: DYLD_LIBRARY_PATH cannot be set in the subshell')
mlog.warning('To fix that, use `meson devenv --dump dev.env && source dev.env`')
Expand Down
Loading