Add build-env --dive
This commit is contained in:
parent
2acf90f7b7
commit
4216a06cd8
@ -17,6 +17,7 @@
|
||||
from spack.cmd.common import arguments
|
||||
from spack.context import Context
|
||||
from spack.util.environment import dump_environment, pickle_environment
|
||||
from spack.util.shell_detection import active_shell_type
|
||||
|
||||
|
||||
def setup_parser(subparser):
|
||||
@ -144,8 +145,10 @@ def emulate_env_utility(cmd_name, context: Context, args):
|
||||
os.execvp(cmd[0], cmd)
|
||||
|
||||
if args.dive:
|
||||
mods.extend(spack.prompt.prompt_modifications(f"{spec.name}-build-env", cmd[0]))
|
||||
os.execvp(cmd[0], [cmd[0]])
|
||||
shell = active_shell_type()
|
||||
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):
|
||||
# If no command or dump/pickle option then act like the "env" command
|
||||
|
32
lib/spack/spack/util/shell_detection.py
Normal file
32
lib/spack/spack/util/shell_detection.py
Normal 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")
|
Loading…
Reference in New Issue
Block a user