@@ -373,6 +373,12 @@ def custom_sort_key(entry):
373373 raise Exception (f"Expected no or one MPI provider, but got { mpi_providers } " )
374374 logging .info (f" ... mpi_providers: { mpi_providers } " )
375375
376+ # To catch errors (invalid compilers, etc) we check that the number of written
377+ # stack-* meta modules matches what we expect: One module for the preferred
378+ # compiler, and (if applicable) one for each (currently one) MPI provider.
379+ number_of_meta_modules_expected = 1 + len (mpi_providers )
380+ number_of_meta_modules_written = 0
381+
376382 # Prepare meta module directory
377383 logging .info ("Preparing meta module directory ..." )
378384 meta_module_dir = os .path .join (module_dir , "Core" )
@@ -508,6 +514,7 @@ def custom_sort_key(entry):
508514 with open (compiler_module_file , "w" ) as f :
509515 f .write (module_content )
510516 logging .info (" ... writing {}" .format (compiler_module_file ))
517+ number_of_meta_modules_written += 1
511518
512519 # If this is the last compiler in the list (i.e. the preferred compiler),
513520 # then save the substitutes for later when building the MPI meta module
@@ -520,13 +527,15 @@ def custom_sort_key(entry):
520527 # Create mpi modules - currently, only one mpi provider is allowed
521528 for mpi_provider in mpi_providers :
522529
530+ if module_choice == "lmod" :
531+ mpi_alias = mpi_provider .name
532+ else :
533+ mpi_alias = ALIASES [mpi_provider .name ]
534+
523535 # For tcl, append modulepath for external specs and for specs without
524536 # compiler dependencies; remove the compiler/mpi prefices from the moduless
525537 if module_choice == "tcl" :
526538
527- # Module paths are short names for tcl modules
528- mpi_alias = ALIASES [mpi_provider .name ]
529-
530539 modulepath_save = os .path .join (module_dir , mpi_alias , str (mpi_provider .version ), "none" , "none" )
531540 if not os .path .isdir (modulepath_save ):
532541 os .makedirs (modulepath_save )
@@ -548,7 +557,7 @@ def custom_sort_key(entry):
548557
549558 # Module paths are short names for tcl modules
550559 if module_choice == "lmod" :
551- mpi_alias = compiler .name
560+ compiler_alias = compiler .name
552561 else :
553562 compiler_alias = ALIASES [compiler .name ]
554563
@@ -654,10 +663,10 @@ def custom_sort_key(entry):
654663 substitutes ["FC" ] = COMPILER_SUBSTITUTES_SAVE ["FC" ]
655664
656665 # Environment variables
657- if "environment" in compiler .extra_attributes .keys ():
658- for action in compiler .extra_attributes ["environment" ].keys ():
659- for env_name in compiler .extra_attributes ["environment" ][action ]:
660- env_values = compiler .extra_attributes ["environment" ][action ][env_name ]
666+ if "environment" in mpi_provider .extra_attributes .keys ():
667+ for action in mpi_provider .extra_attributes ["environment" ].keys ():
668+ for env_name in mpi_provider .extra_attributes ["environment" ][action ]:
669+ env_values = mpi_provider .extra_attributes ["environment" ][action ][env_name ]
661670 substitutes ["ENVVARS" ] += envmod_command (
662671 module_choice ,
663672 action ,
@@ -689,5 +698,10 @@ def custom_sort_key(entry):
689698 with open (mpi_module_file , "w" ) as f :
690699 f .write (module_content )
691700 logging .info (" ... writing {}" .format (mpi_module_file ))
701+ number_of_meta_modules_written += 1
692702
693- logging .info ("Metamodule generation completed successfully in {}" .format (meta_module_dir ))
703+
704+ if number_of_meta_modules_written == number_of_meta_modules_expected :
705+ logging .info ("Metamodule generation completed successfully in {}" .format (meta_module_dir ))
706+ else :
707+ raise Exception ("Metamodule generation NOT successful, check output (invalid compiler?)" )
0 commit comments