From f3a1a8c6fe13b6f92a6c44e771aff5d1f9683a77 Mon Sep 17 00:00:00 2001
From: "Seth R. Johnson" <johnsonsr@ornl.gov>
Date: Wed, 26 Feb 2020 12:03:28 -0500
Subject: [PATCH] Uniquify suffixes added to module names (#14920)

---
 lib/spack/spack/modules/common.py                 | 1 +
 lib/spack/spack/test/data/modules/tcl/suffix.yaml | 1 +
 lib/spack/spack/test/modules/tcl.py               | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py
index c09a225116..8dee443eb3 100644
--- a/lib/spack/spack/modules/common.py
+++ b/lib/spack/spack/modules/common.py
@@ -428,6 +428,7 @@ def suffixes(self):
         for constraint, suffix in self.conf.get('suffixes', {}).items():
             if constraint in self.spec:
                 suffixes.append(suffix)
+        suffixes = sorted(set(suffixes))
         if self.hash:
             suffixes.append(self.hash)
         return suffixes
diff --git a/lib/spack/spack/test/data/modules/tcl/suffix.yaml b/lib/spack/spack/test/data/modules/tcl/suffix.yaml
index 015ac63b0f..57703e1733 100644
--- a/lib/spack/spack/test/data/modules/tcl/suffix.yaml
+++ b/lib/spack/spack/test/data/modules/tcl/suffix.yaml
@@ -5,3 +5,4 @@ tcl:
     suffixes:
       '+debug': foo
       '~debug': bar
+      '^mpich': foo
diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py
index 70eee24461..40cb7be5ef 100644
--- a/lib/spack/spack/test/modules/tcl.py
+++ b/lib/spack/spack/test/modules/tcl.py
@@ -215,9 +215,10 @@ def test_suffixes(self, module_configuration, factory):
 
         writer, spec = factory('mpileaks+debug arch=x86-linux')
         assert 'foo' in writer.layout.use_name
+        assert 'foo-foo' not in writer.layout.use_name
 
         writer, spec = factory('mpileaks~debug arch=x86-linux')
-        assert 'bar' in writer.layout.use_name
+        assert 'bar-foo' in writer.layout.use_name
 
     def test_setup_environment(self, modulefile_content, module_configuration):
         """Tests the internal set-up of run-time environment."""
-- 
GitLab