Skip to content

Commit edee673

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

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

siteconfig.tcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
# superseding
1515
#lappendConf locked_configs implicit_default
1616

17+
# define specific variables in modulefile interpreter context
18+
#set modulefile_extra_vars {varname1 value1 varname2 value2}
19+
20+
# define specific commands in modulefile interpreter context based on
21+
# procedures defined in this file
22+
#set modulefile_extra_cmds {command1 procedure1 command2 procedure2}
23+

tcl/mfinterp.tcl.in

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ x-resource {x-resource x-resource reportCmd nop nop
152152
# initialize list with all commands not dependent of the evaluation mode
153153
array set aliases $::g_modfileBaseAliases
154154

155+
# add site-specific command aliases for modulefile interp
156+
if {[info exists ::modulefile_extra_cmds]} {
157+
if {[catch {array set aliases $::modulefile_extra_cmds} errorMsg]} {
158+
knerror "Invalid value '$::modulefile_extra_cmds' ($errorMsg)\nfor\
159+
siteconfig variable 'modulefile_extra_cmds'"
160+
}
161+
}
162+
155163
# add alias commands whose target command vary depending on the eval mode
156164
set modeidx [lsearch -exact $::g_modfileEvalModes $mode]
157165
foreach alias [array names g_modfilePerModeAliases] {
@@ -264,14 +272,37 @@ proc execute-modulefile {modfile modname modnamevrvar modspec {up_namevr 1}\
264272
$aliasesPassArgVN $tracesVN
265273
}
266274

275+
# variable to define in modulefile interp
276+
if {![info exists ::g_modfileBaseVars]} {
277+
# record module tool properties
278+
set ::g_modfileBaseVars [list ModuleTool Modules ModuleToolVersion\
279+
{@MODULES_RELEASE@}]
280+
281+
if {[info exists ::modulefile_extra_vars]} {
282+
if {([llength $::modulefile_extra_vars] % 2) != 0} {
283+
knerror "Invalid value '$::modulefile_extra_vars' (list must have\
284+
an even number of elements)\nfor siteconfig variable\
285+
'modulefile_extra_vars'"
286+
}
287+
foreach {var val} $::modulefile_extra_vars {
288+
if {[string first { } $var] != -1} {
289+
knerror "Invalid variable name '$var'\ndefined in siteconfig\
290+
variable 'modulefile_extra_vars'"
291+
}
292+
}
293+
lappend ::g_modfileBaseVars {*}$::modulefile_extra_vars
294+
}
295+
}
296+
267297
# create modulefile interpreter at first interpretation
268298
if {![interp exists $itrp]} {
269299
reportDebug "creating interp $itrp"
270300
interp create $itrp
271301

272-
# record module tool properties
273-
interp eval $itrp set ::ModuleTool Modules
274-
interp eval $itrp set ::ModuleToolVersion {@MODULES_RELEASE@}
302+
# initialize global static variables for modulefile interp
303+
foreach {var val} $::g_modfileBaseVars {
304+
interp eval $itrp set ::$var "{$val}"
305+
}
275306

276307
# dump initial interpreter state to restore it before each modulefile
277308
# interpretation. use same dump state for all modes/levels

0 commit comments

Comments
 (0)