diff options
author | Greg Becker <becker33@llnl.gov> | 2020-06-25 12:13:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-25 19:13:26 +0200 |
commit | f936e3a1dbc43629e01a3a7e2cc1682419cb381b (patch) | |
tree | 5fca95fc68507c3fb5f6639bdafe4a5a81058e11 | |
parent | e04c89f0867ba275bf7926a42f175f09ac6cd9dc (diff) | |
download | spack-f936e3a1dbc43629e01a3a7e2cc1682419cb381b.tar.gz spack-f936e3a1dbc43629e01a3a7e2cc1682419cb381b.tar.bz2 spack-f936e3a1dbc43629e01a3a7e2cc1682419cb381b.tar.xz spack-f936e3a1dbc43629e01a3a7e2cc1682419cb381b.zip |
environment spec lists: improve ability to query architecture in when clauses (#17056)
-rw-r--r-- | lib/spack/docs/environments.rst | 10 | ||||
-rw-r--r-- | lib/spack/spack/environment.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/env.py | 23 |
3 files changed, 34 insertions, 5 deletions
diff --git a/lib/spack/docs/environments.rst b/lib/spack/docs/environments.rst index b80e36b4b2..cec7224a86 100644 --- a/lib/spack/docs/environments.rst +++ b/lib/spack/docs/environments.rst @@ -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. diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index bc9730e490..8eab70b544 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -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() diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 5703738731..46977d8eec 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -1429,6 +1429,29 @@ env: 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: |