Add build-env --dive

This commit is contained in:
psakiev 2024-11-12 13:16:59 -07:00
parent 2acf90f7b7
commit 4216a06cd8
2 changed files with 37 additions and 2 deletions

View File

@ -17,6 +17,7 @@
from spack.cmd.common import arguments from spack.cmd.common import arguments
from spack.context import Context from spack.context import Context
from spack.util.environment import dump_environment, pickle_environment from spack.util.environment import dump_environment, pickle_environment
from spack.util.shell_detection import active_shell_type
def setup_parser(subparser): def setup_parser(subparser):
@ -144,8 +145,10 @@ def emulate_env_utility(cmd_name, context: Context, args):
os.execvp(cmd[0], cmd) os.execvp(cmd[0], cmd)
if args.dive: if args.dive:
mods.extend(spack.prompt.prompt_modifications(f"{spec.name}-build-env", cmd[0])) shell = active_shell_type()
os.execvp(cmd[0], [cmd[0]]) mods.extend(spack.prompt.prompt_modifications(f"{spec.name}-{str(context)}-env", shell))
mods.apply_modifications()
os.execvp(shell, [shell])
elif not bool(args.pickle or args.dump): elif not bool(args.pickle or args.dump):
# If no command or dump/pickle option then act like the "env" command # If no command or dump/pickle option then act like the "env" command

View File

@ -0,0 +1,32 @@
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import platform
import subprocess
from spack.error import SpackError
def active_shell_type(env=os.environ):
if platform.system() == "Windows":
if "POWERSHELL" in env:
return "ps1"
else:
try:
output = subprocess.run("powershell -Command \"echo $PSVersionTable\"", shell=True, check=True, text=True)
if "PSVersion" in output:
return "ps1"
else:
pass
except subprocess.CalledProcessError:
pass
raise SpackError("Unknown shell type being used on Windows")
else:
shell = env.get("SHELL", None)
if shell:
return shell
else:
raise SpackError("No shell type detected for the Unix process")