spack spec: add --reuse argument

This commit is contained in:
Massimiliano Culpo 2021-11-03 15:09:45 +01:00 committed by Todd Gamblin
parent 652fa663b5
commit 290f57c779
5 changed files with 35 additions and 18 deletions

View file

@ -320,3 +320,11 @@ def add_cdash_args(subparser, add_help):
default=None,
help=cdash_help['buildstamp']
)
@arg
def reuse():
return Args(
'--reuse', action='store_true', default=False,
help='reuse installed dependencies'
)

View file

@ -44,7 +44,8 @@ def setup_parser(subparser):
# Below are arguments w.r.t. spec display (like spack spec)
arguments.add_common_arguments(
subparser, ['long', 'very_long', 'install_status'])
subparser, ['long', 'very_long', 'install_status', 'reuse']
)
subparser.add_argument(
'-y', '--yaml', action='store_const', dest='format', default=None,
const='yaml', help='print concrete spec as yaml')
@ -67,9 +68,6 @@ def setup_parser(subparser):
subparser.add_argument(
'--stats', action='store_true', default=False,
help='print out statistics from clingo')
subparser.add_argument(
'--reuse', action='store_true', default=False,
help='reuse installed dependencies')
subparser.add_argument(
'specs', nargs=argparse.REMAINDER, help="specs of packages")

View file

@ -28,7 +28,8 @@ def setup_parser(subparser):
spack help --spec
"""
arguments.add_common_arguments(
subparser, ['long', 'very_long', 'install_status'])
subparser, ['long', 'very_long', 'install_status', 'reuse']
)
subparser.add_argument(
'-y', '--yaml', action='store_const', dest='format', default=None,
const='yaml', help='print concrete spec as YAML')
@ -64,7 +65,7 @@ def spec(parser, args):
name_fmt = '{namespace}.{name}' if args.namespaces else '{name}'
fmt = '{@version}{%compiler}{compiler_flags}{variants}{arch=architecture}'
install_status_fn = spack.spec.Spec.install_status
kwargs = {
tree_kwargs = {
'cover': args.cover,
'format': name_fmt + fmt,
'hashlen': None if args.very_long else 7,
@ -81,11 +82,15 @@ def spec(parser, args):
if not args.specs:
tty.die("spack spec requires at least one spec")
concretize_kwargs = {
'reuse': args.reuse
}
for spec in spack.cmd.parse_specs(args.specs):
# With -y, just print YAML to output.
if args.format:
if spec.name in spack.repo.path or spec.virtual:
spec.concretize()
spec.concretize(**concretize_kwargs)
# The user can specify the hash type to use
hash_type = getattr(ht, args.hash_type)
@ -98,13 +103,13 @@ def spec(parser, args):
continue
with tree_context():
kwargs['hashes'] = False # Always False for input spec
tree_kwargs['hashes'] = False # Always False for input spec
print("Input spec")
print("--------------------------------")
print(spec.tree(**kwargs))
print(spec.tree(**tree_kwargs))
kwargs['hashes'] = args.long or args.very_long
tree_kwargs['hashes'] = args.long or args.very_long
print("Concretized")
print("--------------------------------")
spec.concretize()
print(spec.tree(**kwargs))
spec.concretize(**concretize_kwargs)
print(spec.tree(**tree_kwargs))

View file

@ -2597,7 +2597,7 @@ def ensure_no_deprecated(root):
msg += " For each package listed, choose another spec\n"
raise SpecDeprecatedError(msg)
def _new_concretize(self, tests=False):
def _new_concretize(self, tests=False, reuse=False):
import spack.solver.asp
if not self.name:
@ -2607,7 +2607,7 @@ def _new_concretize(self, tests=False):
if self._concrete:
return
result = spack.solver.asp.solve([self], tests=tests)
result = spack.solver.asp.solve([self], tests=tests, reuse=reuse)
result.raise_if_unsat()
# take the best answer
@ -2625,17 +2625,23 @@ def _new_concretize(self, tests=False):
self._dup(concretized)
self._mark_concrete()
def concretize(self, tests=False):
def concretize(self, tests=False, reuse=False):
"""Concretize the current spec.
Args:
tests (bool or list): if False disregard 'test' dependencies,
if a list of names activate them for the packages in the list,
if True activate 'test' dependencies for all packages.
reuse (bool): if True try to maximize reuse of already installed
specs, if False don't account for installation status.
"""
if spack.config.get('config:concretizer') == "clingo":
self._new_concretize(tests)
self._new_concretize(tests, reuse=reuse)
else:
if reuse:
msg = ('maximizing reuse of installed specs is not '
'possible with the original concretizer')
raise spack.error.SpecError(msg)
self._old_concretize(tests)
def _mark_root_concrete(self, value=True):

View file

@ -1635,7 +1635,7 @@ _spack_restage() {
_spack_solve() {
if $list_options
then
SPACK_COMPREPLY="-h --help --show --models -l --long -L --very-long -I --install-status -y --yaml -j --json -c --cover -N --namespaces -t --types --timers --stats --reuse"
SPACK_COMPREPLY="-h --help --show --models -l --long -L --very-long -I --install-status --reuse -y --yaml -j --json -c --cover -N --namespaces -t --types --timers --stats"
else
_all_packages
fi
@ -1644,7 +1644,7 @@ _spack_solve() {
_spack_spec() {
if $list_options
then
SPACK_COMPREPLY="-h --help -l --long -L --very-long -I --install-status -y --yaml -j --json -c --cover -N --namespaces --hash-type -t --types"
SPACK_COMPREPLY="-h --help -l --long -L --very-long -I --install-status --reuse -y --yaml -j --json -c --cover -N --namespaces --hash-type -t --types"
else
_all_packages
fi