environment spec lists: improve ability to query architecture in when clauses (#17056)

This commit is contained in:
Greg Becker 2020-06-25 12:13:26 -05:00 committed by GitHub
parent e04c89f086
commit f936e3a1db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 5 deletions

View File

@ -647,7 +647,7 @@ named list ``compilers`` is ``['%gcc', '%clang', '%intel']`` on
spack:
definitions:
- compilers: ['%gcc', '%clang']
- when: target == 'x86_64'
- when: arch.satisfies('x86_64:')
compilers: ['%intel']
.. note::
@ -666,8 +666,12 @@ The valid variables for a ``when`` clause are:
#. ``target``. The target string of the default Spack
architecture on the system.
#. ``architecture`` or ``arch``. The full string of the
default Spack architecture on the system.
#. ``architecture`` or ``arch``. A Spack spec satisfying the default Spack
architecture on the system. This supports querying via the ``satisfies``
method, as shown above.
#. ``arch_str``. The architecture string of the default Spack architecture
on the system.
#. ``re``. The standard regex module in Python.

View File

@ -409,12 +409,14 @@ def _eval_conditional(string):
"""Evaluate conditional definitions using restricted variable scope."""
arch = architecture.Arch(
architecture.platform(), 'default_os', 'default_target')
arch_spec = spack.spec.Spec('arch=%s' % arch)
valid_variables = {
'target': str(arch.target),
'os': str(arch.os),
'platform': str(arch.platform),
'arch': str(arch),
'architecture': str(arch),
'arch': arch_spec,
'architecture': arch_spec,
'arch_str': str(arch),
're': re,
'env': os.environ,
'hostname': socket.gethostname()

View File

@ -1429,6 +1429,29 @@ def test_stack_definition_conditional_with_variable(tmpdir):
assert Spec('callpath') in test.user_specs
def test_stack_definition_conditional_with_satisfaction(tmpdir):
filename = str(tmpdir.join('spack.yaml'))
with open(filename, 'w') as f:
f.write("""\
env:
definitions:
- packages: [libelf, mpileaks]
when: arch.satisfies('platform=foo') # will be "test" when testing
- packages: [callpath]
when: arch.satisfies('platform=test')
specs:
- $packages
""")
with tmpdir.as_cwd():
env('create', 'test', './spack.yaml')
test = ev.read('test')
assert Spec('libelf') not in test.user_specs
assert Spec('mpileaks') not in test.user_specs
assert Spec('callpath') in test.user_specs
def test_stack_definition_complex_conditional(tmpdir):
filename = str(tmpdir.join('spack.yaml'))
with open(filename, 'w') as f: