concretizer: allow a bool to be passed as argument for tests dependencies (#20082)

refers #20079

Added docstrings to 'concretize' and 'concretized' to
document the format for tests.

Added tests for the activation of test dependencies.
This commit is contained in:
Massimiliano Culpo 2020-11-26 08:55:17 +01:00 committed by Tamara Dahlgren
parent 8e1b5f734f
commit 0ae49821e2
6 changed files with 69 additions and 8 deletions

View File

@ -916,8 +916,13 @@ def package_dependencies_rules(self, pkg, tests):
named_cond.name = named_cond.name or pkg.name
for t in sorted(dep.type):
# Skip test dependencies if they're not requested
if t == 'test' and (not tests or pkg.name not in tests):
# Skip test dependencies if they're not requested at all
if t == 'test' and not tests:
continue
# ... or if they are requested only for certain packages
if t == 'test' and (not isinstance(tests, bool)
and pkg.name not in tests):
continue
if cond == spack.spec.Spec():

View File

@ -2463,8 +2463,14 @@ def _new_concretize(self, tests=False):
self._dup(concretized)
self._mark_concrete()
#: choose your concretizer here.
def concretize(self, tests=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.
"""
if spack.config.get('config:concretizer') == "clingo":
self._new_concretize(tests)
else:
@ -2482,12 +2488,19 @@ def _mark_concrete(self, value=True):
s._normal = value
s._concrete = value
def concretized(self):
"""This is a non-destructive version of concretize(). First clones,
then returns a concrete version of this package without modifying
this package. """
def concretized(self, tests=False):
"""This is a non-destructive version of concretize().
First clones, then returns a concrete version of this package
without modifying this package.
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.
"""
clone = self.copy(caches=False)
clone.concretize()
clone.concretize(tests=tests)
return clone
def flat_dependencies(self, **kwargs):

View File

@ -895,3 +895,31 @@ def test_conditional_provides_or_depends_on(self):
assert 'v1-provider' in s
assert s['v1'].name == 'v1-provider'
assert s['v2'].name == 'conditional-provider'
@pytest.mark.regression('20079')
@pytest.mark.parametrize('spec_str,tests_arg,with_dep,without_dep', [
# Check that True is treated correctly and attaches test deps
# to all nodes in the DAG
('a', True, ['a'], []),
('a foobar=bar', True, ['a', 'b'], []),
# Check that a list of names activates the dependency only for
# packages in that list
('a foobar=bar', ['a'], ['a'], ['b']),
('a foobar=bar', ['b'], ['b'], ['a']),
# Check that False disregard test dependencies
('a foobar=bar', False, [], ['a', 'b']),
])
def test_activating_test_dependencies(
self, spec_str, tests_arg, with_dep, without_dep
):
s = Spec(spec_str).concretized(tests=tests_arg)
for pkg_name in with_dep:
msg = "Cannot find test dependency in package '{0}'"
node = s[pkg_name]
assert node.dependencies(deptype='test'), msg.format(pkg_name)
for pkg_name in without_dep:
msg = "Test dependency in package '{0}' is unexpected"
node = s[pkg_name]
assert not node.dependencies(deptype='test'), msg.format(pkg_name)

View File

@ -31,6 +31,7 @@ class A(AutotoolsPackage):
variant('bvv', default=True, description='The good old BV variant')
depends_on('b', when='foobar=bar')
depends_on('test-dependency', type='test')
parallel = False

View File

@ -13,3 +13,5 @@ class B(Package):
url = "http://www.example.com/b-1.0.tar.gz"
version('1.0', '0123456789abcdef0123456789abcdef')
depends_on('test-dependency', type='test')

View File

@ -0,0 +1,12 @@
# Copyright 2013-2020 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)
class TestDependency(Package):
"""Represent a dependency that is pulled-in to allow testing other
packages.
"""
homepage = "http://www.example.com"
url = "http://www.example.com/tdep-1.0.tar.gz"
version('1.0', '0123456789abcdef0123456789abcdef')