diff --git a/tcl/cache.tcl.in b/tcl/cache.tcl.in index 32c5e058b..b9b9bd956 100644 --- a/tcl/cache.tcl.in +++ b/tcl/cache.tcl.in @@ -272,26 +272,10 @@ proc execute-cachefile {cachefile modpath} { set itrp __cachefile reportTrace '$cachefile' {Evaluate cache file} - # create cachefile interpreter at first interpretation - if {![interp exists $itrp]} { - createInterp $itrp - - # dump initial interpreter state to restore it before each cachefile - # interpretation. - dumpInterpState $itrp g_cachefileVars g_cachefileArrayVars\ - g_cachefileUntrackVars g_cachefileProcs - - # interp has just been created - set fresh 1 - } else { - set fresh 0 - } - - # reset interp state command before each interpretation - resetInterpState $itrp $fresh g_cachefileVars g_cachefileArrayVars\ - g_cachefileUntrackVars g_cachefileProcs g_cachefileAliases\ - g_cachefileAliasesPassArg g_cachefileAliasesTraces\ - g_cachefileRenameCmds g_cachefileCommands + # create cachefile interpreter at first interpretation and reset its state + # before each interpretation + setupInterp $itrp g_cachefile g_cachefileAliases\ + g_cachefileAliasesPassArg g_cachefileAliasesTraces g_cachefileCommands # reset modulefile-specific variable before each interpretation interp eval $itrp set ::ModulesCurrentCachefile "{$cachefile}" diff --git a/tcl/coll.tcl.in b/tcl/coll.tcl.in index d79455d59..992e9c3b8 100644 --- a/tcl/coll.tcl.in +++ b/tcl/coll.tcl.in @@ -256,6 +256,12 @@ proc formatCollectionContent {path_list mod_list tag_arrser header {sgr 0}} { # read given collection file and return the path and module lists it defines proc readCollectionContent {collfile colldesc} { + # read specific __init__ collection from __MODULES_LMINIT env var + if {$collfile eq {__init__}} { + return [parseCollectionContent [getEnvLoadedModulePropertyParsedList\ + init]] + } + # read file if {[catch { set fdata [split [readFile $collfile] \n] @@ -263,7 +269,13 @@ proc readCollectionContent {collfile colldesc} { reportErrorAndExit "Collection $colldesc cannot be read.\n$errMsg" } - return [parseCollectionContent $fdata] + # collection should at least define a path or a mod, but initial env may be + # totally empty + set content [parseCollectionContent $fdata] + if {![llength [lindex $content 0]] && ![llength [lindex $content 1]]} { + reportErrorAndExit "$colldesc is not a valid collection" + } + return $content } proc parseCollectionContent {fdata} { @@ -335,14 +347,8 @@ proc parseCollectionContent {fdata} { # return specified collection content and differences compared to currently # defined environment proc getDiffBetweenCurEnvAndColl {collfile colldesc} { - # read specific __init__ collection from __MODULES_LMINIT env var - if {$collfile eq {__init__}} { - lassign [parseCollectionContent [getEnvLoadedModulePropertyParsedList\ - init]] coll_path_list coll_mod_list coll_tag_arrser - } else { - lassign [readCollectionContent $collfile $colldesc] coll_path_list\ - coll_mod_list coll_tag_arrser - } + lassign [readCollectionContent $collfile $colldesc] coll_path_list\ + coll_mod_list coll_tag_arrser # build list of module tagged auto-loaded in collection array set coll_tag_arr $coll_tag_arrser @@ -353,13 +359,6 @@ proc getDiffBetweenCurEnvAndColl {collfile colldesc} { } } - # collection should at least define a path or a mod, but initial env may be - # totally empty - if {$collfile ne {__init__} && ![llength $coll_path_list] && ![llength\ - $coll_mod_list]} { - reportErrorAndExit "$colldesc is not a valid collection" - } - # fetch what is currently loaded set curr_path_list [getModulePathList returnempty 0] # get current loaded module list diff --git a/tcl/envmngt.tcl.in b/tcl/envmngt.tcl.in index 3c6770e56..e78974ef6 100644 --- a/tcl/envmngt.tcl.in +++ b/tcl/envmngt.tcl.in @@ -43,90 +43,60 @@ proc renderFalse {} { # setup flag to render only once setState false_rendered 1 - - # render a false value most of the time through a variable assignment - # that will be looked at in the shell module function calling - # modulecmd.tcl to return in turns a boolean status. Except for python - # and cmake, the value assigned to variable is also returned as the - # entire rendering status - switch -- [getState shelltype] { - sh - csh - fish { - # no need to set a variable on real shells as last statement - # result can easily be checked - lappend ::g_shcode_out {test 0 = 1;} - } - tcl { - lappend ::g_shcode_out {set _mlstatus 0;} - } - cmd { - lappend ::g_shcode_out {set errorlevel=1} - } - perl { - lappend ::g_shcode_out {{ no strict 'vars'; $_mlstatus = 0; }} - } - python { - lappend ::g_shcode_out {_mlstatus = False} - } - ruby { - lappend ::g_shcode_out {_mlstatus = false} - } - lisp { - lappend ::g_shcode_out {nil} - } - cmake { - lappend ::g_shcode_out {set(_mlstatus FALSE)} - } - r { - lappend ::g_shcode_out {mlstatus <- FALSE} - } - pwsh { - lappend ::g_shcode_out {Set-Variable -Name "_mlstatus" -Value $false\ - -Scope Global} - } - } + renderBool 0 } proc renderTrue {} { - # render a true value most of the time through a variable assignment that - # will be looked at in the shell module function calling modulecmd.tcl to - # return in turns a boolean status. Except for python, cmake, and pwsh, - # the value assigned to variable is also returned as the full rendering - # status + renderBool 1 +} + +# render a boolean value most of the time through a variable assignment that +# will be looked at in the shell module function calling modulecmd.tcl to +# return in turns a boolean status. Except for python, cmake and pwsh, the +# value assigned to variable is also returned as the entire rendering status +proc renderBool {bool} { + # code rendering false value then code rendering true value switch -- [getState shelltype] { sh - csh - fish { # no need to set a variable on real shells as last statement # result can easily be checked - lappend ::g_shcode_out {test 0;} + set code_list [list {test 0 = 1;} {test 0;}] } tcl { - lappend ::g_shcode_out {set _mlstatus 1;} + set code_list [list {set _mlstatus 0;} {set _mlstatus 1;}] } cmd { - lappend ::g_shcode_out {set errorlevel=0} + set code_list [list {set errorlevel=1} {set errorlevel=0}] } perl { - lappend ::g_shcode_out {{ no strict 'vars'; $_mlstatus = 1; }} + set code_list [list {{ no strict 'vars'; $_mlstatus = 0; }} {{ no\ + strict 'vars'; $_mlstatus = 1; }}] } python { - lappend ::g_shcode_out {_mlstatus = True} + set code_list [list {_mlstatus = False} {_mlstatus = True}] } ruby { - lappend ::g_shcode_out {_mlstatus = true} + set code_list [list {_mlstatus = false} {_mlstatus = true}] } lisp { - lappend ::g_shcode_out {t} + set code_list [list {nil} {t}] } cmake { - lappend ::g_shcode_out {set(_mlstatus TRUE)} + set code_list [list {set(_mlstatus FALSE)} {set(_mlstatus TRUE)}] } r { - lappend ::g_shcode_out {mlstatus <- TRUE} + set code_list [list {mlstatus <- FALSE} {mlstatus <- TRUE}] } pwsh { - lappend ::g_shcode_out {Set-Variable -Name "_mlstatus" -Value\ - $true -Scope Global} + set code_list [list {Set-Variable -Name "_mlstatus" -Value $false\ + -Scope Global} {Set-Variable -Name "_mlstatus" -Value $true\ + -Scope Global}] + } + default { + return } } + lappend ::g_shcode_out [lindex $code_list $bool] } proc renderText {text} { @@ -174,6 +144,58 @@ proc renderText {text} { } } +# Render code merging a string into X resource database. This string is made +# of resource name var, a colon and val, which is either resource value +# preceded by a space or an empty string to unset resource. +proc renderXResourceMerge {xrdb var val} { + set res $var:$val + switch -- [getState shelltype] { + sh - csh - fish { + # resource string is rendered unescaped when resource is unset + if {$val ne {}} { + set res [charEscaped $res \"] + } + lappend ::g_shcode_out "echo \"$res\" | $xrdb -merge;" + } + tcl { + set res [charEscaped $res \"] + lappend ::g_shcode_out "set XRDBPIPE \[open \"|$xrdb -merge\" r+\];" + lappend ::g_shcode_out "puts \$XRDBPIPE \"$res\";" + lappend ::g_shcode_out {close $XRDBPIPE;} + lappend ::g_shcode_out {unset XRDBPIPE;} + } + perl { + set res [charEscaped $res \"] + lappend ::g_shcode_out "open(XRDBPIPE, \"|$xrdb -merge\");" + lappend ::g_shcode_out "print XRDBPIPE \"$res\\n\";" + lappend ::g_shcode_out {close XRDBPIPE;} + } + python { + set res [charEscaped $res '] + lappend ::g_shcode_out "subprocess.Popen(\['$xrdb', '-merge'\],\ + stdin=subprocess.PIPE).communicate(input='$res\\n')" + } + ruby { + set res [charEscaped $res '] + lappend ::g_shcode_out "Open3.popen2('$xrdb -merge') {|i,o,t|\ + i.puts '$res'}" + } + lisp { + lappend ::g_shcode_out "(shell-command-to-string \"echo $res |\ + $xrdb -merge\")" + } + cmake { + set res [charEscaped $res \"] + lappend ::g_shcode_out "execute_process(COMMAND echo \"$res\"\ + COMMAND $xrdb -merge)" + } + r { + set res [charEscaped $res {\\'}] + lappend ::g_shcode_out "system('$xrdb -merge', input='$res')" + } + } +} + proc renderSettings {} { global g_stateEnvVars g_stateAliases g_stateFunctions g_stateCompletes\ g_newXResources g_delXResources g_shcode_out @@ -542,59 +564,7 @@ proc renderSettings {} { } } } else { - switch -- [getState shelltype] { - sh - csh - fish { - set var [charEscaped $var \"] - set val [charEscaped $val \"] - lappend g_shcode_out "echo \"$var: $val\" | $xrdb -merge;" - } - tcl { - lappend g_shcode_out "set XRDBPIPE \[open \"|$xrdb -merge\"\ - r+\];" - set var [charEscaped $var \"] - set val [charEscaped $val \"] - lappend g_shcode_out "puts \$XRDBPIPE \"$var: $val\";" - lappend g_shcode_out {close $XRDBPIPE;} - lappend g_shcode_out {unset XRDBPIPE;} - } - perl { - lappend g_shcode_out "open(XRDBPIPE, \"|$xrdb -merge\");" - set var [charEscaped $var \"] - set val [charEscaped $val \"] - lappend g_shcode_out "print XRDBPIPE \"$var: $val\\n\";" - lappend g_shcode_out {close XRDBPIPE;} - } - python { - set var [charEscaped $var '] - set val [charEscaped $val '] - lappend g_shcode_out "subprocess.Popen(\['$xrdb',\ - '-merge'\],\ - stdin=subprocess.PIPE).communicate(input='$var:\ - $val\\n')" - } - ruby { - set var [charEscaped $var '] - set val [charEscaped $val '] - lappend g_shcode_out "Open3.popen2('$xrdb -merge') {|i,o,t|\ - i.puts '$var: $val'}" - } - lisp { - lappend g_shcode_out "(shell-command-to-string \"echo $var:\ - $val | $xrdb -merge\")" - } - cmake { - set var [charEscaped $var \"] - set val [charEscaped $val \"] - lappend g_shcode_out "execute_process(COMMAND echo \"$var:\ - $val\" COMMAND $xrdb -merge)" - } - r { - set var [charEscaped $var {\\'}] - set val [charEscaped $val {\\'}] - lappend g_shcode_out "system('$xrdb -merge', input='$var:\ - $val')" - } - } + renderXResourceMerge $xrdb $var " $val" } } } @@ -618,63 +588,8 @@ proc renderSettings {} { # xresource strings are unset by emptying their value since there # is no command of xrdb that can properly remove one property - switch -- [getState shelltype] { - sh - csh - fish { - foreach var $xres_to_del { - lappend g_shcode_out "echo \"$var:\" | $xrdb -merge;" - } - } - tcl { - foreach var $xres_to_del { - lappend g_shcode_out "set XRDBPIPE \[open \"|$xrdb -merge\"\ - r+\];" - set var [charEscaped $var \"] - lappend g_shcode_out "puts \$XRDBPIPE \"$var:\";" - lappend g_shcode_out {close $XRDBPIPE;} - lappend g_shcode_out {unset XRDBPIPE;} - } - } - perl { - foreach var $xres_to_del { - lappend g_shcode_out "open(XRDBPIPE, \"|$xrdb -merge\");" - set var [charEscaped $var \"] - lappend g_shcode_out "print XRDBPIPE \"$var:\\n\";" - lappend g_shcode_out {close XRDBPIPE;} - } - } - python { - foreach var $xres_to_del { - set var [charEscaped $var '] - lappend g_shcode_out "subprocess.Popen(\['$xrdb', '-merge'\],\ - stdin=subprocess.PIPE).communicate(input='$var:\\n')" - } - } - ruby { - foreach var $xres_to_del { - set var [charEscaped $var '] - lappend g_shcode_out "Open3.popen2('$xrdb -merge') {|i,o,t|\ - i.puts '$var:'}" - } - } - lisp { - foreach var $xres_to_del { - lappend g_shcode_out "(shell-command-to-string \"echo $var: |\ - $xrdb -merge\")" - } - } - cmake { - foreach var $xres_to_del { - set var [charEscaped $var \"] - lappend g_shcode_out "execute_process(COMMAND echo \"$var:\"\ - COMMAND $xrdb -merge)" - } - } - r { - foreach var $xres_to_del { - set var [charEscaped $var {\\'}] - lappend g_shcode_out "system('$xrdb -merge', input='$var:')" - } - } + foreach var $xres_to_del { + renderXResourceMerge $xrdb $var {} } } @@ -1477,9 +1392,13 @@ proc getQuarantineVarList {{report_bad 0}} { return $var_list } -proc setEnvVarIfUndefined {var_name value} { +# Indicate env var name to configured traces and define this variable with +# an empty value if undefined, to get it known when referred afterward. For +# modulefile commands evaluated in a mode that does not change environment. +proc declareEnvVar {var_name} { + setState current_envvar $var_name if {![isEnvVarDefined $var_name]} { - set ::env($var_name) $value + set ::env($var_name) {} } } diff --git a/tcl/interp.tcl.in b/tcl/interp.tcl.in index 3786f8b7f..2b293ff07 100644 --- a/tcl/interp.tcl.in +++ b/tcl/interp.tcl.in @@ -264,52 +264,13 @@ proc execute-modulefile {modfile modname modnamevrvar modspec requested\ # variable to define in modulefile interp if {![info exists ::g_modfileBaseVars]} { - # record module tool properties - set ::g_modfileBaseVars [list ModuleTool Modules ModuleToolVersion\ - [getState modules_release]] - - if {[info exists ::modulefile_extra_vars]} { - if {([llength $::modulefile_extra_vars] % 2) != 0} { - knerror "Invalid value '$::modulefile_extra_vars' (list must have\ - an even number of elements)\nfor siteconfig variable\ - 'modulefile_extra_vars'" - } - foreach {var val} $::modulefile_extra_vars { - if {[string first { } $var] != -1} { - knerror "Invalid variable name '$var'\ndefined in siteconfig\ - variable 'modulefile_extra_vars'" - } - } - lappend ::g_modfileBaseVars {*}$::modulefile_extra_vars - } - } - - # create modulefile interpreter at first interpretation - if {![interp exists $itrp]} { - createInterp $itrp - - # initialize global static variables for modulefile interp - foreach {var val} $::g_modfileBaseVars { - interp eval $itrp set ::$var "{$val}" - } - - # dump initial interpreter state to restore it before each modulefile - # interpretation. use same dump state for all modes/levels - if {![info exists ::g_modfileVars]} { - dumpInterpState $itrp g_modfileVars g_modfileArrayVars\ - g_modfileUntrackVars g_modfileProcs - } - - # interp has just been created - set fresh 1 - } else { - set fresh 0 + initInterpBaseVars g_modfileBaseVars modulefile_extra_vars } - # reset interp state command before each interpretation - resetInterpState $itrp $fresh g_modfileVars g_modfileArrayVars\ - g_modfileUntrackVars g_modfileProcs $aliasesVN $aliasesPassArgVN\ - $tracesVN g_modfileRenameCmds $dumpCommandsVN + # create modulefile interpreter at first interpretation and reset its + # state before each interpretation + setupInterp $itrp g_modfile $aliasesVN $aliasesPassArgVN $tracesVN\ + $dumpCommandsVN runHooks before-modulefile-eval $modfile $modname $modnamevr $modspec\ $mode $requested @@ -602,23 +563,7 @@ proc execute-modulerc {modfile modname modspec} { array set ::g_modrcAliasesTraces [list] # variable to define in modulerc interp - set ::g_modrcBaseVars [list ModuleTool Modules ModuleToolVersion\ - [getState modules_release]] - - if {[info exists ::modulerc_extra_vars]} { - if {([llength $::modulerc_extra_vars] % 2) != 0} { - knerror "Invalid value '$::modulerc_extra_vars' (list must have\ - an even number of elements)\nfor siteconfig variable\ - 'modulerc_extra_vars'" - } - foreach {var val} $::modulerc_extra_vars { - if {[string first { } $var] != -1} { - knerror "Invalid variable name '$var'\ndefined in siteconfig\ - variable 'modulerc_extra_vars'" - } - } - lappend ::g_modrcBaseVars {*}$::modulerc_extra_vars - } + initInterpBaseVars g_modrcBaseVars modulerc_extra_vars } # dedicate an interpreter per level of interpretation to have in case of @@ -626,32 +571,10 @@ proc execute-modulerc {modfile modname modspec} { set itrp __modrc_[depthState modulename] reportTrace '$modfile' {Evaluate modulerc} - # create modulerc interpreter at first interpretation - if {![interp exists $itrp]} { - createInterp $itrp - - # initialize global static variables for modulerc interp - foreach {var val} $::g_modrcBaseVars { - interp eval $itrp set ::$var "{$val}" - } - - # dump initial interpreter state to restore it before each modulerc - # interpretation. use same dump state for all levels - if {![info exists ::g_modrcVars]} { - dumpInterpState $itrp g_modrcVars g_modrcArrayVars\ - g_modrcUntrackVars g_modrcProcs - } - - # interp has just been created - set fresh 1 - } else { - set fresh 0 - } - - # reset interp state command before each interpretation - resetInterpState $itrp $fresh g_modrcVars g_modrcArrayVars\ - g_modrcUntrackVars g_modrcProcs g_modrcAliases g_modrcAliasesPassArg\ - g_modrcAliasesTraces g_modrcRenameCmds g_modrcCommands + # create modulerc interpreter at first interpretation and reset its state + # before each interpretation + setupInterp $itrp g_modrc g_modrcAliases g_modrcAliasesPassArg\ + g_modrcAliasesTraces g_modrcCommands runHooks before-modulerc-eval $modfile $modname @@ -732,6 +655,61 @@ proc formatInterpErrStackTrace {itrp modfile} { commands]]] } +# Define in global variable named base_vars_vn the variables to set in a kind +# of sub interpreter: module tool properties and variables defined through +# the siteconfig variable named extra_vars_name. +proc initInterpBaseVars {base_vars_vn extra_vars_name} { + upvar #0 $base_vars_vn base_vars $extra_vars_name extra_vars + # record module tool properties + set base_vars [list ModuleTool Modules ModuleToolVersion [getState\ + modules_release]] + + if {[info exists extra_vars]} { + if {([llength $extra_vars] % 2) != 0} { + knerror "Invalid value '$extra_vars' (list must have an even number\ + of elements)\nfor siteconfig variable '$extra_vars_name'" + } + foreach {var val} $extra_vars { + if {[string first { } $var] != -1} { + knerror "Invalid variable name '$var'\ndefined in siteconfig\ + variable '$extra_vars_name'" + } + } + lappend base_vars {*}$extra_vars + } +} + +# Create sub interpreter at first interpretation and reset its state before +# each interpretation. Names of the global structures holding initial state +# of interpreter start with prefix (g_modfile, g_modrc or g_cachefile). +proc setupInterp {itrp prefix aliasesVN aliasesPassArgVN tracesVN\ + dumpCommandsVN} { + upvar #0 ${prefix}BaseVars base_vars ${prefix}Vars dump_vars + set fresh [expr {![interp exists $itrp]}] + if {$fresh} { + createInterp $itrp + + # initialize global static variables of interp + if {[info exists base_vars]} { + foreach {var val} $base_vars { + interp eval $itrp set ::$var "{$val}" + } + } + + # dump initial interpreter state to restore it before each + # interpretation. use same dump state for all modes/levels + if {![info exists dump_vars]} { + dumpInterpState $itrp ${prefix}Vars ${prefix}ArrayVars\ + ${prefix}UntrackVars ${prefix}Procs + } + } + + # reset interp state command before each interpretation + resetInterpState $itrp $fresh ${prefix}Vars ${prefix}ArrayVars\ + ${prefix}UntrackVars ${prefix}Procs $aliasesVN $aliasesPassArgVN\ + $tracesVN ${prefix}RenameCmds $dumpCommandsVN +} + # Save list of the defined procedure and the global variables with their # associated values set in sub interpreter passed as argument. Global # structures are used to save these information and the name of these diff --git a/tcl/main.tcl.in b/tcl/main.tcl.in index 4f85467e8..358296f25 100644 --- a/tcl/main.tcl.in +++ b/tcl/main.tcl.in @@ -216,19 +216,11 @@ proc parseModuleCommandArgs {topcall cmd ignerr ml_spec args} { lappend otherargs $arg } } - --all - --show_hidden { - # include hidden modules only on a limited set of command - if {$cmd in [list avail aliases search whatis ml list lint\ - savelist spider]} { - set ::asked_hiding_threshold 2 - } else { - lappend otherargs $arg - } - } - -a { + -a - --all - --show_hidden { # -a option has a different meaning whether sub-command is use - # or one of the search/listing sub-commands - if {$cmd eq {use}} { + # or one of the search/listing sub-commands. include hidden + # modules only on a limited set of command + if {$arg eq {-a} && $cmd eq {use}} { set addpath_pos append } elseif {$cmd in [list avail aliases search whatis ml list\ lint savelist spider]} { diff --git a/tcl/mfcmd.tcl b/tcl/mfcmd.tcl index e73e754d6..f6da7b4c1 100644 --- a/tcl/mfcmd.tcl +++ b/tcl/mfcmd.tcl @@ -80,11 +80,11 @@ proc module-info {what {more {}}} { specified { return [currentState specifiedname] } - shell { + shell - shelltype { if {$more ne {}} { - return [expr {[getState shell] eq $more}] + return [expr {[getState $what] eq $more}] } else { - return [getState shell] + return [getState $what] } } flags { @@ -92,13 +92,6 @@ proc module-info {what {more {}}} { # a zero integer value to avoid breaking modulefiles using it return 0 } - shelltype { - if {$more ne {}} { - return [expr {[getState shelltype] eq $more}] - } else { - return [getState shelltype] - } - } user { # C-version specific option, not relevant for Tcl-version but return # an empty value or false to avoid breaking modulefiles using it @@ -116,10 +109,7 @@ proc module-info {what {more {}}} { return {} } } - trace { - return {} - } - tracepat { + trace - tracepat { return {} } type { @@ -417,47 +407,50 @@ proc setModspecTag {modspec tag {props {}} {is_regexp 0}} { } } -proc module-forbid {args} { - # parse application criteria arguments to determine if command apply - lassign [parseApplicationCriteriaArgs 1 [expr {[getConf\ - nearly_forbidden_days] * 86400}] {*}$args] apply isnearly after\ - otherargs is_regexp - - # parse remaining argument list, do it even if command does not apply to - # raise any command specification error - foreach arg $otherargs { +# Parse arguments of a module-* modulefile command left once application +# criteria are extracted. optspec associates each option of command to either +# the name of the variable of calling context that receives option value or +# to this variable name and the value to set it to when option takes no +# value. Return the other arguments, which are the module specifications. +proc parseModspecCommandArgs {is_regexp optspec args} { + array set optarr $optspec + set modarglist {} + foreach arg $args { if {[info exists nextargisval]} { - ##nagelfar vartype nextargisval varName - set $nextargisval $arg + uplevel 1 [list set $nextargisval $arg] unset nextargisval - } else { - switch -glob -- $arg { - --nearly-message { - set nextargisval nearlymessage - } - --message { - set nextargisval message - } - -* { - # a regular expression may start with a dash character - if {!$is_regexp} { - knerror "Invalid option '$arg'" - } - lappend modarglist $arg - } - default { - lappend modarglist $arg - } + } elseif {[info exists optarr($arg)]} { + if {[llength $optarr($arg)] > 1} { + uplevel 1 [list set {*}$optarr($arg)] + } else { + set nextargisval $optarr($arg) + set prevarg $arg } - set prevarg $arg + # a regular expression may start with a dash character + } elseif {[string index $arg 0] eq {-} && !$is_regexp} { + knerror "Invalid option '$arg'" + } else { + lappend modarglist $arg } } if {[info exists nextargisval]} { knerror "Missing value for '$prevarg' option" } + return $modarglist +} - if {![info exists modarglist]} { +proc module-forbid {args} { + # parse application criteria arguments to determine if command apply + lassign [parseApplicationCriteriaArgs 1 [expr {[getConf\ + nearly_forbidden_days] * 86400}] {*}$args] apply isnearly after\ + otherargs is_regexp + + # parse remaining argument list, do it even if command does not apply to + # raise any command specification error + set modarglist [parseModspecCommandArgs $is_regexp [list --nearly-message\ + nearlymessage --message message] {*}$otherargs] + if {![llength $modarglist]} { knerror {No module specified in argument} } @@ -499,34 +492,10 @@ proc module-hide {args} { # parse remaining argument list, do it even if command does not apply to # raise any command specification error - foreach arg $otherargs { - switch -glob -- $arg { - --hard { - # hardened stealth - set hidinglvl 2 - } - --soft { - # soften level of camouflage - set hidinglvl 0 - } - --hidden-loaded { - # module should stay hidden once being loaded - set hiddenloaded 1 - } - -* { - # a regular expression may start with a dash character - if {!$is_regexp} { - knerror "Invalid option '$arg'" - } - lappend modarglist $arg - } - default { - lappend modarglist $arg - } - } - } - - if {![info exists modarglist]} { + set modarglist [parseModspecCommandArgs $is_regexp [list --hard\ + {hidinglvl 2} --soft {hidinglvl 0} --hidden-loaded {hiddenloaded 1}]\ + {*}$otherargs] + if {![llength $modarglist]} { knerror {No module specified in argument} } @@ -687,49 +656,19 @@ proc setenv-un {args} { proc setenv-wh {args} { lassign [parseSetenvCommandArgs load set {*}$args] bhv var val - # indicate env var name to configured traces - setState current_envvar $var - - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } # parse arguments sent to the getenv modulefile command proc parseGetenvCommandArgs {cmd args} { - set returnval 0 - set valifundef {} - switch -- [llength $args] { - 1 { - set var [lindex $args 0] - } - 2 { - switch -- [lindex $args 0] { - --return-value { - set returnval 1 - set var [lindex $args 1] - } - default { - set var [lindex $args 0] - set valifundef [lindex $args 1] - } - } - } - 3 { - if {[lindex $args 0] ne {--return-value}} { - set wrongargs 1 - } else { - set returnval 1 - set var [lindex $args 1] - set valifundef [lindex $args 2] - } - } - default { - set wrongargs 1 - } - } + # option may be set prior the one or two arguments expected + set returnval [expr {[llength $args] > 1 && [lindex $args 0] eq\ + {--return-value}}] + lassign [lrange $args $returnval end] var valifundef set argname [expr {$cmd eq {getenv} ? {variable} : {name}}] - if {[info exists wrongargs]} { + if {[llength $args] - $returnval ni {1 2}} { knerror "wrong # args: should be \"$cmd ?--return-value? $argname\ ?valifundef?\"" } @@ -850,10 +789,7 @@ proc unsetenv-un {args} { proc unsetenv-wh {args} { lassign [parseUnsetenvCommandArgs load noop {*}$args] bhv var val - # indicate env var name to configured traces - setState current_envvar $var - - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } @@ -987,51 +923,31 @@ proc setModulesVersion {val} { # enabled) or postpone content channel send after rendering on stdout the # relative environment changes required by the modulefile proc putsModfileCmd {itrp args} { + # option may be set prior the one or two arguments expected + set nonewline [expr {[llength $args] > 1 && [lindex $args 0] eq\ + {-nonewline}}] + set msg [lindex $args end] # determine if puts call targets the stdout or stderr channel - switch -- [llength $args] { + switch -- [expr {[llength $args] - $nonewline}] { 1 { - # create struct with newline status and message to output - set deferPuts [list 1 [lindex $args 0]] + set defer_var ::g_stdoutPuts } 2 { - switch -- [lindex $args 0] { - -nonewline { - set deferPuts [list 0 [lindex $args 1]] - } + switch -- [lindex $args end-1] { stdout { - set deferPuts [list 1 [lindex $args 1]] + set defer_var ::g_stdoutPuts } prestdout { - set deferPrePuts [list 1 [lindex $args 1]] + set defer_var ::g_prestdoutPuts } stderr { - set reportArgs [list [lindex $args 1]] + set to_stderr 1 } log { - set logPuts [lindex $args 1] + set to_log 1 } } } - 3 { - if {[lindex $args 0] eq {-nonewline}} { - switch -- [lindex $args 1] { - stdout { - set deferPuts [list 0 [lindex $args 2]] - } - prestdout { - set deferPrePuts [list 0 [lindex $args 2]] - } - stderr { - set reportArgs [list [lindex $args 2] 1] - } - log { - set logPuts [lindex $args 2] - } - } - } else { - set wrongNumArgs 1 - } - } default { set wrongNumArgs 1 } @@ -1042,21 +958,20 @@ proc putsModfileCmd {itrp args} { if {[info exists wrongNumArgs]} { knerror {wrong # args: should be "puts ?-nonewline? ?channelId? string"} # send content to log system - } elseif {[info exists logPuts]} { - log $logPuts - # defer puts if it targets stdout (see renderSettings) - } elseif {[info exists deferPuts]} { + } elseif {[info exists to_log]} { + log $msg + # defer puts if it targets stdout (see renderSettings): record newline + # status and message to output + } elseif {[info exists defer_var]} { # current module is qualified for refresh evaluation lappendState -nodup refresh_qualified [currentState modulename] - lappend ::g_stdoutPuts {*}$deferPuts - } elseif {[info exists deferPrePuts]} { - lappendState -nodup refresh_qualified [currentState modulename] - lappend ::g_prestdoutPuts {*}$deferPrePuts + ##nagelfar vartype defer_var varName + lappend $defer_var [expr {!$nonewline}] $msg # if it targets stderr call report, which knows what channel to use - } elseif {[info exists reportArgs]} { + } elseif {[info exists to_stderr]} { # report message only if not silent if {[isVerbosityLevel concise]} { - report {*}$reportArgs + report $msg $nonewline } # pass to real puts command if not related to stdout and do that in modfile # interpreter context to get access to eventual specific channel @@ -1126,10 +1041,7 @@ proc edit-path-wh {cmd args} { idx_val ign_refcount val_set_is_delim glob_match bhv var path_list\ priority - # indicate env var name to configured traces - setState current_envvar $var - - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } @@ -1561,29 +1473,15 @@ proc execShAndGetEnv {elt_ignored_list shell script args} { set varvalmap [list {\"} \" \\\\ \\] set alvalmap [list {'\''} ' {'"'"'} '] } - bash { - ##nagelfar ignore +3 Found constant - set command "export -p; echo $sep; declare -f; echo $sep; alias;\ - echo $sep; complete; echo $sep; pwd; echo $sep; umask; echo $sep;\ - . [listTo shell $shdesc] 2>&1; echo $sep; export -p; echo $sep;\ - declare -f; echo $sep; alias; echo $sep; complete; echo $sep;\ - pwd; echo $sep; umask" - set varre {declare -x (\S+?)="(.*?)"$} - set funcre {(\S+?) \(\)\s?\n{\s?\n(.+?)\n}$} - set aliasre {alias (\S+?)='(.*?)'$} - set compre {complete (.+?) (\S+?)$} - set comprevar [list match value name] - set varvalmap [list {\"} \" \\\\ \\] - set alvalmap [list {'\''} '] - lappend shellopts --noprofile --norc - } - bash-eval { - ##nagelfar ignore +3 Found constant + bash - bash-eval { + ##nagelfar ignore Found constant + set shcmd [listTo shell $shdesc] + set srccmd [expr {[file tail $shell] eq {bash} ? ". $shcmd 2>&1" :\ + "eval \"\$($shcmd 2>/dev/null)\""}] set command "export -p; echo $sep; declare -f; echo $sep; alias;\ echo $sep; complete; echo $sep; pwd; echo $sep; umask; echo $sep;\ - eval \"\$([listTo shell $shdesc] 2>/dev/null)\"; echo $sep;\ - export -p; echo $sep; declare -f; echo $sep; alias; echo $sep;\ - complete; echo $sep; pwd; echo $sep; umask" + $srccmd; echo $sep; export -p; echo $sep; declare -f; echo $sep;\ + alias; echo $sep; complete; echo $sep; pwd; echo $sep; umask" set varre {declare -x (\S+?)="(.*?)"$} set funcre {(\S+?) \(\)\s?\n{\s?\n(.+?)\n}$} set aliasre {alias (\S+?)='(.*?)'$} @@ -2492,10 +2390,7 @@ proc pushenv-un {var val} { # optimized pushenv for whatis mode (same approach than setenv-wh) proc pushenv-wh {var val} { - # indicate env var name to configured traces - setState current_envvar $var - - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } @@ -2717,38 +2612,12 @@ proc module-warn {args} { # parse remaining argument list, do it even if command does not apply to # raise any command specification error - foreach arg $otherargs { - if {[info exists nextargisval]} { - ##nagelfar vartype nextargisval varName - set $nextargisval $arg - unset nextargisval - } else { - switch -glob -- $arg { - --message { - set nextargisval message - } - -* { - # a regular expression may start with a dash character - if {!$is_regexp} { - knerror "Invalid option '$arg'" - } - lappend modarglist $arg - } - default { - lappend modarglist $arg - } - } - set prevarg $arg - } - } - - if {[info exists nextargisval]} { - knerror "Missing value for '$prevarg' option" - } + set modarglist [parseModspecCommandArgs $is_regexp [list --message\ + message] {*}$otherargs] if {![info exists message]} { knerror {No message specified in argument} } - if {![info exists modarglist]} { + if {![llength $modarglist]} { knerror {No module specified in argument} } diff --git a/tcl/modeval.tcl b/tcl/modeval.tcl index 2d24edec6..657c31574 100644 --- a/tcl/modeval.tcl +++ b/tcl/modeval.tcl @@ -527,25 +527,12 @@ proc getDependentLoadedModuleList {modlist {strong 1} {direct 1} {nporeq 0}\ # may given module be automatically unloaded # unmodlist: pass a list of modules that are going to be unloaded proc isModuleUnloadable {mod {unmodlist {}}} { - set ret 1 - # module may be unloaded if it has been automatically loaded, it is not - # tagged keep-loaded and it is not sticky. - if {[isModuleTagged $mod loaded 1] || [isModuleTagged $mod keep-loaded\ - 1] || [isModuleSticky $mod]} { - set ret 0 - # there should no one requiring module or these dependent should be part of - # the unloaded/unloading list - } else { - foreach depmod [getDirectDependentList $mod] { - if {$depmod ni $unmodlist} { - set ret 0 - break - } - } - } - - return $ret + # tagged keep-loaded and it is not sticky. there should no one requiring + # module or these dependent should be part of the unloaded/unloading list + return [expr {![isModuleTagged $mod loaded 1] && ![isModuleTagged $mod\ + keep-loaded 1] && ![isModuleSticky $mod] && ![isDiffBetweenList\ + [getDirectDependentList $mod] $unmodlist]}] } # gets the list of all loaded modules which are required by passed mod_list diff --git a/tcl/modfind.tcl.in b/tcl/modfind.tcl.in index 13c9ce2ce..d4e6f4f63 100644 --- a/tcl/modfind.tcl.in +++ b/tcl/modfind.tcl.in @@ -679,18 +679,13 @@ proc getModuleTagProp {mod fpmod tag prop} { # Gather all tags applying to a given module proc collectModuleTags {mod} { - if {[info exists ::g_tagHash($mod)]} { - set known_tag_list $::g_tagHash($mod) - } else { - set known_tag_list {} - } - set tag_list [getMatchingTagList $mod $known_tag_list] + set tag_list [getMatchingTagList $mod] if {[llength $tag_list]} { setModuleTag $mod {*}$tag_list } } -proc getMatchingTagList {mod {known_tag_list {}}} { +proc getMatchingTagList {mod} { set tag_list {} set modroot [getModuleRootFromVersSpec $mod] # look if mod matches one of the module specs applying to mod root @@ -702,7 +697,6 @@ proc getMatchingTagList {mod {known_tag_list {}}} { $::g_moduleTagRootSpec($modroot) $i] { # add tag if one modspec matches mod if {[modEq $tmodspec $mod eqstart 1 0 1]} { - lappend known_tag_list $tag lappend tag_list $tag break } @@ -1022,80 +1016,36 @@ proc getVariantList {mod {report 0} {excl_dflval 0} {from 0}} { 3 {lappend ret $vrname [lindex $vrarr($vrname) 0] [lindex\ $vrarr($vrname) 1]} 2 {lappend ret [list $vrname 0 $vrisbool($vrname) $vrarr($vrname)]} - 1 - 5 - 6 { + 1 - 5 - 6 - 7 { if {$vrisbool($vrname)} { - if {$vrarr($vrname)} { - lappend ret +$vrname - # track if +var variant has been reported to build key - # unless if key should not be updated (report mode '6') - if {$report != 6 && ![info exists ::g_used_va(on)]} { - set ::g_used_va(on) 1 - } - } else { - lappend ret -$vrname - # track if -var variant has been reported to build key - # unless if key should not be updated (report mode '6') - if {$report != 6 && ![info exists ::g_used_va(off)]} { - set ::g_used_va(off) 1 - } - } + set vrset {} + lassign [expr {$vrarr($vrname) ? {+ on} : {- off}}] sign key + set vrval [list $sign$vrname] + set keyval 1 # use defined shortcut to report if any set for this variant # ignore shortcut if report=5 (when saving collection) } elseif {$report != 5 && [info exists\ ::g_variantShortcut($vrname)]} { - set sc $::g_variantShortcut($vrname) - lappend ret $sc$vrarr($vrname) - # track if variant shortcut has been reported to build key - # unless if key should not be updated (report mode '6') - if {$report != 6 && ![info exists ::g_used_va($sc)]} { - set ::g_used_va($sc) $vrname - } + set vrset $::g_variantShortcut($vrname) + set vrval $vrarr($vrname) + set key $vrset + set keyval $vrname } else { - lappend ret $vrname=$vrarr($vrname) - # track if var=val variant has been reported to build key - # unless if key should not be updated (report mode '6') - if {$report != 6 && ![info exists ::g_used_va(val)]} { - set ::g_used_va(val) 1 - } + set vrset $vrname= + set vrval $vrarr($vrname) + set key val + set keyval 1 } - } - 7 { - if {$vrisbool($vrname)} { - if {$vrarr($vrname)} { - lappend ret [list $vrname {} [list +$vrname]\ - $vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] - # track if +var variant has been reported to build key - if {![info exists ::g_used_va(on)]} { - set ::g_used_va(on) 1 - } - } else { - lappend ret [list $vrname {} [list -$vrname]\ - $vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] - # track if -var variant has been reported to build key - if {![info exists ::g_used_va(off)]} { - set ::g_used_va(off) 1 - } - } - # use defined shortcut to report if any set for this variant - # ignore shortcut if report=5 (when saving collection) - } elseif {$report != 5 && [info exists\ - ::g_variantShortcut($vrname)]} { - set sc $::g_variantShortcut($vrname) - lappend ret [list $vrname $sc $vrarr($vrname)\ - $vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] - # track if variant shortcut has been reported to build key - # unless if key should not be updated (report mode '6') - if {$report != 6 && ![info exists ::g_used_va($sc)]} { - set ::g_used_va($sc) $vrname - } + if {$report == 7} { + lappend ret [list $vrname $vrset $vrval $vrdflidxarr($vrname)\ + $vrloidxarr($vrname) $loadedsgrkey] } else { - lappend ret [list $vrname $vrname= $vrarr($vrname)\ - $vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] - # track if var=val variant has been reported to build key - # unless if key should not be updated (report mode '6') - if {$report != 6 && ![info exists ::g_used_va(val)]} { - set ::g_used_va(val) 1 - } + lappend ret $vrset$vrval + } + # track kind of variant reported to build key unless if key + # should not be updated (report mode '6') + if {$report != 6 && ![info exists ::g_used_va($key)]} { + set ::g_used_va($key) $keyval } } 0 {lappend ret $vrname $vrarr($vrname)} @@ -1105,20 +1055,15 @@ proc getVariantList {mod {report 0} {excl_dflval 0} {from 0}} { return $ret } -proc isOtherVariantOfModuleLoading {mod} { - set mod_name [getModuleNameAndVersFromVersSpec $mod] - set mod_has_variant [expr {$mod ne $mod_name}] - - return [expr {$mod_has_variant && [isModuleLoading $mod_name] && ![string\ - length [getLoadedMatchingName $mod {} 1]]}] -} - -proc isOtherVariantOfModuleLoaded {mod} { +# is module loaded, or loading if loading is enabled, with other variants +# than those specified +proc isOtherVariantOfModuleLoaded {mod {loading 0}} { set mod_name [getModuleNameAndVersFromVersSpec $mod] set mod_has_variant [expr {$mod ne $mod_name}] - return [expr {$mod_has_variant && [isModuleLoaded $mod_name] && ![string\ - length [getLoadedMatchingName $mod]]}] + return [expr {$mod_has_variant && ($loading ? [isModuleLoading $mod_name]\ + : [isModuleLoaded $mod_name]) && ![string length\ + [getLoadedMatchingName $mod {} $loading]]}] } proc isModuleDotHidden {mod} { @@ -1728,9 +1673,7 @@ proc setLoadedSourceSh {mod args} { } proc unsetLoadedSourceSh {mod} { - if {[info exists ::g_loadedModuleSourceSh($mod)]} { - unset ::g_loadedModuleSourceSh($mod) - } + unset -nocomplain ::g_loadedModuleSourceSh($mod) } proc getLoadedSourceSh {mod} { @@ -1765,9 +1708,7 @@ proc setLoadedConflictByModroot {mod args} { } proc unsetLoadedConflict {mod} { - if {[info exists ::g_loadedModuleConflict($mod)]} { - unset ::g_loadedModuleConflict($mod) - } + unset -nocomplain ::g_loadedModuleConflict($mod) unsetLoadedConflictByModroot $mod } @@ -1853,9 +1794,7 @@ proc setLoadedPrereq {mod args} { } proc unsetLoadedPrereq {mod} { - if {[info exists ::g_loadedModulePrereq($mod)]} { - unset ::g_loadedModulePrereq($mod) - } + unset -nocomplain ::g_loadedModulePrereq($mod) } proc getLoadedPrereq {mod} { @@ -1884,9 +1823,7 @@ proc setLoadedPrereqPath {mod args} { } proc unsetLoadedPrereqPath {mod} { - if {[info exists ::g_loadedModulePrereqPath($mod)]} { - unset ::g_loadedModulePrereqPath($mod) - } + unset -nocomplain ::g_loadedModulePrereqPath($mod) } proc getLoadedPrereqPath {mod {prereq {}}} { @@ -1919,15 +1856,8 @@ proc setLoadedAltname {mod args} { } proc unsetLoadedAltname {mod} { - if {[info exists ::g_loadedModuleAltname($mod)]} { - unset ::g_loadedModuleAltname($mod) - } - if {[info exists ::g_loadedModuleAliasAltname($mod)]} { - unset ::g_loadedModuleAliasAltname($mod) - } - if {[info exists ::g_loadedModuleAutoAltname($mod)]} { - unset ::g_loadedModuleAutoAltname($mod) - } + unset -nocomplain ::g_loadedModuleAltname($mod)\ + ::g_loadedModuleAliasAltname($mod) ::g_loadedModuleAutoAltname($mod) } proc getLoadedAltname {mod {typelist {sym alias autosym}} {with_type 0}} { @@ -2014,9 +1944,7 @@ proc setLoadedVariant {mod args} { } proc unsetLoadedVariant {mod} { - if {[info exists ::g_loadedModuleVariant($mod)]} { - unset ::g_loadedModuleVariant($mod) - } + unset -nocomplain ::g_loadedModuleVariant($mod) } proc getLoadedVariant {mod} { @@ -2028,12 +1956,7 @@ proc getLoadedVariant {mod} { proc getLoadedModuleWithVariantList {} { set modvrlist [list] foreach mod [getEnvLoadedModulePropertyParsedList name] { - set modvr [list $mod] - set vrlist [getVariantList $mod 5] - if {[llength $vrlist]} { - lappend modvr {*}$vrlist - } - lappend modvrlist $modvr + lappend modvrlist [list $mod {*}[getVariantList $mod 5]] } return $modvrlist } @@ -2041,11 +1964,7 @@ proc getLoadedModuleWithVariantList {} { proc getLoadedModuleWithVariantSaveTagArrayList {} { array set tag_arr {} foreach mod [getEnvLoadedModulePropertyParsedList name] { - set modvr [list $mod] - set vrlist [getVariantList $mod 1] - if {[llength $vrlist]} { - lappend modvr {*}$vrlist - } + set modvr [list $mod {*}[getVariantList $mod 1]] # create entry in array only if tags set set tag_list [getSaveTagList $mod] if {[llength $tag_list]} { @@ -2074,9 +1993,7 @@ proc setLoadedUse {mod args} { } proc unsetLoadedUse {mod} { - if {[info exists ::g_loadedModuleUse($mod)]} { - unset ::g_loadedModuleUse($mod) - } + unset -nocomplain ::g_loadedModuleUse($mod) } proc getLoadedUse {mod} { @@ -2382,45 +2299,27 @@ proc setModuleDependency {mod} { } } - switch -- [llength $lmprelist] { - 0 { + # build 'is depended by' relations, first taking loading order into + # account then not taking it (No Particular Order) + ##nagelfar ignore +2 Found constant + foreach {npo lmlist dep_list_vn vio_vn hash_vn} [list {} $lmprelist\ + deplist g_prereqViolation g_dependHash {NPO } $lmnpolist depnpolist\ + g_prereqNPOViolation g_dependNPOHash] { + ##nagelfar vartype dep_list_vn varName + upvar #0 $vio_vn vio_arr $hash_vn hash_arr + if {![llength $lmlist]} { # prereq not satisfied - reportDebug "set prereq violation state for '$mod'" - lappend ::g_prereqViolation($mod) $prereq - } - 1 { - set lmmod [lindex $lmprelist 0] - lappend deplist [list $lmmod] - # set 'is depended by' relations - lappend ::g_dependHash($lmmod) [list $mod] - } - default { - lappend deplist $lmprelist + reportDebug "set ${npo}prereq violation state for '$mod'" + lappend vio_arr($mod) $prereq + } else { + lappend $dep_list_vn $lmlist # many modules in prereq list, means they all set an optional dep - foreach lmmod $lmprelist { - lappend ::g_dependHash($lmmod) [list $mod 1] + set hashdep [list $mod] + if {[llength $lmlist] > 1} { + lappend hashdep 1 } - } - } - - # build 'is depended by' relations not taking loading order into account - switch -- [llength $lmnpolist] { - 0 { - # even on No Particular Order mode, prereq is not satisfied - reportDebug "set NPO prereq violation state for '$mod'" - lappend ::g_prereqNPOViolation($mod) $prereq - } - 1 { - set lmmod [lindex $lmnpolist 0] - lappend depnpolist [list $lmmod] - # set 'is depended by' relations - lappend ::g_dependNPOHash($lmmod) [list $mod] - } - default { - lappend depnpolist $lmnpolist - # many modules in prereq list, means they all set an optional dep - foreach lmmod $lmnpolist { - lappend ::g_dependNPOHash($lmmod) [list $mod 1] + foreach lmmod $lmlist { + lappend hash_arr($lmmod) $hashdep } } } @@ -2508,49 +2407,30 @@ proc setModuleDependency {mod} { # update dependency chain when unloading module proc unsetModuleDependency {mod} { - foreach lmmodlist $::g_moduleDepend($mod) { - set manymod [expr {[llength $lmmodlist] > 1}] - - # unset 'is depended by' mod relations - foreach lmmod $lmmodlist { - if {[info exists ::g_dependHash($lmmod)]} { - if {$manymod} { - set hashdep [list $mod 1] - } else { - set hashdep [list $mod] - } - lrem ::g_dependHash($lmmod) $hashdep - if {![llength $::g_dependHash($lmmod)]} { - unset ::g_dependHash($lmmod) - } - } - } - } - # unset mod's 'depends on' relation - reportDebug "unset requirements of '$mod'" - unset ::g_moduleDepend($mod) - - foreach lmmodlist $::g_moduleNPODepend($mod) { - set manymod [expr {[llength $lmmodlist] > 1}] - - # unset 'is depended by' mod relations - foreach lmmod $lmmodlist { - if {[info exists ::g_dependNPOHash($lmmod)]} { - if {$manymod} { - set hashdep [list $mod 1] - } else { - set hashdep [list $mod] - } - lrem ::g_dependNPOHash($lmmod) $hashdep - if {![llength $::g_dependNPOHash($lmmod)]} { - unset ::g_dependNPOHash($lmmod) + # process dependency structures taking loading order into account then + # those not taking it (No Particular Order) + foreach {npo dep_vn hash_vn} [list {} g_moduleDepend g_dependHash {NPO }\ + g_moduleNPODepend g_dependNPOHash] { + upvar #0 $dep_vn dep_arr $hash_vn hash_arr + foreach lmmodlist $dep_arr($mod) { + set hashdep [list $mod] + if {[llength $lmmodlist] > 1} { + lappend hashdep 1 + } + # unset 'is depended by' mod relations + foreach lmmod $lmmodlist { + if {[info exists hash_arr($lmmod)]} { + lrem hash_arr($lmmod) $hashdep + if {![llength $hash_arr($lmmod)]} { + unset hash_arr($lmmod) + } } } } + # unset mod's 'depends on' relation + reportDebug "unset ${npo}requirements of '$mod'" + unset dep_arr($mod) } - # unset mod's No Particular Order 'depends on' relation - reportDebug "unset NPO requirements of '$mod'" - unset ::g_moduleNPODepend($mod) # unset eventual violation states if {[info exists ::g_prereqViolation($mod)]} { @@ -2747,23 +2627,17 @@ proc cacheCurrentModules {} { } # cache declared tags of loaded modules - foreach modtag [getEnvLoadedModulePropertyParsedList tag] { - set tag_list [lassign $modtag mod] - if {[info exists modvrarr($mod)]} { - set mod_with_vr $modvrarr($mod) - } else { - set mod_with_vr {} - } - setModuleAndVariantsTag $mod $mod_with_vr {*}$tag_list - } - foreach modtag [getEnvLoadedModulePropertyParsedList extratag] { - set tag_list [lassign $modtag mod] - if {[info exists modvrarr($mod)]} { - set mod_with_vr $modvrarr($mod) - } else { - set mod_with_vr {} + foreach {prop setproc} [list tag setModuleAndVariantsTag extratag\ + setModuleAndVariantsExtraTag] { + foreach modtag [getEnvLoadedModulePropertyParsedList $prop] { + set tag_list [lassign $modtag mod] + if {[info exists modvrarr($mod)]} { + set mod_with_vr $modvrarr($mod) + } else { + set mod_with_vr {} + } + $setproc $mod $mod_with_vr {*}$tag_list } - setModuleAndVariantsExtraTag $mod $mod_with_vr {*}$tag_list } foreach modstickyrule [getEnvLoadedModulePropertyParsedList\ stickyrule] { @@ -3305,20 +3179,14 @@ proc findModulesFromDirsAndFiles {dir full_list depthlvl fetch_mtime\ } } else { switch -glob -- $tail { - .modulerc { - # rc file has normally been evaluated when its directory - # content was fetched: evaluate it here otherwise, when it - # is walked directly (limited access rc file from cache) - if {![info exists g_rcfilesSourced($element)]} { - execute-modulerc $element $modulename $modulename - set g_rcfilesSourced($element) 1 - } - set mod_list($modulename) [list modulerc] - } - .version { + .modulerc - .version { # skip .version file from different depth level than search - # targets if no in depth mode is enabled - if {$depthlvl == 0 || $moddepthlvl == $depthlvl} { + # targets if no in depth mode is enabled. rc file has normally + # been evaluated when its directory content was fetched: + # evaluate it here otherwise, when it is walked directly + # (limited access rc file from cache) + if {$tail eq {.modulerc} || $depthlvl == 0 || $moddepthlvl ==\ + $depthlvl} { if {![info exists g_rcfilesSourced($element)]} { execute-modulerc $element $modulename $modulename set g_rcfilesSourced($element) 1 diff --git a/tcl/modscan.tcl b/tcl/modscan.tcl index a6f065dbe..f8e0f3e57 100644 --- a/tcl/modscan.tcl +++ b/tcl/modscan.tcl @@ -47,12 +47,9 @@ proc variant-sc {itrp args} { proc setenv-sc {args} { lassign [parseSetenvCommandArgs load set {*}$args] bhv var val - # indicate env var name to configured traces - setState current_envvar $var - recordScanModuleElt $var setenv envvar - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } @@ -61,9 +58,6 @@ proc edit-path-sc {cmd args} { idx_val ign_refcount val_set_is_delim glob_match bhv var path_list\ priority - # indicate env var name to configured traces - setState current_envvar $var - recordScanModuleElt $var $cmd envvar # record MODULEPATH edition as "module use" command @@ -71,29 +65,23 @@ proc edit-path-sc {cmd args} { recordScanModuleUsePathList $path_list } - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } proc pushenv-sc {var val} { recordScanModuleElt $var pushenv envvar - # indicate env var name to configured traces - setState current_envvar $var - - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } proc unsetenv-sc {args} { lassign [parseUnsetenvCommandArgs load noop {*}$args] bhv var val - # indicate env var name to configured traces - setState current_envvar $var - recordScanModuleElt $var unsetenv envvar - setEnvVarIfUndefined $var {} + declareEnvVar $var return {} } diff --git a/tcl/modspec.tcl b/tcl/modspec.tcl index 213640c64..d4101ba24 100644 --- a/tcl/modspec.tcl +++ b/tcl/modspec.tcl @@ -18,6 +18,29 @@ ########################################################################## +# Rename alternative procedure procname into the generic procedure name it +# implements, unless already done. Alternative procedure previously renamed +# this way gets its own name back. Return 1 if an alternative procedure +# defined for another context has been replaced, 0 otherwise. +proc defineProcFromAlt {name procname} { + upvar #0 g_${name}_proc curprocname + set replaced 0 + # define proc if not done yet or if it was defined for another context + if {[info procs $name] eq {} || $curprocname ne $procname} { + if {[info exists curprocname]} { + # remove existing debug trace if any + initProcReportTrace remove $name + rename ::$name ::$curprocname + set replaced 1 + } + rename ::$procname ::$name + # set report traces if some debug mode enabled + initProcReportTrace add $name + set curprocname $procname + } + return $replaced +} + # Define procedure to get how many parts between passed name and mod are equal # Adapt procedure code whether icase is enabled or disabled proc defineModStartNbProc {icase} { @@ -25,19 +48,8 @@ proc defineModStartNbProc {icase} { if {$icase} { append procname Icase } - # define proc if not done yet or if it was defined for another context - if {[info procs modStartNb] eq {} || $::g_modStartNb_proc ne $procname} { - if {[info exists ::g_modStartNb_proc]} { - # remove existing debug trace if any - initProcReportTrace remove modStartNb - rename ::modStartNb ::$::g_modStartNb_proc - } - ##nagelfar syntax modStartNb x x - rename ::$procname ::modStartNb - # set report traces if some debug mode enabled - initProcReportTrace add modStartNb - set ::g_modStartNb_proc $procname - } + ##nagelfar syntax modStartNb x x + defineProcFromAlt modStartNb $procname } # alternative definitions of modStartNb proc @@ -94,21 +106,8 @@ proc defineGetEqArrayKeyProc {impdfl} { if {$impdfl} { append procname Impdfl } - - # define proc if not done yet or if it was defined for another context - if {[info procs getEqArrayKey] eq {} || $::g_getEqArrayKey_proc ne\ - $procname} { - if {[info exists ::g_getEqArrayKey_proc]} { - # remove existing debug trace if any - initProcReportTrace remove getEqArrayKey - rename ::getEqArrayKey ::$::g_getEqArrayKey_proc - } - ##nagelfar syntax getEqArrayKey x x - rename ::$procname ::getEqArrayKey - # set report traces if some debug mode enabled - initProcReportTrace add getEqArrayKey - set ::g_getEqArrayKey_proc $procname - } + ##nagelfar syntax getEqArrayKey x x + defineProcFromAlt getEqArrayKey $procname } # alternative definitions of getEqArrayKey proc @@ -255,20 +254,8 @@ proc defineModVersCmpProc {icase extdfl} { if {$extdfl} { append procname Extdfl } - - # define proc if not done yet or if it was defined for another context - if {[info procs modVersCmp] eq {} || $::g_modVersCmp_proc ne $procname} { - if {[info exists ::g_modVersCmp_proc]} { - # remove existing debug trace if any - initProcReportTrace remove modVersCmp - rename ::modVersCmp ::$::g_modVersCmp_proc - } - ##nagelfar syntax modVersCmp x x x x x? - rename ::$procname ::modVersCmp - # set report traces if some debug mode enabled - initProcReportTrace add modVersCmp - set ::g_modVersCmp_proc $procname - } + ##nagelfar syntax modVersCmp x x x x x? + defineProcFromAlt modVersCmp $procname } # alternative definitions of modVersCmp proc @@ -600,21 +587,10 @@ proc defineModEqProc {icase extdfl} { if {$extdfl} { append procname Extdfl } - - # define proc if not done yet or if it was defined for another context - if {[info procs modEq] eq {} || $::g_modEq_proc ne $procname} { - if {[info exists ::g_modEq_proc]} { - # remove existing debug trace if any - initProcReportTrace remove modEq - rename ::modEq ::$::g_modEq_proc - # drop existing mem cache - array unset ::g_modEqMemCache - } - ##nagelfar syntax modEq x x x? x? x? x? x? x? - rename ::$procname ::modEq - # set report traces if some debug mode enabled - initProcReportTrace add modEq - set ::g_modEq_proc $procname + ##nagelfar syntax modEq x x x? x? x? x? x? x? + if {[defineProcFromAlt modEq $procname]} { + # drop existing mem cache + array unset ::g_modEqMemCache } } @@ -1275,21 +1251,8 @@ proc defineParseModuleSpecificationProc {advverspec} { # resolved configured variant shortcut getConf variant_shortcut } - # define proc if not done yet or if it was defined for another context - if {[info procs parseModuleSpecification] eq {} ||\ - $::g_parseModuleSpecification_proc ne $procname} { - if {[info exists ::g_parseModuleSpecification_proc]} { - # remove existing debug trace if any - initProcReportTrace remove parseModuleSpecification - rename ::parseModuleSpecification\ - ::$::g_parseModuleSpecification_proc - } - ##nagelfar syntax parseModuleSpecification x x x x x* - rename ::$procname ::parseModuleSpecification - # set report traces if some debug mode enabled - initProcReportTrace add parseModuleSpecification - set ::g_parseModuleSpecification_proc $procname - } + ##nagelfar syntax parseModuleSpecification x x x x x* + defineProcFromAlt parseModuleSpecification $procname } # when advanced_version_spec option is enabled, parse argument list to set in diff --git a/tcl/report.tcl.in b/tcl/report.tcl.in index 88e125366..89679f288 100644 --- a/tcl/report.tcl.in +++ b/tcl/report.tcl.in @@ -266,17 +266,9 @@ proc reportMsgRecord {header {hidden 0}} { } } - # display each line - set first 1 - foreach line $linelist { - append dispmsg \n - if {$first} { - set first 0 - } else { - append dispmsg $padding - } - append dispmsg $padding$line - } + # display each line, those after first one are padded twice. a + # recorded message always holds text, so line list is not empty + append dispmsg \n$padding[join $linelist \n$padding$padding] } reportSeparateNextContent report $dispmsg @@ -605,16 +597,7 @@ proc __report {message {nonewline 0} {immed 0} {padnl 0}} { } # prefix msg lines after first one with 2 spaces if {$padnl} { - set first 1 - foreach line [split $message \n] { - if {$first} { - set first 0 - } else { - append padmsg "\n " - } - append padmsg $line - } - set message $padmsg + set message [join [split $message \n] "\n "] } # protect from issue with fd, just ignore it @@ -2023,24 +2006,11 @@ proc displayLinterOutput {linter output} { set colidx [string first : $line] set linenum [string trimleft [string range $line 5\ $colidx-1]] - set severity [string index $line $colidx+2] - switch -- $severity { - W { - set severity WARNING - set sgrkey wa - set raisecnt 0 - } - E { - set severity ERROR - set sgrkey er - set raisecnt 1 - } - default { - set severity NOTICE - set sgrkey in - set raisecnt 0 - } - } + lassign [switch -- [string index $line $colidx+2] { + W {list WARNING wa 0} + E {list ERROR er 1} + default {list NOTICE in 0} + }] severity sgrkey raisecnt set msg [string range $line $colidx+4 end] # start recorded message properties diff --git a/tcl/subcmd.tcl.in b/tcl/subcmd.tcl.in index 47a593562..ceb49e421 100644 --- a/tcl/subcmd.tcl.in +++ b/tcl/subcmd.tcl.in @@ -133,10 +133,12 @@ proc cmdModuleList {show_oneperline show_mtime search_match args} { } } -proc cmdModuleDisplay {args} { - lappendState mode display +# evaluate modules in specified mode and report result of each evaluation +# under a title made of modulefile path +proc displayModuleEvalList {evalmode title_prefix mod_list} { + lappendState mode $evalmode set first_report 1 - foreach mod $args { + foreach mod $mod_list { lassign [getPathToModule $mod] modfile modname modnamevr if {$modfile ne {}} { # only one separator lines between 2 modules @@ -144,7 +146,7 @@ proc cmdModuleDisplay {args} { displaySeparatorLine set first_report 0 } - report [sgr hi $modfile]:\n + report "$title_prefix[sgr hi $modfile]:\n" execute-modulefile $modfile $modname modnamevr $mod 1 displaySeparatorLine } @@ -152,6 +154,10 @@ proc cmdModuleDisplay {args} { lpopState mode } +proc cmdModuleDisplay {args} { + displayModuleEvalList display {} $args +} + proc cmdModulePaths {mod} { set dir_list [getModulePathList exiterronundef] foreach dir $dir_list { @@ -251,30 +257,22 @@ proc cmdModuleSearch {args} { # build list of modulefile to interpret foreach elt [array names mod_list] { switch -- [lindex $mod_list($elt) 0] { - modulefile { - if {[isModuleTagged $elt forbidden 0 $dir/$elt]} { - # register any error occurring on element matching search - if {[modEqAny $mod_pattern_list $elt]} { - set err_list($elt) [list accesserr [getForbiddenMsg\ - $elt $dir/$elt]] - } + modulefile - virtual { + if {[lindex $mod_list($elt) 0] eq {virtual}} { + set eltfile [lindex $mod_list($elt) 2] } else { - set interp_list($elt) $dir/$elt - # register module name in a global list (shared across - # modulepaths) to get hints when solving aliases/version - set full_list($elt) 1 + set eltfile $dir/$elt } - } - virtual { - if {[isModuleTagged $elt forbidden 0 [lindex $mod_list($elt)\ - 2]]} { + if {[isModuleTagged $elt forbidden 0 $eltfile]} { # register any error occurring on element matching search if {[modEqAny $mod_pattern_list $elt]} { set err_list($elt) [list accesserr [getForbiddenMsg\ - $elt [lindex $mod_list($elt) 2]]] + $elt $eltfile]] } } else { - set interp_list($elt) [lindex $mod_list($elt) 2] + set interp_list($elt) $eltfile + # register module name in a global list (shared across + # modulepaths) to get hints when solving aliases/version set full_list($elt) 1 } } @@ -695,14 +693,10 @@ proc cmdModuleSave {{coll default}} { } proc cmdModuleRestore {args} { - # distinguish between zero and one argument provided - if {![llength $args]} { - set arg_provided 0 - set coll default - } else { - set arg_provided 1 - set coll [lindex $args 0] - } + # distinguish between zero and one argument provided, default collection + # is targeted if no argument provided + set arg_provided [llength $args] + set coll [lindex [list {*}$args default] 0] # get corresponding collection, raise error if it does not exist unless # if no collection name has been provided or if __init__ @@ -815,36 +809,20 @@ proc cmdModuleSaverm {{coll default}} { } proc cmdModuleSaveshow {args} { - # distinguish between zero and one argument provided - if {![llength $args]} { - set arg_provided 0 - set coll default - } else { - set arg_provided 1 - set coll [lindex $args 0] - } + # distinguish between zero and one argument provided, default collection + # is targeted if no argument provided + set arg_provided [llength $args] + set coll [lindex [list {*}$args default] 0] # get corresponding collection, raise error if it does not exist unless # if no collection name has been provided or if __init__ lassign [findCollections $coll exact [expr {!$arg_provided}]\ $arg_provided] collfile colldesc - # read specific __init__ collection from __MODULES_LMINIT env var + lassign [readCollectionContent $collfile $colldesc] coll_path_list\ + coll_mod_list coll_tag_arrser if {$collfile eq {__init__}} { - lassign [parseCollectionContent [getEnvLoadedModulePropertyParsedList\ - init]] coll_path_list coll_mod_list coll_tag_arrser set collfile {initial environment} - set coll __init__ - } else { - lassign [readCollectionContent $collfile $colldesc] coll_path_list\ - coll_mod_list coll_tag_arrser - } - - # collection should at least define a path or a mod, but initial env may be - # totally empty - if {$coll ne {__init__} && ![llength $coll_path_list] && ![llength\ - $coll_mod_list]} { - reportErrorAndExit "$colldesc is not a valid collection" } displaySeparatorLine @@ -1211,7 +1189,7 @@ proc cmdModuleLoad {context uasked tryload loadany tag_list modulepath_list\ } # stop if same mod is loaded but with a different set of variants } elseif {[isOtherVariantOfModuleLoaded $modnamevr] ||\ - [isOtherVariantOfModuleLoading $modnamevr]} { + [isOtherVariantOfModuleLoaded $modnamevr 1]} { # no error if ConUn mechanism handles unload of this module if {![getConf auto_handling] || ![getConf conflict_unload] ||\ $isloading} { @@ -1710,15 +1688,9 @@ proc cmdModuleUnload {context match auto force onlyureq args} { # update cache arrays unsetLoadedModule $modname $modfile - if {[array exists ::g_isLoadedMatchSpecificPathMemCache]} { - array unset ::g_isLoadedMatchSpecificPathMemCache - } - if {[array exists ::g_isLoadingMatchSpecificPathMemCache]} { - array unset ::g_isLoadingMatchSpecificPathMemCache - } - if {[array exists ::g_loadRequirementModuleListMemCache]} { - array unset ::g_loadRequirementModuleListMemCache - } + array unset ::g_isLoadedMatchSpecificPathMemCache + array unset ::g_isLoadingMatchSpecificPathMemCache + array unset ::g_loadRequirementModuleListMemCache # unregister declared source-sh unsetEnvLoadedModuleProperty $modname sourcesh @@ -2399,22 +2371,7 @@ proc cmdModuleResurface {cmd args} { } proc cmdModuleTest {args} { - lappendState mode test - set first_report 1 - foreach mod $args { - lassign [getPathToModule $mod] modfile modname modnamevr - if {$modfile ne {}} { - # only one separator lines between 2 modules - if {$first_report} { - displaySeparatorLine - set first_report 0 - } - report "Module Specific Test for [sgr hi $modfile]:\n" - execute-modulefile $modfile $modname modnamevr $mod 1 - displaySeparatorLine - } - } - lpopState mode + displayModuleEvalList test {Module Specific Test for } $args } proc cmdModuleClear {args} { @@ -2754,23 +2711,7 @@ proc cmdModuleRefresh {} { } proc cmdModuleHelp {args} { - lappendState mode help - set first_report 1 - foreach arg $args { - lassign [getPathToModule $arg] modfile modname modnamevr - - if {$modfile ne {}} { - # only one separator lines between 2 modules - if {$first_report} { - displaySeparatorLine - set first_report 0 - } - report "Module Specific Help for [sgr hi $modfile]:\n" - execute-modulefile $modfile $modname modnamevr $arg 1 - displaySeparatorLine - } - } - lpopState mode + displayModuleEvalList help {Module Specific Help for } $args if {![llength $args]} { reportUsage }