diff --git a/init/modulerc.in b/init/modulerc.in index 227016f1..81c725d5 100644 --- a/init/modulerc.in +++ b/init/modulerc.in @@ -1,3 +1,4 @@ +#%Module1.0 # This file defines the initial setup for the modulefiles search path # and modulefiles you want to load by default for all users. It should # contains a lines of module command like 'module use path' and diff --git a/modulecmd.tcl b/modulecmd.tcl index 20770dfb..0ac5522a 100755 --- a/modulecmd.tcl +++ b/modulecmd.tcl @@ -33,7 +33,7 @@ echo "FATAL: module: Could not find tclsh in \$PATH or in standard directories" # # Some Global Variables..... # -set MODULES_CURRENT_VERSION 1.804 +set MODULES_CURRENT_VERSION 1.807 set MODULES_CURRENT_RELEASE_DATE "2017-04-17" set g_debug 0 ;# Set to 1 to enable debugging set error_count 0 ;# Start with 0 errors @@ -229,7 +229,7 @@ proc unset-env {var} { } } -proc execute-modulefile {modfile {exit_on_error 1}} { +proc execute-modulefile {modfile {exit_on_error 1} {must_have_cookie 1}} { global g_debug g_inhibit_interp g_inhibit_errreport g_inhibit_dispreport global ModulesCurrentModulefile @@ -287,12 +287,14 @@ proc execute-modulefile {modfile {exit_on_error 1}} { $g_inhibit_errreport] interp eval $slave [list "set" "g_inhibit_dispreport"\ $g_inhibit_dispreport] + interp eval $slave [list "set" "must_have_cookie" $must_have_cookie] } set errorVal [interp eval $slave { if {$g_debug} { report "Sourcing $ModulesCurrentModulefile" } - set modcontent [readModuleContent $ModulesCurrentModulefile 1] + set modcontent [readModuleContent $ModulesCurrentModulefile 1\ + $must_have_cookie] if {$modcontent eq ""} { # exit after end of slave evaluation return 2 @@ -2757,7 +2759,7 @@ proc checkValidModule {modfile} { return 0 } -proc readModuleContent {modfile {report_read_issue 0}} { +proc readModuleContent {modfile {report_read_issue 0} {must_have_cookie 1}} { reportDebug "readModuleContent: $modfile" # read file @@ -2772,8 +2774,8 @@ proc readModuleContent {modfile {report_read_issue 0}} { return {} } - # check module validity - if {[string first "\#%Module" $fdata] == 0} { + # check module validity if magic cookie is mandatory + if {[string first "\#%Module" $fdata] == 0 || !$must_have_cookie} { return $fdata } else { reportInternalBug "Magic cookie '#%Module' missing in '$modfile'" @@ -4008,7 +4010,11 @@ proc cmdModuleSource {args} { pushMode "load" pushSpecifiedName $file pushModuleName $file - execute-modulefile $file + # relax constraint of having a magic cookie at the start of the + # modulefile to execute as sourced files may need more flexibility + # as they may be managed outside of the modulefile environment like + # the initialization modulerc file + execute-modulefile $file 1 0 popModuleName popSpecifiedName popMode diff --git a/testsuite/home/rcnomagic b/testsuite/home/rcnomagic new file mode 100644 index 00000000..f44d7559 --- /dev/null +++ b/testsuite/home/rcnomagic @@ -0,0 +1,22 @@ +#%Missing magic cookie + +############################################################################## +# Modules Revision 3.0 +# Providing a flexible user environment +# +# File: home/%M% +# Revision: %I% +# First Edition: 2017/04/17 +# Last Mod.: %U%, %G% +# +# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr +# +# Description: RC file to source +# +# Comment: %C{ +# RC file to test behavior of module command 'source' +# }C% +# +############################################################################## + +setenv testsuite "yes" diff --git a/testsuite/home/rctosource b/testsuite/home/rctosource new file mode 100644 index 00000000..7b9edeca --- /dev/null +++ b/testsuite/home/rctosource @@ -0,0 +1,22 @@ +#%Module1.0 + +############################################################################## +# Modules Revision 3.0 +# Providing a flexible user environment +# +# File: home/%M% +# Revision: %I% +# First Edition: 2017/04/17 +# Last Mod.: %U%, %G% +# +# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr +# +# Description: RC file to source +# +# Comment: %C{ +# RC file to test behavior of module command 'source' +# }C% +# +############################################################################## + +setenv testsuite "yes" diff --git a/testsuite/modules.70-maint/090-source.exp b/testsuite/modules.70-maint/090-source.exp new file mode 100644 index 00000000..2e3866c5 --- /dev/null +++ b/testsuite/modules.70-maint/090-source.exp @@ -0,0 +1,60 @@ +############################################################################## +# Modules Revision 3.0 +# Providing a flexible user environment +# +# File: modules.70-maint/%M% +# Revision: %I% +# First Edition: 2017/04/17 +# Last Mod.: %U%, %G% +# +# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr +# +# Description: Testuite testsequence +# Command: source +# Modulefiles: rctosource, rcnomagic, nonexistent +# Sub-Command: +# +# Comment: %C{ +# Tests the module command 'source' +# }C% +# +############################################################################## + +# +# Test variables +# + +set module_1 "$env(TESTSUITEDIR)/home/rctosource" +set module_2 "$env(TESTSUITEDIR)/home/rcnomagic" +set module_3 "$env(TESTSUITEDIR)/home/nonexistent" + +set out_csh "setenv testsuite yes;" +set out_csh3 "/bin/false;" +set err_csh "$error_msgs: File $module_3 does not exist" + +# +# test sourcing rc file with regular module-specific magic cookie +# +testouterr_cmd "csh" "source $module_1" "$out_csh" "" + +# +# test sourcing rc file with no module-specific magic cookie +# +testouterr_cmd "csh" "source $module_2" "$out_csh" "" + +# +# test with nonexistent file +# +testouterr_cmd "csh" "source $module_3" "$out_csh3" "$err_csh" + +# +# Cleanup +# + +unset err_csh +unset out_csh3 +unset out_csh + +unset module_1 +unset module_2 +unset module_3