From 3b4d6ddc03e2bf93cbc70f54e795d085ef44ee60 Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Tue, 6 Aug 2019 12:53:41 -0700 Subject: stacks: fix reference handling in env.write() (#12096) * stacks: Fix env.write to properly write references * stacks: regression test for 12095 --- lib/spack/spack/environment.py | 6 ++++-- lib/spack/spack/test/cmd/env.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index a854800601..0e59cba746 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -1235,9 +1235,11 @@ class Environment(object): # Remove any specs in yaml that are not in internal representation for ayl in active_yaml_lists: # If it's not a string, it's a matrix. Those can't have changed + # If it is a string that starts with '$', it's a reference. + # Those also can't have changed. ayl[name][:] = [s for s in ayl.setdefault(name, []) - if not isinstance(s, six.string_types) or - Spec(s) in speclist.specs] + if (not isinstance(s, six.string_types)) or + s.startswith('$') or Spec(s) in speclist.specs] # Put the new specs into the first active list from the yaml new_specs = [entry for entry in speclist.yaml_list diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 80b00bab1d..c7f1c75579 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -965,6 +965,29 @@ env: assert Spec('callpath') in test.user_specs +@pytest.mark.regression('12095') +def test_stack_yaml_definitions_write_reference(tmpdir): + filename = str(tmpdir.join('spack.yaml')) + with open(filename, 'w') as f: + f.write("""\ +env: + definitions: + - packages: [mpileaks, callpath] + - indirect: [$packages] + specs: + - $packages +""") + with tmpdir.as_cwd(): + env('create', 'test', './spack.yaml') + + with ev.read('test'): + concretize() + test = ev.read('test') + + assert Spec('mpileaks') in test.user_specs + assert Spec('callpath') in test.user_specs + + def test_stack_yaml_add_to_list(tmpdir): filename = str(tmpdir.join('spack.yaml')) with open(filename, 'w') as f: -- cgit v1.2.3-60-g2f50