Skip to content

Commit c8e3bc3

Browse files
committed
Add hooks for specific vars/cmds in modulerc interp ctx
Introduce hooks to define specific variables and commands for modulerc interpreter context. It relies on variables defined in siteconfig.tcl configuration file: * modulerc_extra_vars is a list of variable name and value pairs * modulerc_extra_cmds is a list of command name and procedure pairs Fixes #286
1 parent edee673 commit c8e3bc3

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

siteconfig.tcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@
2121
# procedures defined in this file
2222
#set modulefile_extra_cmds {command1 procedure1 command2 procedure2}
2323

24+
# define specific variables in modulerc interpreter context
25+
#set modulerc_extra_vars {varname1 value1 varname2 value2}
26+
27+
# define specific commands in modulerc interpreter context based on procedures
28+
# defined in this file
29+
#set modulerc_extra_cmds {command1 procedure1 command2 procedure2}
30+

tcl/mfinterp.tcl.in

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,39 @@ proc execute-modulerc {modfile modname modspec} {
493493
setModulesVersion readModuleContent readModuleContent\
494494
formatErrStackTrace formatErrStackTrace]
495495

496+
# add site-specific command aliases for modulerc interp
497+
if {[info exists ::modulerc_extra_cmds]} {
498+
if {[catch {array set ::g_modrcAliases $::modulerc_extra_cmds}\
499+
errorMsg]} {
500+
knerror "Invalid value '$::modulerc_extra_cmds' ($errorMsg)\nfor\
501+
siteconfig variable 'modulerc_extra_cmds'"
502+
}
503+
}
504+
496505
# alias commands where an argument should be passed
497506
array set ::g_modrcAliasesPassArg [list]
498507

499508
# trace commands that should be associated to aliases
500509
array set ::g_modrcAliasesTraces [list]
510+
511+
# variable to define in modulerc interp
512+
set ::g_modrcBaseVars [list ModuleTool Modules ModuleToolVersion\
513+
{@MODULES_RELEASE@}]
514+
515+
if {[info exists ::modulerc_extra_vars]} {
516+
if {([llength $::modulerc_extra_vars] % 2) != 0} {
517+
knerror "Invalid value '$::modulerc_extra_vars' (list must have\
518+
an even number of elements)\nfor siteconfig variable\
519+
'modulerc_extra_vars'"
520+
}
521+
foreach {var val} $::modulerc_extra_vars {
522+
if {[string first { } $var] != -1} {
523+
knerror "Invalid variable name '$var'\ndefined in siteconfig\
524+
variable 'modulerc_extra_vars'"
525+
}
526+
}
527+
lappend ::g_modrcBaseVars {*}$::modulerc_extra_vars
528+
}
501529
}
502530

503531
# dedicate an interpreter per level of interpretation to have in case of
@@ -510,9 +538,10 @@ proc execute-modulerc {modfile modname modspec} {
510538
reportDebug "creating interp $itrp"
511539
interp create $itrp
512540

513-
# record module tool properties
514-
interp eval $itrp set ::ModuleTool Modules
515-
interp eval $itrp set ::ModuleToolVersion {@MODULES_RELEASE@}
541+
# initialize global static variables for modulerc interp
542+
foreach {var val} $::g_modrcBaseVars {
543+
interp eval $itrp set ::$var "{$val}"
544+
}
516545

517546
# dump initial interpreter state to restore it before each modulerc
518547
# interpretation. use same dump state for all levels

0 commit comments

Comments
 (0)