aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mdevenv.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-09-18 13:53:49 -0400
committerXavier Claessens <xclaesse@gmail.com>2022-09-21 18:32:51 -0400
commit31a6633e62b760b3bd7314b543cc4ebc43292090 (patch)
treebed35fb267603263b1830b321ae036aa7e736b2d /mesonbuild/mdevenv.py
parentbb4c8c07f80a9d5503655e38f5073adce663aaa5 (diff)
downloadmeson-31a6633e62b760b3bd7314b543cc4ebc43292090.zip
meson-31a6633e62b760b3bd7314b543cc4ebc43292090.tar.gz
meson-31a6633e62b760b3bd7314b543cc4ebc43292090.tar.bz2
mdevenv: powershell <7.0 is EOL, prefer using pwsh.exe
If neither pwsh.exe nor powershell.exe works, fallback to cmd.exe. This script could be failing because of virus scanner.
Diffstat (limited to 'mesonbuild/mdevenv.py')
-rw-r--r--mesonbuild/mdevenv.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py
index 8a5b5ba..2fb7904 100644
--- a/mesonbuild/mdevenv.py
+++ b/mesonbuild/mdevenv.py
@@ -13,6 +13,8 @@ import typing as T
if T.TYPE_CHECKING:
from .backends import InstallData
+POWERSHELL_EXES = {'pwsh.exe', 'powershell.exe'}
+
def add_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument('-C', dest='wd', action=RealPathAction,
help='Directory to cd into before running')
@@ -21,12 +23,17 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument('command', nargs=argparse.REMAINDER,
help='Command to run in developer environment (default: interactive shell)')
-def get_windows_shell() -> str:
+def get_windows_shell() -> T.Optional[str]:
mesonbuild = Path(__file__).parent
script = mesonbuild / 'scripts' / 'cmd_or_ps.ps1'
- command = ['powershell.exe', '-noprofile', '-executionpolicy', 'bypass', '-file', str(script)]
- result = subprocess.check_output(command)
- return result.decode().strip()
+ for shell in POWERSHELL_EXES:
+ try:
+ command = [shell, '-noprofile', '-executionpolicy', 'bypass', '-file', str(script)]
+ result = subprocess.check_output(command)
+ return result.decode().strip()
+ except (subprocess.CalledProcessError, OSError):
+ pass
+ return None
def reduce_winepath(env: T.Dict[str, str]) -> None:
winepath = env.get('WINEPATH')
@@ -145,7 +152,9 @@ def run(options: argparse.Namespace) -> int:
args = [shell_env]
elif is_windows():
shell = get_windows_shell()
- if shell in ['powershell.exe', 'pwsh.exe']:
+ if not shell:
+ 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]