Add "spack [cd|location] --source-dir" (#22321)
This commit is contained in:
parent
3d7069e039
commit
8b16728fd9
@ -47,9 +47,13 @@ def setup_parser(subparser):
|
|||||||
directories.add_argument(
|
directories.add_argument(
|
||||||
'-S', '--stages', action='store_true',
|
'-S', '--stages', action='store_true',
|
||||||
help="top level stage directory")
|
help="top level stage directory")
|
||||||
|
directories.add_argument(
|
||||||
|
'--source-dir', action='store_true',
|
||||||
|
help="source directory for a spec "
|
||||||
|
"(requires it to be staged first)")
|
||||||
directories.add_argument(
|
directories.add_argument(
|
||||||
'-b', '--build-dir', action='store_true',
|
'-b', '--build-dir', action='store_true',
|
||||||
help="checked out or expanded source directory for a spec "
|
help="build directory for a spec "
|
||||||
"(requires it to be staged first)")
|
"(requires it to be staged first)")
|
||||||
directories.add_argument(
|
directories.add_argument(
|
||||||
'-e', '--env', action='store',
|
'-e', '--env', action='store',
|
||||||
@ -61,64 +65,78 @@ def setup_parser(subparser):
|
|||||||
def location(parser, args):
|
def location(parser, args):
|
||||||
if args.module_dir:
|
if args.module_dir:
|
||||||
print(spack.paths.module_path)
|
print(spack.paths.module_path)
|
||||||
|
return
|
||||||
|
|
||||||
elif args.spack_root:
|
if args.spack_root:
|
||||||
print(spack.paths.prefix)
|
print(spack.paths.prefix)
|
||||||
|
return
|
||||||
|
|
||||||
elif args.env:
|
if args.env:
|
||||||
path = spack.environment.root(args.env)
|
path = spack.environment.root(args.env)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
tty.die("no such environment: '%s'" % args.env)
|
tty.die("no such environment: '%s'" % args.env)
|
||||||
print(path)
|
print(path)
|
||||||
|
return
|
||||||
|
|
||||||
elif args.packages:
|
if args.packages:
|
||||||
print(spack.repo.path.first_repo().root)
|
print(spack.repo.path.first_repo().root)
|
||||||
|
return
|
||||||
|
|
||||||
elif args.stages:
|
if args.stages:
|
||||||
print(spack.stage.get_stage_root())
|
print(spack.stage.get_stage_root())
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
|
||||||
specs = spack.cmd.parse_specs(args.spec)
|
specs = spack.cmd.parse_specs(args.spec)
|
||||||
|
|
||||||
if not specs:
|
if not specs:
|
||||||
tty.die("You must supply a spec.")
|
tty.die("You must supply a spec.")
|
||||||
|
|
||||||
if len(specs) != 1:
|
if len(specs) != 1:
|
||||||
tty.die("Too many specs. Supply only one.")
|
tty.die("Too many specs. Supply only one.")
|
||||||
|
|
||||||
if args.install_dir:
|
|
||||||
# install_dir command matches against installed specs.
|
# install_dir command matches against installed specs.
|
||||||
|
if args.install_dir:
|
||||||
env = ev.get_env(args, 'location')
|
env = ev.get_env(args, 'location')
|
||||||
spec = spack.cmd.disambiguate_spec(specs[0], env)
|
spec = spack.cmd.disambiguate_spec(specs[0], env)
|
||||||
print(spec.prefix)
|
print(spec.prefix)
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
|
||||||
spec = specs[0]
|
spec = specs[0]
|
||||||
|
|
||||||
|
# Package dir just needs the spec name
|
||||||
if args.package_dir:
|
if args.package_dir:
|
||||||
# This one just needs the spec name.
|
|
||||||
print(spack.repo.path.dirname_for_package_name(spec.name))
|
print(spack.repo.path.dirname_for_package_name(spec.name))
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
# Either concretize or filter from already concretized environment
|
||||||
spec = spack.cmd.matching_spec_from_env(spec)
|
spec = spack.cmd.matching_spec_from_env(spec)
|
||||||
pkg = spec.package
|
pkg = spec.package
|
||||||
|
|
||||||
if args.stage_dir:
|
if args.stage_dir:
|
||||||
print(pkg.stage.path)
|
print(pkg.stage.path)
|
||||||
|
return
|
||||||
|
|
||||||
else: # args.build_dir is the default.
|
if args.build_dir:
|
||||||
if not pkg.stage.expanded:
|
|
||||||
tty.die("Build directory does not exist yet. "
|
|
||||||
"Run this to create it:",
|
|
||||||
"spack stage " + " ".join(args.spec))
|
|
||||||
|
|
||||||
# Out of source builds have build_directory defined
|
# Out of source builds have build_directory defined
|
||||||
if hasattr(pkg, 'build_directory'):
|
if hasattr(pkg, 'build_directory'):
|
||||||
# build_directory can be either absolute or relative
|
# build_directory can be either absolute or relative to the stage path
|
||||||
# to the stage path in either case os.path.join makes it
|
# in either case os.path.join makes it absolute
|
||||||
# absolute
|
|
||||||
print(os.path.normpath(os.path.join(
|
print(os.path.normpath(os.path.join(
|
||||||
pkg.stage.path,
|
pkg.stage.path,
|
||||||
pkg.build_directory
|
pkg.build_directory
|
||||||
)))
|
)))
|
||||||
else:
|
return
|
||||||
|
|
||||||
# Otherwise assume in-source builds
|
# Otherwise assume in-source builds
|
||||||
return print(pkg.stage.source_path)
|
print(pkg.stage.source_path)
|
||||||
|
return
|
||||||
|
|
||||||
|
# source and build dir remain, they require the spec to be staged
|
||||||
|
if not pkg.stage.expanded:
|
||||||
|
tty.die("Source directory does not exist yet. "
|
||||||
|
"Run this to create it:",
|
||||||
|
"spack stage " + " ".join(args.spec))
|
||||||
|
|
||||||
|
if args.source_dir:
|
||||||
|
print(pkg.stage.source_path)
|
||||||
|
return
|
||||||
|
@ -52,18 +52,24 @@ def test_location_build_dir(mock_spec):
|
|||||||
assert location('--build-dir', spec.name).strip() == pkg.stage.source_path
|
assert location('--build-dir', spec.name).strip() == pkg.stage.source_path
|
||||||
|
|
||||||
|
|
||||||
def test_location_build_dir_missing():
|
def test_location_source_dir(mock_spec):
|
||||||
"""Tests spack location --build-dir with a missing build directory."""
|
"""Tests spack location --source-dir."""
|
||||||
|
spec, pkg = mock_spec
|
||||||
|
assert location('--source-dir', spec.name).strip() == pkg.stage.source_path
|
||||||
|
|
||||||
|
|
||||||
|
def test_location_source_dir_missing():
|
||||||
|
"""Tests spack location --source-dir with a missing source directory."""
|
||||||
spec = 'mpileaks'
|
spec = 'mpileaks'
|
||||||
prefix = "==> Error: "
|
prefix = "==> Error: "
|
||||||
expected = "%sBuild directory does not exist yet. Run this to create it:"\
|
expected = "%sSource directory does not exist yet. Run this to create it:"\
|
||||||
"%s spack stage %s" % (prefix, os.linesep, spec)
|
"%s spack stage %s" % (prefix, os.linesep, spec)
|
||||||
out = location('--build-dir', spec, fail_on_error=False).strip()
|
out = location('--source-dir', spec, fail_on_error=False).strip()
|
||||||
assert out == expected
|
assert out == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('options', [([]),
|
@pytest.mark.parametrize('options', [([]),
|
||||||
(['--build-dir', 'mpileaks']),
|
(['--source-dir', 'mpileaks']),
|
||||||
(['--env', 'missing-env']),
|
(['--env', 'missing-env']),
|
||||||
(['spec1', 'spec2'])])
|
(['spec1', 'spec2'])])
|
||||||
def test_location_cmd_error(options):
|
def test_location_cmd_error(options):
|
||||||
|
@ -453,7 +453,7 @@ _spack_buildcache_update_index() {
|
|||||||
_spack_cd() {
|
_spack_cd() {
|
||||||
if $list_options
|
if $list_options
|
||||||
then
|
then
|
||||||
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages -b --build-dir -e --env"
|
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages --source-dir -b --build-dir -e --env"
|
||||||
else
|
else
|
||||||
_all_packages
|
_all_packages
|
||||||
fi
|
fi
|
||||||
@ -1089,7 +1089,7 @@ _spack_load() {
|
|||||||
_spack_location() {
|
_spack_location() {
|
||||||
if $list_options
|
if $list_options
|
||||||
then
|
then
|
||||||
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages -b --build-dir -e --env"
|
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages --source-dir -b --build-dir -e --env"
|
||||||
else
|
else
|
||||||
_all_packages
|
_all_packages
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user