summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2020-05-12 10:23:42 -0700
committerGitHub <noreply@github.com>2020-05-12 10:23:42 -0700
commit0307111dd8d562de5de055f6a50c4352f0fb28a5 (patch)
tree5320ac9b98857500962dc9f2fba3ba81db9a50cb /lib
parent154c0f57711dc6e7cd81e2e125bcfb437bdf8d62 (diff)
downloadspack-0307111dd8d562de5de055f6a50c4352f0fb28a5.tar.gz
spack-0307111dd8d562de5de055f6a50c4352f0fb28a5.tar.bz2
spack-0307111dd8d562de5de055f6a50c4352f0fb28a5.tar.xz
spack-0307111dd8d562de5de055f6a50c4352f0fb28a5.zip
bugfix: reorder variants in Spec strings (#16462)
* change print order for variants to avoid zsh parsing bugs * change tests for new variant parse order
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/spec_syntax.py4
-rw-r--r--lib/spack/spack/test/variant.py2
-rw-r--r--lib/spack/spack/variant.py29
3 files changed, 17 insertions, 18 deletions
diff --git a/lib/spack/spack/test/spec_syntax.py b/lib/spack/spack/test/spec_syntax.py
index a5f7b6fdb0..688c89022c 100644
--- a/lib/spack/spack/test/spec_syntax.py
+++ b/lib/spack/spack/test/spec_syntax.py
@@ -177,7 +177,7 @@ class TestSpecSyntax(object):
" ^stackwalker@8.1_1e")
self.check_parse(
"mvapich_foo"
- " ^_openmpi@1.2:1.4,1.6%intel@12.1 debug=2 ~qt_4"
+ " ^_openmpi@1.2:1.4,1.6%intel@12.1~qt_4 debug=2"
" ^stackwalker@8.1_1e")
self.check_parse(
'mvapich_foo'
@@ -185,7 +185,7 @@ class TestSpecSyntax(object):
' ^stackwalker@8.1_1e')
self.check_parse(
"mvapich_foo"
- " ^_openmpi@1.2:1.4,1.6%intel@12.1 debug=2 ~qt_4"
+ " ^_openmpi@1.2:1.4,1.6%intel@12.1~qt_4 debug=2"
" ^stackwalker@8.1_1e arch=test-redhat6-x86")
def test_canonicalize(self):
diff --git a/lib/spack/spack/test/variant.py b/lib/spack/spack/test/variant.py
index d1657b71b7..10e8ea7e7f 100644
--- a/lib/spack/spack/test/variant.py
+++ b/lib/spack/spack/test/variant.py
@@ -694,7 +694,7 @@ class TestVariantMapTest(object):
c['foobar'] = SingleValuedVariant('foobar', 'fee')
c['feebar'] = SingleValuedVariant('feebar', 'foo')
c['shared'] = BoolValuedVariant('shared', True)
- assert str(c) == ' feebar=foo foo=bar,baz foobar=fee +shared'
+ assert str(c) == '+shared feebar=foo foo=bar,baz foobar=fee'
def test_disjoint_set_initialization_errors():
diff --git a/lib/spack/spack/variant.py b/lib/spack/spack/variant.py
index 3915fe00fa..0443b68ec3 100644
--- a/lib/spack/spack/variant.py
+++ b/lib/spack/spack/variant.py
@@ -567,25 +567,24 @@ class VariantMap(lang.HashableMap):
# print keys in order
sorted_keys = sorted(self.keys())
+ # Separate boolean variants from key-value pairs as they print
+ # differently. All booleans go first to avoid ' ~foo' strings that
+ # break spec reuse in zsh.
+ bool_keys = []
+ kv_keys = []
+ for key in sorted_keys:
+ bool_keys.append(key) if isinstance(self[key].value, bool) \
+ else kv_keys.append(key)
+
# add spaces before and after key/value variants.
string = StringIO()
- kv = False
- for key in sorted_keys:
- vspec = self[key]
-
- if not isinstance(vspec.value, bool):
- # add space before all kv pairs.
- string.write(' ')
- kv = True
- else:
- # not a kv pair this time
- if kv:
- # if it was LAST time, then pad after.
- string.write(' ')
- kv = False
+ for key in bool_keys:
+ string.write(str(self[key]))
- string.write(str(vspec))
+ for key in kv_keys:
+ string.write(' ')
+ string.write(str(self[key]))
return string.getvalue()