diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/module.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index c71e615d1c..4f6b4764b6 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -25,6 +25,7 @@ import os import shutil import sys +import collections import llnl.util.tty as tty import spack.cmd @@ -100,12 +101,32 @@ def module_refresh(name, specs, args): ask_for_confirmation('Do you want to proceed ? ') cls = module_types[name] + + # Detect name clashes + writers = [cls(spec) for spec in specs] + file2writer = collections.defaultdict(list) + for item in writers: + file2writer[item.file_name].append(item) + + if len(file2writer) != len(writers): + message = 'Name clashes detected in module files:\n' + for filename, writer_list in file2writer.items(): + if len(writer_list) > 1: + message += 'file : {0}\n'.format(filename) + for x in writer_list: + message += 'spec : {0}\n'.format(x.spec.format(color=True)) + message += '\n' + tty.error(message) + tty.error('Operation aborted') + raise SystemExit(1) + + # Proceed regenerating module files tty.msg('Regenerating {name} module files'.format(name=name)) if os.path.isdir(cls.path) and args.delete_tree: shutil.rmtree(cls.path, ignore_errors=False) mkdirp(cls.path) - for spec in specs: - cls(spec).write() + for x in writers: + x.write(overwrite=True) # Qualifiers to be used when querying the db for specs constraint_qualifiers = { |