WIP unify
This commit is contained in:
parent
8d5e71f66b
commit
2acf90f7b7
@ -805,7 +805,7 @@ def load_external_modules(pkg):
|
|||||||
load_module(external_module)
|
load_module(external_module)
|
||||||
|
|
||||||
|
|
||||||
def setup_package(pkg, dirty, context: Context = Context.BUILD, interactive: bool = False):
|
def setup_package(pkg, dirty, context: Context = Context.BUILD):
|
||||||
"""Execute all environment setup routines."""
|
"""Execute all environment setup routines."""
|
||||||
if context not in (Context.BUILD, Context.TEST):
|
if context not in (Context.BUILD, Context.TEST):
|
||||||
raise ValueError(f"'context' must be Context.BUILD or Context.TEST - got {context}")
|
raise ValueError(f"'context' must be Context.BUILD or Context.TEST - got {context}")
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
from spack.context import Context
|
from spack.context import Context
|
||||||
|
|
||||||
description = (
|
description = (
|
||||||
"run a command in a spec's install environment, or dump its environment to screen or file"
|
"run a command in a spec's build environment, or dump its environment to screen or file"
|
||||||
)
|
)
|
||||||
section = "build"
|
section = "build"
|
||||||
level = "long"
|
level = "long"
|
||||||
@ -14,5 +14,7 @@
|
|||||||
setup_parser = env_utility.setup_parser
|
setup_parser = env_utility.setup_parser
|
||||||
|
|
||||||
|
|
||||||
|
#TODO create a dropin/dive funciton that dev_build and build_env cmd's can use
|
||||||
|
# create a default shell utility for picking the current shell to start with
|
||||||
def build_env(parser, args):
|
def build_env(parser, args):
|
||||||
env_utility.emulate_env_utility("build-env", Context.BUILD, args)
|
env_utility.emulate_env_utility("build-env", Context.BUILD, args)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
import spack.cmd
|
import spack.cmd
|
||||||
import spack.deptypes as dt
|
import spack.deptypes as dt
|
||||||
import spack.error
|
import spack.error
|
||||||
|
import spack.prompt
|
||||||
import spack.spec
|
import spack.spec
|
||||||
import spack.store
|
import spack.store
|
||||||
from spack import build_environment, traverse
|
from spack import build_environment, traverse
|
||||||
@ -26,7 +27,9 @@ def setup_parser(subparser):
|
|||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
"--pickle", metavar="FILE", help="dump a pickled source-able environment to FILE"
|
"--pickle", metavar="FILE", help="dump a pickled source-able environment to FILE"
|
||||||
)
|
)
|
||||||
subparser.add_argument("--dive", action="store_true", help="dive into the build-env in a subshell")
|
subparser.add_argument(
|
||||||
|
"--dive", action="store_true", help="dive into the build-env in a subshell"
|
||||||
|
)
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
"spec",
|
"spec",
|
||||||
nargs=argparse.REMAINDER,
|
nargs=argparse.REMAINDER,
|
||||||
@ -124,7 +127,7 @@ def emulate_env_utility(cmd_name, context: Context, args):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
build_environment.setup_package(spec.package, args.dirty, context)
|
mods = build_environment.setup_package(spec.package, args.dirty, context)
|
||||||
|
|
||||||
if args.dump:
|
if args.dump:
|
||||||
# Dump a source-able environment to a text file.
|
# Dump a source-able environment to a text file.
|
||||||
@ -136,13 +139,14 @@ def emulate_env_utility(cmd_name, context: Context, args):
|
|||||||
tty.msg("Pickling a source-able environment to {0}".format(args.pickle))
|
tty.msg("Pickling a source-able environment to {0}".format(args.pickle))
|
||||||
pickle_environment(args.pickle)
|
pickle_environment(args.pickle)
|
||||||
|
|
||||||
if args.dive:
|
|
||||||
os.execvp(cmd[0], [cmd[0]])
|
|
||||||
|
|
||||||
if cmd:
|
if cmd:
|
||||||
# Execute the command with the new environment
|
# Execute the command with the new environment
|
||||||
os.execvp(cmd[0], cmd)
|
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]])
|
||||||
|
|
||||||
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
|
||||||
# and print out env vars.
|
# and print out env vars.
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
import os
|
import os
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from llnl.util.tty.color import colorize
|
from llnl.util.tty.color import colorize
|
||||||
|
|
||||||
from spack.util.environment import EnvironmentModifications
|
from spack.util.environment import EnvironmentModifications
|
||||||
@ -19,16 +20,16 @@ def prompt_modifications(prompt, shell, env=os.environ):
|
|||||||
mods.set("SPACK_OLD_PROMPT", env.get("prompt", None))
|
mods.set("SPACK_OLD_PROMPT", env.get("prompt", None))
|
||||||
mods.set("prompt", prompt)
|
mods.set("prompt", prompt)
|
||||||
else:
|
else:
|
||||||
mods.set('SPACK_OLD_PS1', env.get('PS1', '$$$$'))
|
mods.set("SPACK_OLD_PS1", env.get("PS1", "$$$$"))
|
||||||
if 'TERM' in env and 'color' in env['TERM']:
|
if "TERM" in env and "color" in env["TERM"]:
|
||||||
if 'BASH' in env:
|
if "BASH" in env:
|
||||||
bash_color_prompt = colorize(f"@G{{{prompt}}}", color=True, enclose=True)
|
bash_color_prompt = colorize(f"@G{{{prompt}}}", color=True, enclose=True)
|
||||||
mods.set('PS1', f"{bash_color_prompt} {env.get('PS1','$ ')}")
|
mods.set("PS1", f"{bash_color_prompt} {env.get('PS1','$ ')}")
|
||||||
else:
|
else:
|
||||||
zsh_color_prompt = colorize(f"@G{{{prompt}}}", color=True, enclose=False, zsh=True)
|
zsh_color_prompt = colorize(f"@G{{{prompt}}}", color=True, enclose=False, zsh=True)
|
||||||
mods.set('PS1', f"{zsh_color_prompt} {env.get('PS1', '$ ')}")
|
mods.set("PS1", f"{zsh_color_prompt} {env.get('PS1', '$ ')}")
|
||||||
else:
|
else:
|
||||||
mods.set('PS1', f"{prompt} {env.get('PS1', '$ ')}")
|
mods.set("PS1", f"{prompt} {env.get('PS1', '$ ')}")
|
||||||
|
|
||||||
return mods
|
return mods
|
||||||
|
|
||||||
@ -70,4 +71,3 @@ def custom_prompt(prompt, shell):
|
|||||||
"""
|
"""
|
||||||
).lstrip("\n")
|
).lstrip("\n")
|
||||||
return cmds
|
return cmds
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user