| 1 |
########################################################################## |
| 2 |
|
| 3 |
# MODFIND.TCL, available or loaded module find procedures |
| 4 |
# Copyright (C) 2002-2004 Mark Lakata |
| 5 |
# Copyright (C) 2004-2017 Kent Mein |
| 6 |
# Copyright (C) 2016-2026 Xavier Delaruelle |
| 7 |
# |
| 8 |
# This program is free software: you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation, either version 2 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
########################################################################## |
| 22 |
|
| 23 |
# convert environment variable references in string to their values |
| 24 |
# every local variable is prefixed by '0' to ensure they will not be |
| 25 |
# overwritten through variable reference resolution process |
| 26 |
proc resolvStringWithEnv {0str} { |
| 27 |
# fetch variable references in string |
| 28 |
set 0match_list [regexp -all -inline {\$[{]?([A-Za-z_][A-Za-z0-9_]*)[}]?}\ |
| 29 |
${0str}] |
| 30 |
if {[llength ${0match_list}]} { |
| 31 |
# put in local scope every environment variable referred in string |
| 32 |
for {set 0i 1} {${0i} < [llength ${0match_list}]} {incr 0i 2} { |
| 33 |
set 0varname [lindex ${0match_list} ${0i}] |
| 34 |
##nagelfar vartype 0varname varName |
| 35 |
if {![info exists ${0varname}]} { |
| 36 |
set ${0varname} [get-env ${0varname}] |
| 37 |
} |
| 38 |
} |
| 39 |
# resolve variable reference with values (now in local scope) |
| 40 |
set 0res [subst -nobackslashes -nocommands ${0str}] |
| 41 |
} else { |
| 42 |
set 0res ${0str} |
| 43 |
} |
| 44 |
|
| 45 |
reportDebug "'${0str}' resolved to '${0res}'" |
| 46 |
|
| 47 |
return ${0res} |
| 48 |
} |
| 49 |
|
| 50 |
# in each string of a list, convert their variable reference into actual value |
| 51 |
proc resolvStringListWithEnv {str_list} { |
| 52 |
set res_list {} |
| 53 |
foreach str $str_list { |
| 54 |
lappend res_list [resolvStringWithEnv $str] |
| 55 |
} |
| 56 |
return $res_list |
| 57 |
} |
| 58 |
|
| 59 |
# Return first string in list matching given resolved string. Strings in list |
| 60 |
# are resolved to help comparison in case they contain an env variable ref. |
| 61 |
proc getStringFromListMatchingResString {str_list resolved_str} { |
| 62 |
foreach str $str_list { |
| 63 |
if {$resolved_str eq [resolvStringWithEnv $str]} { |
| 64 |
return $str |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
# deduce modulepath from modulefile and module name |
| 70 |
proc getModulepathFromModuleName {modfile modname} { |
| 71 |
return [string range $modfile 0 end-[string length /$modname]] |
| 72 |
} |
| 73 |
|
| 74 |
# deduce module name from modulefile and modulepath |
| 75 |
proc getModuleNameFromModulepath {modfile modpath} { |
| 76 |
return [string range $modfile [string length $modpath/] end] |
| 77 |
} |
| 78 |
|
| 79 |
# check if given modulefile is hosted in one the given modulepaths |
| 80 |
proc isModulefileInModulepathList {mod_file modulepath_list} { |
| 81 |
set ret 0 |
| 82 |
foreach modulepath $modulepath_list { |
| 83 |
if {[string first $modulepath/ $mod_file] == 0} { |
| 84 |
set ret 1 |
| 85 |
break |
| 86 |
} |
| 87 |
} |
| 88 |
return $ret |
| 89 |
} |
| 90 |
|
| 91 |
# return list of all enabled modulepaths matching given path |
| 92 |
proc getMatchingModulepathList {path} { |
| 93 |
set ret {} |
| 94 |
foreach modulepath [getModulePathList] { |
| 95 |
if {[string first $path/ $modulepath] == 0} { |
| 96 |
lappend ret $modulepath |
| 97 |
} |
| 98 |
} |
| 99 |
return $ret |
| 100 |
} |
| 101 |
|
| 102 |
# extract module name from modulefile and currently enabled modulepaths |
| 103 |
proc findModuleNameFromModulefile {modfile} { |
| 104 |
set ret {} |
| 105 |
|
| 106 |
foreach modpath [getModulePathList] { |
| 107 |
if {[string first $modpath/ $modfile/] == 0} { |
| 108 |
set ret [getModuleNameFromModulepath $modfile $modpath] |
| 109 |
break |
| 110 |
} |
| 111 |
} |
| 112 |
return $ret |
| 113 |
} |
| 114 |
|
| 115 |
# extract modulepath from modulefile and currently enabled modulepaths |
| 116 |
proc findModulepathFromModulefile {modfile} { |
| 117 |
set ret {} |
| 118 |
|
| 119 |
foreach modpath [getModulePathList] { |
| 120 |
if {[string first $modpath/ $modfile/] == 0} { |
| 121 |
set ret $modpath |
| 122 |
break |
| 123 |
} |
| 124 |
} |
| 125 |
return $ret |
| 126 |
} |
| 127 |
|
| 128 |
# Determine with a name provided as argument the corresponding module name, |
| 129 |
# version and name/version. Module name is guessed from current module name |
| 130 |
# when shorthand version notation is used. Both name and version are guessed |
| 131 |
# from current module if name provided is empty. If 'name_relative_tocur' is |
| 132 |
# enabled then name argument may be interpreted as a name relative to the |
| 133 |
# current modulefile directory (useful for module-version and module-alias |
| 134 |
# for instance). |
| 135 |
proc getModuleNameVersion {{name {}} {name_relative_tocur 0}} { |
| 136 |
set curmod [currentState modulename] |
| 137 |
set curmodname [file dirname $curmod] |
| 138 |
set curmodversion [file tail $curmod] |
| 139 |
|
| 140 |
if {$name eq {}} { |
| 141 |
set name $curmodname |
| 142 |
set version $curmodversion |
| 143 |
# check for shorthand version notation like "/version" or "./version" |
| 144 |
# only if we are currently interpreting a modulefile or modulerc |
| 145 |
} elseif {$curmod ne {} && [regexp {^\.?\/(.*)$} $name match version]} { |
| 146 |
# if we cannot distinguish a module name, raise error when shorthand |
| 147 |
# version notation is used |
| 148 |
if {[currentState modulefile] ne $curmod && $curmod ne {.modulerc}} { |
| 149 |
# name is the name of current module directory |
| 150 |
set name $curmodname |
| 151 |
} else { |
| 152 |
reportError "Invalid modulename '$name' found" |
| 153 |
return {} |
| 154 |
} |
| 155 |
} else { |
| 156 |
set name [string trimright $name /] |
| 157 |
set version [file tail $name] |
| 158 |
if {$name eq $version} { |
| 159 |
set version {} |
| 160 |
} else { |
| 161 |
set name [file dirname $name] |
| 162 |
} |
| 163 |
# name may correspond to last part of current module |
| 164 |
# if so name is replaced by current module name |
| 165 |
if {$name_relative_tocur && [file tail $curmodname] eq $name} { |
| 166 |
set name $curmodname |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
if {$version eq {}} { |
| 171 |
set mod $name |
| 172 |
} else { |
| 173 |
set mod $name/$version |
| 174 |
} |
| 175 |
|
| 176 |
return [list $mod $name $version] |
| 177 |
} |
| 178 |
|
| 179 |
# Register alias or symbolic version deep resolution in a global array that |
| 180 |
# can be used thereafter to get in one query the actual modulefile behind |
| 181 |
# a virtual name. Also consolidate a global array that in the same manner |
| 182 |
# list all the symbols held by modulefiles. |
| 183 |
proc setModuleResolution {mod target {symver {}} {override_res_path 1}\ |
| 184 |
{auto_symver 0}} { |
| 185 |
global g_moduleResolved g_resolvedHash g_resolvedPath g_symbolHash |
| 186 |
|
| 187 |
# find end-point module and register step-by-step path to get to it |
| 188 |
set res $target |
| 189 |
lappend res_path $res |
| 190 |
while {$mod ne $res && [info exists g_resolvedPath($res)]} { |
| 191 |
set res $g_resolvedPath($res) |
| 192 |
lappend res_path $res |
| 193 |
} |
| 194 |
|
| 195 |
# error if resolution end on initial module |
| 196 |
if {$mod eq $res} { |
| 197 |
reportError "Resolution loop on '$res' detected" |
| 198 |
return 0 |
| 199 |
} |
| 200 |
|
| 201 |
# module name will be useful when registering symbol |
| 202 |
if {$symver ne {}} { |
| 203 |
lassign [getModuleNameVersion $mod] modfull modname |
| 204 |
} |
| 205 |
|
| 206 |
# change default symbol owner if previously given; auto symbol are defined |
| 207 |
# only if no default is pre-existing |
| 208 |
if {$symver eq {default} && !$auto_symver} { |
| 209 |
# alternative name "modname" is set when mod = "modname/default" both |
| 210 |
# names will be registered to be known for queries and resolution defs |
| 211 |
set modalt $modname |
| 212 |
|
| 213 |
if {[info exists g_moduleResolved($mod)]} { |
| 214 |
set prev $g_moduleResolved($mod) |
| 215 |
# there may not be a default in case of auto symbol |
| 216 |
if {[info exists g_symbolHash($prev)] && [set idx [lsearch -exact\ |
| 217 |
$g_symbolHash($prev) default]] != -1} { |
| 218 |
reportDebug "remove symbol 'default' from '$prev'" |
| 219 |
set g_symbolHash($prev) [lreplace $g_symbolHash($prev) $idx $idx] |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
# register end-point resolution |
| 225 |
reportDebug "$mod resolved to $res" |
| 226 |
set g_moduleResolved($mod) $res |
| 227 |
# set first element of resolution path only if not already set or |
| 228 |
# scratching enabled, no change when propagating symbol along res path |
| 229 |
if {$override_res_path || ![info exists g_resolvedPath($mod)]} { |
| 230 |
set g_resolvedPath($mod) $target |
| 231 |
} |
| 232 |
lappend g_resolvedHash($res) $mod |
| 233 |
|
| 234 |
# also register resolution on alternative name if any |
| 235 |
if {[info exists modalt]} { |
| 236 |
reportDebug "$modalt resolved to $res" |
| 237 |
set g_moduleResolved($modalt) $res |
| 238 |
if {$override_res_path || ![info exists g_resolvedPath($modalt)]} { |
| 239 |
set g_resolvedPath($modalt) $target |
| 240 |
} |
| 241 |
lappend g_resolvedHash($res) $modalt |
| 242 |
# register name alternative to know their existence |
| 243 |
set ::g_moduleAltName($modalt) $mod |
| 244 |
set ::g_moduleAltName($mod) $modalt |
| 245 |
} |
| 246 |
|
| 247 |
# if other modules were pointing to this one, adapt resolution end-point |
| 248 |
set relmod_list {} |
| 249 |
if {[info exists g_resolvedHash($mod)]} { |
| 250 |
set relmod_list $g_resolvedHash($mod) |
| 251 |
unset g_resolvedHash($mod) |
| 252 |
} |
| 253 |
# also adapt resolution for modules pointing to the alternative name |
| 254 |
if {[info exists modalt] && [info exists g_resolvedHash($modalt)]} { |
| 255 |
lappend relmod_list {*}$g_resolvedHash($modalt) |
| 256 |
unset g_resolvedHash($modalt) |
| 257 |
} |
| 258 |
foreach relmod $relmod_list { |
| 259 |
set g_moduleResolved($relmod) $res |
| 260 |
reportDebug "$relmod now resolved to $res" |
| 261 |
lappend g_resolvedHash($res) $relmod |
| 262 |
} |
| 263 |
|
| 264 |
# register and propagate symbols to the resolution path, exception made for |
| 265 |
# auto symbol which are stored separately and not propagated |
| 266 |
if {[info exists g_symbolHash($mod)]} { |
| 267 |
set sym_list $g_symbolHash($mod) |
| 268 |
} else { |
| 269 |
set sym_list {} |
| 270 |
} |
| 271 |
if {$symver ne {} && $auto_symver} { |
| 272 |
reportDebug "define auto symbolic version '$mod' targeting $target" |
| 273 |
set ::g_autoSymbol($mod) $target |
| 274 |
} elseif {$symver ne {} && !$auto_symver} { |
| 275 |
# merge symbol definitions in case of alternative name |
| 276 |
if {[info exists modalt] && [info exists g_symbolHash($modalt)]} { |
| 277 |
set sym_list [lsort -dictionary -unique [list {*}$sym_list\ |
| 278 |
{*}$g_symbolHash($modalt)]] |
| 279 |
reportDebug "set symbols '$sym_list' to $mod and $modalt" |
| 280 |
set g_symbolHash($mod) $sym_list |
| 281 |
set g_symbolHash($modalt) $sym_list |
| 282 |
} |
| 283 |
|
| 284 |
# dictionary-sort symbols and remove eventual duplicates |
| 285 |
set sym_list [lsort -dictionary -unique [list {*}$sym_list $symver]] |
| 286 |
|
| 287 |
# propagate symbols in g_symbolHash and g_moduleVersion toward the |
| 288 |
# resolution path, handle that locally if we still work on same |
| 289 |
# modulename, call for a proper resolution as soon as we change of |
| 290 |
# module to get this new resolution registered |
| 291 |
foreach modres $res_path { |
| 292 |
lassign [getModuleNameVersion $modres] modfull modresname |
| 293 |
if {$modname eq $modresname} { |
| 294 |
if {[info exists g_symbolHash($modres)]} { |
| 295 |
set modres_sym_list [lsort -dictionary -unique [list\ |
| 296 |
{*}$g_symbolHash($modres) {*}$sym_list]] |
| 297 |
} else { |
| 298 |
set modres_sym_list $sym_list |
| 299 |
} |
| 300 |
# sync symbols of alternative name if any |
| 301 |
if {[info exists ::g_moduleAltName($modres)]} { |
| 302 |
set altmodres $::g_moduleAltName($modres) |
| 303 |
reportDebug "set symbols '$modres_sym_list' to $modres and\ |
| 304 |
$altmodres" |
| 305 |
set g_symbolHash($altmodres) $modres_sym_list |
| 306 |
} else { |
| 307 |
reportDebug "set symbols '$modres_sym_list' to $modres" |
| 308 |
} |
| 309 |
set g_symbolHash($modres) $modres_sym_list |
| 310 |
|
| 311 |
# register symbolic version for querying in g_moduleVersion |
| 312 |
foreach symelt $sym_list { |
| 313 |
set modvers $modresname/$symelt |
| 314 |
reportDebug "module-version $modvers = $modres" |
| 315 |
set ::g_moduleVersion($modvers) $modres |
| 316 |
set ::g_sourceVersion($modvers) [currentState modulefile] |
| 317 |
# record eventual missing resolution |
| 318 |
if {![info exists g_moduleResolved($modvers)]} { |
| 319 |
set g_moduleResolved($modvers) $modres |
| 320 |
reportDebug "$modvers resolved to $modres" |
| 321 |
lappend g_resolvedHash($modres) $modvers |
| 322 |
} |
| 323 |
} |
| 324 |
# as we change of module name a proper resolution call should be |
| 325 |
# made (see below) and will handle the rest of the resolution path |
| 326 |
} else { |
| 327 |
set need_set_res 1 |
| 328 |
break |
| 329 |
} |
| 330 |
} |
| 331 |
# when registering an alias, existing symbols on alias source name should |
| 332 |
# be broadcast along the resolution path with a proper resolution call |
| 333 |
# (see below) |
| 334 |
} else { |
| 335 |
lassign [getModuleNameVersion $target] modres modresname |
| 336 |
set need_set_res 1 |
| 337 |
} |
| 338 |
|
| 339 |
# resolution needed to broadcast symbols along resolution path without |
| 340 |
# altering initial path already set for these symbols |
| 341 |
if {[info exists need_set_res]} { |
| 342 |
foreach symelt $sym_list { |
| 343 |
set modvers $modresname/$symelt |
| 344 |
reportDebug "set resolution for $modvers" |
| 345 |
setModuleResolution $modvers $modres $symelt 0 |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
return 1 |
| 350 |
} |
| 351 |
|
| 352 |
# retrieve all names that resolve to passed mod |
| 353 |
proc getAllModuleResolvedName {mod {flag_type 0} {modspec {}} {filter_default\ |
| 354 |
0}} { |
| 355 |
set namelist {} |
| 356 |
set resmodlist {} |
| 357 |
set icase [isIcase] |
| 358 |
|
| 359 |
# get parent directories of mod |
| 360 |
foreach modelt [split $mod /] { |
| 361 |
if {[info exists modroot]} { |
| 362 |
append modroot / |
| 363 |
} |
| 364 |
append modroot $modelt |
| 365 |
lappend resmodlist $modroot |
| 366 |
} |
| 367 |
|
| 368 |
set modpar [file dirname $mod] |
| 369 |
set moddfl $modpar/default |
| 370 |
|
| 371 |
# add additionally all the altnames set on directories, parents of mod |
| 372 |
# or on distant directories whose default version resolves to mod |
| 373 |
for {set i 0} {$i < [llength $resmodlist]} {incr i 1} { |
| 374 |
set modelt [getArrayKey ::g_resolvedHash [lindex $resmodlist $i] $icase] |
| 375 |
if {[info exists ::g_resolvedHash($modelt)]} { |
| 376 |
foreach resmod $::g_resolvedHash($modelt) { |
| 377 |
# if alternative name corresponds to one root name test if default |
| 378 |
# symbol is hidden |
| 379 |
set resmoddfl [expr {[lsearch -exact $resmodlist $resmod] != -1 ?\ |
| 380 |
"$resmod/default" : {}}] |
| 381 |
# if alternative name corresponds to default symbol and is hidden |
| 382 |
# test if query matches bare module name |
| 383 |
set resmodpar [expr {[file tail $resmod] eq {default} ? [file\ |
| 384 |
dirname $resmod] : {}}] |
| 385 |
|
| 386 |
# if modelt is not a parent directory of mod, check its resolution |
| 387 |
# points to mod (directly for alias/sym or indirectly for dir |
| 388 |
# whose default version bridge resolution toward mod) |
| 389 |
# if modspec arg is set, exclude hidden entries not explicitly |
| 390 |
# matching modspec. auto symbols cannot be hidden |
| 391 |
# if filter_default is asked, skip parent module name and /default |
| 392 |
# symbol name from result list |
| 393 |
if {($modspec eq {} || ([info exists ::g_autoSymbol($resmod)] &&\ |
| 394 |
$::g_autoSymbol($resmod) eq $mod) || (![isModuleHidden $resmod\ |
| 395 |
$modspec] && ($resmoddfl eq {} || ![isModuleHidden $resmoddfl\ |
| 396 |
$modspec])) || [modEq $modspec $resmod eqspec] || ($resmodpar\ |
| 397 |
ne {} && [modEq $modspec $resmodpar eqspec])) && ([modEq\ |
| 398 |
$modelt $mod eqstart] || $::g_moduleResolved($resmod) eq $mod\ |
| 399 |
|| $mod eq [lindex [getPathToModule\ |
| 400 |
$::g_moduleResolved($resmod) {} 0] 1]) && (!$filter_default ||\ |
| 401 |
(![modEq $resmod $modpar] && ![modEq $resmod $moddfl]))} { |
| 402 |
# prefix automatically generated syms with type flag if asked |
| 403 |
if {$flag_type} { |
| 404 |
set name_entry [list] |
| 405 |
if {[info exists ::g_moduleAlias($resmod)]} { |
| 406 |
lappend name_entry al |
| 407 |
} elseif {[info exists ::g_autoSymbol($resmod)]} { |
| 408 |
lappend name_entry as |
| 409 |
} |
| 410 |
lappend name_entry $resmod |
| 411 |
} else { |
| 412 |
set name_entry $resmod |
| 413 |
} |
| 414 |
lappendNoDup namelist $name_entry |
| 415 |
|
| 416 |
unset modroot |
| 417 |
foreach reselt [split [file dirname $resmod] /] { |
| 418 |
if {[info exists modroot]} { |
| 419 |
append modroot / |
| 420 |
} |
| 421 |
append modroot $reselt |
| 422 |
lappendNoDup resmodlist $modroot |
| 423 |
} |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
return $namelist |
| 429 |
} |
| 430 |
|
| 431 |
# build list for a given loaded module of its alternative names plus its |
| 432 |
# simplified names (name minus version or any subdir if this version or subdir |
| 433 |
# are the implicit default for module) |
| 434 |
proc getLoadedAltAndSimplifiedName {mod} { |
| 435 |
if {[isModuleFullPath $mod]} { |
| 436 |
set namelist [list $mod] |
| 437 |
# use already computed name list if any |
| 438 |
} elseif {[info exists ::g_loadedAltAndSimplifiedName($mod)]} { |
| 439 |
set namelist $::g_loadedAltAndSimplifiedName($mod) |
| 440 |
} else { |
| 441 |
# get recorded alternative name |
| 442 |
set namelist [getLoadedAltname $mod] |
| 443 |
# also look through modpaths for simplified mod name |
| 444 |
set modpathlist [getModulePathList] |
| 445 |
if {[llength $modpathlist]} { |
| 446 |
set modfile [getModulefileFromLoadedModule $mod] |
| 447 |
set parentmod [file dirname $mod] |
| 448 |
# simplify to parent name as long as it resolves to current mod |
| 449 |
while {$parentmod ne {.}} { |
| 450 |
lassign [getPathToModule $parentmod $modpathlist 0] parentfile |
| 451 |
if {$parentfile eq $modfile} { |
| 452 |
lappend namelist $parentmod |
| 453 |
set parentmod [file dirname $parentmod] |
| 454 |
} else { |
| 455 |
set parentmod . |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
# recorded computed name list for later use |
| 460 |
set ::g_loadedAltAndSimplifiedName($mod) $namelist |
| 461 |
} |
| 462 |
return $namelist |
| 463 |
} |
| 464 |
|
| 465 |
# return value list of a loaded module property by parsing corresponding |
| 466 |
# environment variable |
| 467 |
proc getEnvLoadedModulePropertyParsedList {prop} { |
| 468 |
set unserialize_depth [getEnvLoadedModulePropertyStructDepth $prop] |
| 469 |
set unserialize_proc unserialize${unserialize_depth}ModulePropertyValueList |
| 470 |
set char_unmap_list [getEnvLoadedModulePropertyCharUnmapList $prop] |
| 471 |
|
| 472 |
set serialized_value_list [getEnvLoadedModulePropertyList $prop] |
| 473 |
set structured_value_list [$unserialize_proc $serialized_value_list\ |
| 474 |
$char_unmap_list] |
| 475 |
return $structured_value_list |
| 476 |
} |
| 477 |
|
| 478 |
proc getEnvLoadedModulePropertyList {prop} { |
| 479 |
set env_var_name [getLoadedModulePropertyEnvVarName $prop] |
| 480 |
return [split [get-env $env_var_name] [getState path_separator]] |
| 481 |
} |
| 482 |
|
| 483 |
proc getLoadedModulePropertyEnvVarName {prop} { |
| 484 |
switch -- $prop { |
| 485 |
name {set env_var_name LOADEDMODULES} |
| 486 |
file {set env_var_name _LMFILES_} |
| 487 |
modulepath {set env_var_name MODULEPATH} |
| 488 |
default {set env_var_name __MODULES_LM[string toupper $prop]} |
| 489 |
} |
| 490 |
return $env_var_name |
| 491 |
} |
| 492 |
|
| 493 |
# return list of module paths by parsing MODULEPATH env variable |
| 494 |
# behavior param enables to exit in error when no MODULEPATH env variable |
| 495 |
# is set. by default an empty list is returned if no MODULEPATH set |
| 496 |
# resolv_var param tells if environment variable references in path elements |
| 497 |
# should be resolved or passed as-is in result list |
| 498 |
proc getModulePathList {{behavior returnempty} {resolv_var 1}} { |
| 499 |
if {![isEnvVarDefined MODULEPATH] && $behavior eq {exiterronundef}} { |
| 500 |
reportErrorAndExit {No module path defined} |
| 501 |
} |
| 502 |
|
| 503 |
set modpath_list [list] |
| 504 |
foreach modpath [getEnvLoadedModulePropertyParsedList modulepath] { |
| 505 |
if {$resolv_var} { |
| 506 |
set modpath [resolvStringWithEnv $modpath] |
| 507 |
} |
| 508 |
# relative modulepath refers to current working directory of module |
| 509 |
# command, not to the directory of the modulefile being evaluated |
| 510 |
lappendNoDup modpath_list [getAbsolutePath $modpath 1] |
| 511 |
} |
| 512 |
return $modpath_list |
| 513 |
} |
| 514 |
|
| 515 |
# return the MODULEPATH entry, as registered in environment variable, that |
| 516 |
# corresponds to given path. path is resolved as an absolute path from the |
| 517 |
# directory of the modulefile being evaluated and from the current working |
| 518 |
# directory, as a relative MODULEPATH entry refers to the latter. an empty |
| 519 |
# string is returned if path is not found in MODULEPATH |
| 520 |
# resolv_var param tells if environment variable references in MODULEPATH |
| 521 |
# entries should be resolved or compared as-is |
| 522 |
proc getUsedModulePathEntry {path {resolv_var 1}} { |
| 523 |
set abspath [getAbsolutePath $path] |
| 524 |
set abspath_from_cwd [getAbsolutePath $path 1] |
| 525 |
foreach modpath [getEnvLoadedModulePropertyParsedList modulepath] { |
| 526 |
set absmodpath [expr {$resolv_var ? [resolvStringWithEnv $modpath] :\ |
| 527 |
$modpath}] |
| 528 |
set absmodpath [getAbsolutePath $absmodpath 1] |
| 529 |
if {$absmodpath eq $abspath || $absmodpath eq $abspath_from_cwd} { |
| 530 |
return $modpath |
| 531 |
} |
| 532 |
} |
| 533 |
return {} |
| 534 |
} |
| 535 |
|
| 536 |
proc getModulepathLabel {modpath} { |
| 537 |
if {[info exists ::g_modulepathLabel($modpath)]} { |
| 538 |
return $::g_modulepathLabel($modpath) |
| 539 |
} else { |
| 540 |
return $modpath |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
# return list of the configured and existing global RC files |
| 545 |
proc getGlobalRcFileList {} { |
| 546 |
set rclist {} |
| 547 |
|
| 548 |
set rcfilelist [getConfList rcfile] |
| 549 |
if {[llength $rcfilelist]} { |
| 550 |
foreach rcfile $rcfilelist { |
| 551 |
# if rcfile is a dir, look at a modulerc file in it |
| 552 |
if {[file isdirectory $rcfile] && [file isfile $rcfile/modulerc]} { |
| 553 |
lappend rclist $rcfile/modulerc |
| 554 |
} elseif {[file isfile $rcfile]} { |
| 555 |
lappend rclist $rcfile |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
if {[file isfile {@etcdir@/rc}]} { |
| 560 |
lappend rclist {@etcdir@/rc} |
| 561 |
} |
| 562 |
# ignore user rc if relative configuration is enabled |
| 563 |
if {![getConf ignore_user_rc] && [isEnvVarDefined HOME] && [file isfile\ |
| 564 |
$::env(HOME)/.modulerc]} { |
| 565 |
lappend rclist $::env(HOME)/.modulerc |
| 566 |
} |
| 567 |
|
| 568 |
set readable_rclist {} |
| 569 |
foreach rc $rclist { |
| 570 |
if {[file readable $rc]} { |
| 571 |
lappend readable_rclist $rc |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
return $readable_rclist |
| 576 |
} |
| 577 |
|
| 578 |
proc getModuleTag {mod full_path_mod tag} { |
| 579 |
# check if tag is set on full path module designation (no prop there) |
| 580 |
lassign [getFullPathModuleTagSpec $full_path_mod $tag] tag_mod_spec\ |
| 581 |
tag_props |
| 582 |
if {[string length $tag_mod_spec]} { |
| 583 |
return [list $tag $tag_props] |
| 584 |
} |
| 585 |
# look if mod matches one of the module specs applying to mod root |
| 586 |
foreach {tmodspec tag_props} [getModuleRootTagSpecList $mod $tag] { |
| 587 |
# first matching module spec wins with its properties |
| 588 |
if {[modEq $tmodspec $mod eqstart 1 0 1]} { |
| 589 |
return [list $tag $tag_props] |
| 590 |
} |
| 591 |
} |
| 592 |
return {} |
| 593 |
} |
| 594 |
|
| 595 |
proc getModuleTagRuleList {mod full_path_mod tag} { |
| 596 |
set rule_list {} |
| 597 |
lassign [getFullPathModuleTagSpec $full_path_mod $tag] tag_mod_spec\ |
| 598 |
tag_props |
| 599 |
if {[string length $tag_mod_spec]} { |
| 600 |
lappend rule_list $tag_mod_spec |
| 601 |
} |
| 602 |
foreach {tag_mod_spec tag_props} [getModuleRootTagSpecList $mod $tag] { |
| 603 |
if {$tag_mod_spec ni $rule_list && [modEq $tag_mod_spec $mod eqstart 1\ |
| 604 |
0 1]} { |
| 605 |
lappend rule_list $tag_mod_spec |
| 606 |
} |
| 607 |
} |
| 608 |
return $rule_list |
| 609 |
} |
| 610 |
|
| 611 |
proc getModuleRootTagSpecList {mod tag} { |
| 612 |
set tag_spec_list {} |
| 613 |
set mod_root [getModuleRootFromVersSpec $mod] |
| 614 |
if {[info exists ::g_moduleTagRoot($mod_root)]} { |
| 615 |
set idx [lsearch -exact $::g_moduleTagRoot($mod_root) $tag] |
| 616 |
set tag_spec_list [lindex $::g_moduleTagRootSpec($mod_root) $idx] |
| 617 |
} |
| 618 |
return $tag_spec_list |
| 619 |
} |
| 620 |
|
| 621 |
proc getFullPathModuleTagSpec {full_path_mod tag} { |
| 622 |
set tag_spec {} |
| 623 |
if {$full_path_mod ne {} && [info exists\ |
| 624 |
::g_moduleTagFullPath($full_path_mod)]} { |
| 625 |
set idx [lsearch -exact $::g_moduleTagFullPath($full_path_mod) $tag] |
| 626 |
if {$idx != -1} { |
| 627 |
set tag_spec [list $full_path_mod [lindex\ |
| 628 |
$::g_moduleTagFullPathSpec($full_path_mod) $idx]] |
| 629 |
} |
| 630 |
} |
| 631 |
return $tag_spec |
| 632 |
} |
| 633 |
|
| 634 |
proc isModuleTagged {mod tag {collected 0} {fpmod {}}} { |
| 635 |
# retrieve tag information from collected tags or raw info |
| 636 |
if {$collected} { |
| 637 |
return [expr {$tag in [getTagList $mod $fpmod]}] |
| 638 |
} else { |
| 639 |
return [llength [getModuleTag $mod $fpmod $tag]] |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
proc getTaggedLoadedModuleList {tag} { |
| 644 |
set modlist [list] |
| 645 |
foreach mod [getEnvLoadedModulePropertyParsedList name] { |
| 646 |
if {[isModuleTagged $mod $tag 1]} { |
| 647 |
lappend modlist $mod |
| 648 |
} |
| 649 |
} |
| 650 |
return $modlist |
| 651 |
} |
| 652 |
|
| 653 |
proc getModuleTagProp {mod fpmod tag prop} { |
| 654 |
array set tags [getModuleTag $mod $fpmod $tag] |
| 655 |
|
| 656 |
if {[info exists tags($tag)]} { |
| 657 |
array set props $tags($tag) |
| 658 |
if {[info exists props($prop)]} { |
| 659 |
return $props($prop) |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
# Gather all tags applying to a given module |
| 665 |
proc collectModuleTags {mod} { |
| 666 |
if {[info exists ::g_tagHash($mod)]} { |
| 667 |
set known_tag_list $::g_tagHash($mod) |
| 668 |
} else { |
| 669 |
set known_tag_list {} |
| 670 |
} |
| 671 |
set tag_list [getMatchingTagList $mod $known_tag_list] |
| 672 |
if {[llength $tag_list]} { |
| 673 |
setModuleTag $mod {*}$tag_list |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
proc getMatchingTagList {mod {known_tag_list {}}} { |
| 678 |
set tag_list {} |
| 679 |
set modroot [getModuleRootFromVersSpec $mod] |
| 680 |
# look if mod matches one of the module specs applying to mod root |
| 681 |
if {[info exists ::g_moduleTagRoot($modroot)]} { |
| 682 |
for {set i 0} {$i < [llength $::g_moduleTagRoot($modroot)]} {incr i} { |
| 683 |
set tag [lindex $::g_moduleTagRoot($modroot) $i] |
| 684 |
if {$tag ni $tag_list} { |
| 685 |
foreach {tmodspec tprops} [lindex\ |
| 686 |
$::g_moduleTagRootSpec($modroot) $i] { |
| 687 |
# add tag if one modspec matches mod |
| 688 |
if {[modEq $tmodspec $mod eqstart 1 0 1]} { |
| 689 |
lappend known_tag_list $tag |
| 690 |
lappend tag_list $tag |
| 691 |
break |
| 692 |
} |
| 693 |
} |
| 694 |
} |
| 695 |
} |
| 696 |
} |
| 697 |
return $tag_list |
| 698 |
} |
| 699 |
|
| 700 |
proc setModuleTag {mod args} { |
| 701 |
lappendNoDup ::g_tagHash($mod) {*}$args |
| 702 |
} |
| 703 |
|
| 704 |
proc setModuleAndVariantsTag {mod mod_with_vr args} { |
| 705 |
setModuleTag $mod {*}$args |
| 706 |
if {$mod_with_vr ne {} && $mod ne $mod_with_vr} { |
| 707 |
setModuleTag $mod_with_vr {*}$args |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
proc setModuleExtraTag {mod args} { |
| 712 |
lappendNoDup ::g_extraTagHash($mod) {*}$args |
| 713 |
} |
| 714 |
|
| 715 |
proc setModuleAndVariantsExtraTag {mod mod_with_vr args} { |
| 716 |
setModuleExtraTag $mod {*}$args |
| 717 |
if {$mod_with_vr ne {} && $mod ne $mod_with_vr} { |
| 718 |
setModuleExtraTag $mod_with_vr {*}$args |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
proc unsetModuleTag {mod args} { |
| 723 |
if {[info exists ::g_tagHash($mod)]} { |
| 724 |
lassign [getDiffBetweenList $::g_tagHash($mod) $args] diff_list |
| 725 |
if {[llength $args] && [llength $diff_list]} { |
| 726 |
set ::g_tagHash($mod) $diff_list |
| 727 |
} else { |
| 728 |
unset ::g_tagHash($mod) |
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
proc unsetModuleAndVariantsTag {mod mod_with_vr args} { |
| 734 |
unsetModuleTag $mod {*}$args |
| 735 |
if {$mod_with_vr ne {} && $mod ne $mod_with_vr} { |
| 736 |
unsetModuleTag $mod_with_vr {*}$args |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
proc unsetModuleExtraTag {mod args} { |
| 741 |
if {[info exists ::g_extraTagHash($mod)]} { |
| 742 |
lassign [getDiffBetweenList $::g_extraTagHash($mod) $args] diff_list |
| 743 |
if {[llength $args] && [llength $diff_list]} { |
| 744 |
set ::g_extraTagHash($mod) $diff_list |
| 745 |
} else { |
| 746 |
unset ::g_extraTagHash($mod) |
| 747 |
} |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
proc unsetModuleAndVariantsExtraTag {mod mod_with_vr args} { |
| 752 |
unsetModuleExtraTag $mod {*}$args |
| 753 |
if {$mod_with_vr ne {} && $mod ne $mod_with_vr} { |
| 754 |
unsetModuleExtraTag $mod_with_vr {*}$args |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
proc getTagList {mod {fpmod {}} {sort 1}} { |
| 759 |
set tag_list {} |
| 760 |
# get tags applied over module full path designation |
| 761 |
if {$fpmod ne {} && [info exists ::g_moduleTagFullPath($fpmod)]} { |
| 762 |
lappendNoDup tag_list {*}$::g_moduleTagFullPath($fpmod) |
| 763 |
} |
| 764 |
# recompute tags applying from module specification if mod is loaded but |
| 765 |
# not the same modulefile. tags applying to loaded mod are recorded in |
| 766 |
# g_tagHash but should not apply to same mod from a different modulepath |
| 767 |
# do not make this distinction if modulefile is not provided |
| 768 |
# directly check on g_loadedModules array to avoid triggering env check |
| 769 |
if {[string length $fpmod] && [info exists ::g_loadedModules($mod)] &&\ |
| 770 |
$fpmod ne [getModulefileFromLoadedModule $mod]} { |
| 771 |
lappendNoDup tag_list {*}[getMatchingTagList $mod] |
| 772 |
# get collected tags applied on short designation |
| 773 |
} elseif {[info exists ::g_tagHash($mod)]} { |
| 774 |
lappendNoDup tag_list {*}$::g_tagHash($mod) |
| 775 |
} |
| 776 |
if {[llength $tag_list]} { |
| 777 |
if {$sort} { |
| 778 |
set tag_list [lsort -dictionary $tag_list] |
| 779 |
} |
| 780 |
reportDebug "'$mod' has tag list '$tag_list'" |
| 781 |
} |
| 782 |
return $tag_list |
| 783 |
} |
| 784 |
|
| 785 |
# return tags applying to mod that can be exported |
| 786 |
proc getExportTagList {mod {fpmod {}}} { |
| 787 |
# remove loaded, hidden and user-defined non exportable tags from the list |
| 788 |
# to register |
| 789 |
lassign [getDiffBetweenList [getTagList $mod $fpmod 0] [list loaded\ |
| 790 |
hidden {*}[getConfList non_exportable_tags]]] ret |
| 791 |
return $ret |
| 792 |
} |
| 793 |
|
| 794 |
# return extra tags set on mod |
| 795 |
proc getExtraTagList {mod} { |
| 796 |
if {[info exists ::g_extraTagHash($mod)]} { |
| 797 |
return $::g_extraTagHash($mod) |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
# return rule definition of sticky/super-sticky tag on given module |
| 802 |
proc getStickyRuleList {mod {fpmod {}}} { |
| 803 |
set ret {} |
| 804 |
foreach tag {sticky super-sticky} { |
| 805 |
if {[isModuleTagged $mod $tag 1]} { |
| 806 |
set export_sticky_rule 1 |
| 807 |
set tag_rule_list [getModuleTagRuleList $mod $fpmod $tag] |
| 808 |
|
| 809 |
# skip rule export if one matches module name and version or full |
| 810 |
# path designation |
| 811 |
foreach tag_rule $tag_rule_list { |
| 812 |
if {[modEq $tag_rule $mod equal 1 0 1] || [modEq $tag_rule $fpmod\ |
| 813 |
equal 1 0 1]} { |
| 814 |
set export_sticky_rule 0 |
| 815 |
break |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
if {[llength $tag_rule_list] && $export_sticky_rule} { |
| 820 |
lappend ret [list $tag {*}$tag_rule_list] |
| 821 |
} |
| 822 |
} |
| 823 |
} |
| 824 |
return $ret |
| 825 |
} |
| 826 |
|
| 827 |
# return tags set on mod to record in collection |
| 828 |
proc getSaveTagList {mod} { |
| 829 |
# return all tags if pin tag is enabled, except nearly-forbidden that is |
| 830 |
# not intended for save |
| 831 |
if {[getConf collection_pin_tag]} { |
| 832 |
lassign [getDiffBetweenList [getExportTagList $mod] [list\ |
| 833 |
nearly-forbidden]] ret |
| 834 |
} else { |
| 835 |
set ret [getExtraTagList $mod] |
| 836 |
# in addition to those set with --tag option, add tags obtained by the |
| 837 |
# way mod has been loaded |
| 838 |
if {[isModuleTagged $mod auto-loaded 1]} { |
| 839 |
lappend ret auto-loaded |
| 840 |
} |
| 841 |
if {[isModuleTagged $mod keep-loaded 1]} { |
| 842 |
lappend ret keep-loaded |
| 843 |
} |
| 844 |
} |
| 845 |
return $ret |
| 846 |
} |
| 847 |
|
| 848 |
proc abbrevTagList {taglist} { |
| 849 |
set ret [list] |
| 850 |
foreach tag $taglist { |
| 851 |
if {[info exists ::g_tagAbbrev($tag)]} { |
| 852 |
# empty string abbrev means no tag report |
| 853 |
if {$::g_tagAbbrev($tag) ne {}} { |
| 854 |
lappend ret $::g_tagAbbrev($tag) |
| 855 |
} |
| 856 |
} else { |
| 857 |
lappend ret $tag |
| 858 |
} |
| 859 |
} |
| 860 |
return [lsort -dictionary $ret] |
| 861 |
} |
| 862 |
|
| 863 |
proc getTagFromAbbrev {abbrev} { |
| 864 |
if {![array exists ::g_abbrevTag]} { |
| 865 |
getConf tag_abbrev |
| 866 |
} |
| 867 |
if {[info exists ::g_abbrevTag($abbrev)]} { |
| 868 |
return $::g_abbrevTag($abbrev) |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
proc getVariantList {mod {report 0} {excl_dflval 0} {from 0}} { |
| 873 |
set vrspeclist {} |
| 874 |
set loadedsgrkey {} |
| 875 |
# fetch variant information from |
| 876 |
switch -- $from { |
| 877 |
0 { |
| 878 |
# variant set after module being loaded |
| 879 |
if {[info exists ::g_loadedModuleVariant($mod)]} { |
| 880 |
set vrspeclist $::g_loadedModuleVariant($mod) |
| 881 |
} |
| 882 |
} |
| 883 |
1 { |
| 884 |
# module specification |
| 885 |
set vrspeclist {} |
| 886 |
foreach vrspec [getVariantListFromVersSpec $mod] { |
| 887 |
lassign $vrspec vrname vrnot vrvalisbool vrvalue |
| 888 |
lappend vrspeclist [list $vrname $vrvalue $vrvalisbool] |
| 889 |
} |
| 890 |
} |
| 891 |
2 { |
| 892 |
# variant definition collected during scan evaluation |
| 893 |
if {[info exists ::g_scanModuleVariant($mod)]} { |
| 894 |
set vrspeclist $::g_scanModuleVariant($mod) |
| 895 |
} |
| 896 |
# if module is currently loaded, gather its variant values |
| 897 |
if {[info exists ::g_loadedModuleVariant($mod)]} { |
| 898 |
foreach lovrspec $::g_loadedModuleVariant($mod) { |
| 899 |
lassign $lovrspec lovrname lovrvalue lovrvalisbool lovrvalisdfl |
| 900 |
if {$lovrvalisbool} { |
| 901 |
set lovrvalue [expr {$lovrvalue ? {on} : {off}}] |
| 902 |
} |
| 903 |
set lovrarr($lovrname) $lovrvalue |
| 904 |
} |
| 905 |
# get sgr key corresponding to loaded tag (if tag reported) |
| 906 |
if {$report == 7 && [isEltInReport tag]} { |
| 907 |
set loadedkind [expr {[isModuleTagged $mod auto-loaded 1] ?\ |
| 908 |
{auto-loaded} : {loaded}}] |
| 909 |
lassign [abbrevTagList [list $loadedkind]] loadedsgrkey |
| 910 |
} |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
# use array to make variant unique |
| 916 |
foreach vrspec $vrspeclist { |
| 917 |
if {$from == 2} { |
| 918 |
# report all available variant values on avail |
| 919 |
lassign $vrspec vrname vrvalues vrdefdflval vrdflval |
| 920 |
set vrvalisbool 0 |
| 921 |
set vrvalisdfl 0 |
| 922 |
# build value list to output for free-variant value |
| 923 |
if {![llength $vrvalues]} { |
| 924 |
# if module is loaded, add loaded variant value |
| 925 |
if {[info exists lovrarr($vrname)]} { |
| 926 |
lappend vrvalues $lovrarr($vrname) |
| 927 |
} |
| 928 |
# if a default value is defined, add it to possible value list |
| 929 |
if {$vrdefdflval && $vrdflval ni $vrvalues} { |
| 930 |
lappend vrvalues $vrdflval |
| 931 |
} |
| 932 |
# indicate on free-value variant that all values are possible |
| 933 |
lappend vrvalues * |
| 934 |
} |
| 935 |
} else { |
| 936 |
lassign $vrspec vrname vrvalue vrvalisbool vrvalisdfl |
| 937 |
set vrvalues [list $vrvalue] |
| 938 |
} |
| 939 |
# correct is-default value if invalid |
| 940 |
if {![string is integer -strict $vrvalisdfl]} { |
| 941 |
set vrvalisdfl 0 |
| 942 |
} |
| 943 |
# correct is-boolean value if invalid |
| 944 |
if {![string is boolean -strict $vrvalisbool]} { |
| 945 |
set vrvalisbool 0 |
| 946 |
} |
| 947 |
set vrisbool($vrname) $vrvalisbool |
| 948 |
# correct boolean value if invalid |
| 949 |
if {$vrvalisbool && ![string is boolean -strict $vrvalue]} { |
| 950 |
set vrvalue 0 |
| 951 |
} |
| 952 |
# do not return variant if value is default, unless if variant was |
| 953 |
# specifically set to default value (isdfl=1) and we only want to |
| 954 |
# exclude the automatically set default value (excl_dflval=2) |
| 955 |
if {$excl_dflval > 0} { |
| 956 |
if {$vrvalisdfl == 0 || ($excl_dflval == 2 && $vrvalisdfl == 1)} { |
| 957 |
set vrarr($vrname) $vrvalue |
| 958 |
# nullify previous duplicate definition if this one is default |
| 959 |
} elseif {[info exists vrarr($vrname)]} { |
| 960 |
unset vrarr($vrname) |
| 961 |
} |
| 962 |
} else { |
| 963 |
if {$report == 7} { |
| 964 |
# indicate what value in the list is the default one |
| 965 |
if {[info exists vrdefdflval]} { |
| 966 |
set vrdflidxarr($vrname) [expr {$vrdefdflval ? [lsearch -exact\ |
| 967 |
$vrvalues $vrdflval] : {-1}}] |
| 968 |
} else { |
| 969 |
set vrdflidxarr($vrname) [expr {$vrvalisdfl ? {0} : {-1}}] |
| 970 |
} |
| 971 |
# indicate what value in the list is the loaded one |
| 972 |
set vrloidxarr($vrname) [expr {[info exists lovrarr($vrname)] ?\ |
| 973 |
[lsearch -exact $vrvalues $lovrarr($vrname)] : {-1}}] |
| 974 |
if {$vrvalisbool} { |
| 975 |
set vrarr($vrname) $vrvalue |
| 976 |
} else { |
| 977 |
set vrarr($vrname) $vrvalues |
| 978 |
} |
| 979 |
# is-default hint has to be transmitted on report mode '3' |
| 980 |
} elseif {$report == 3} { |
| 981 |
set vrarr($vrname) [list $vrvalue [expr {$vrvalisdfl > 0 &&\ |
| 982 |
$vrvalisdfl < 3}]] |
| 983 |
} else { |
| 984 |
set vrarr($vrname) $vrvalue |
| 985 |
} |
| 986 |
} |
| 987 |
} |
| 988 |
# sort variant to report |
| 989 |
set ret {} |
| 990 |
foreach vrname [lsort -dictionary [array names vrarr]] { |
| 991 |
switch -- $report { |
| 992 |
4 {lappend ret $vrname $vrarr($vrname) $vrisbool($vrname)} |
| 993 |
3 {lappend ret $vrname [lindex $vrarr($vrname) 0] [lindex\ |
| 994 |
$vrarr($vrname) 1]} |
| 995 |
2 {lappend ret [list $vrname 0 $vrisbool($vrname) $vrarr($vrname)]} |
| 996 |
1 - 5 - 6 { |
| 997 |
if {$vrisbool($vrname)} { |
| 998 |
if {$vrarr($vrname)} { |
| 999 |
lappend ret +$vrname |
| 1000 |
# track if +var variant has been reported to build key |
| 1001 |
# unless if key should not be updated (report mode '6') |
| 1002 |
if {$report != 6 && ![info exists ::g_used_va(on)]} { |
| 1003 |
set ::g_used_va(on) 1 |
| 1004 |
} |
| 1005 |
} else { |
| 1006 |
lappend ret -$vrname |
| 1007 |
# track if -var variant has been reported to build key |
| 1008 |
# unless if key should not be updated (report mode '6') |
| 1009 |
if {$report != 6 && ![info exists ::g_used_va(off)]} { |
| 1010 |
set ::g_used_va(off) 1 |
| 1011 |
} |
| 1012 |
} |
| 1013 |
# use defined shortcut to report if any set for this variant |
| 1014 |
# ignore shortcut if report=5 (when saving collection) |
| 1015 |
} elseif {$report != 5 && [info exists\ |
| 1016 |
::g_variantShortcut($vrname)]} { |
| 1017 |
set sc $::g_variantShortcut($vrname) |
| 1018 |
lappend ret $sc$vrarr($vrname) |
| 1019 |
# track if variant shortcut has been reported to build key |
| 1020 |
# unless if key should not be updated (report mode '6') |
| 1021 |
if {$report != 6 && ![info exists ::g_used_va($sc)]} { |
| 1022 |
set ::g_used_va($sc) $vrname |
| 1023 |
} |
| 1024 |
} else { |
| 1025 |
lappend ret $vrname=$vrarr($vrname) |
| 1026 |
# track if var=val variant has been reported to build key |
| 1027 |
# unless if key should not be updated (report mode '6') |
| 1028 |
if {$report != 6 && ![info exists ::g_used_va(val)]} { |
| 1029 |
set ::g_used_va(val) 1 |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
7 { |
| 1034 |
if {$vrisbool($vrname)} { |
| 1035 |
if {$vrarr($vrname)} { |
| 1036 |
lappend ret [list $vrname {} [list +$vrname]\ |
| 1037 |
$vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] |
| 1038 |
# track if +var variant has been reported to build key |
| 1039 |
if {![info exists ::g_used_va(on)]} { |
| 1040 |
set ::g_used_va(on) 1 |
| 1041 |
} |
| 1042 |
} else { |
| 1043 |
lappend ret [list $vrname {} [list -$vrname]\ |
| 1044 |
$vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] |
| 1045 |
# track if -var variant has been reported to build key |
| 1046 |
if {![info exists ::g_used_va(off)]} { |
| 1047 |
set ::g_used_va(off) 1 |
| 1048 |
} |
| 1049 |
} |
| 1050 |
# use defined shortcut to report if any set for this variant |
| 1051 |
# ignore shortcut if report=5 (when saving collection) |
| 1052 |
} elseif {$report != 5 && [info exists\ |
| 1053 |
::g_variantShortcut($vrname)]} { |
| 1054 |
set sc $::g_variantShortcut($vrname) |
| 1055 |
lappend ret [list $vrname $sc $vrarr($vrname)\ |
| 1056 |
$vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] |
| 1057 |
# track if variant shortcut has been reported to build key |
| 1058 |
# unless if key should not be updated (report mode '6') |
| 1059 |
if {$report != 6 && ![info exists ::g_used_va($sc)]} { |
| 1060 |
set ::g_used_va($sc) $vrname |
| 1061 |
} |
| 1062 |
} else { |
| 1063 |
lappend ret [list $vrname $vrname= $vrarr($vrname)\ |
| 1064 |
$vrdflidxarr($vrname) $vrloidxarr($vrname) $loadedsgrkey] |
| 1065 |
# track if var=val variant has been reported to build key |
| 1066 |
# unless if key should not be updated (report mode '6') |
| 1067 |
if {$report != 6 && ![info exists ::g_used_va(val)]} { |
| 1068 |
set ::g_used_va(val) 1 |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
0 {lappend ret $vrname $vrarr($vrname)} |
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
return $ret |
| 1077 |
} |
| 1078 |
|
| 1079 |
proc isOtherVariantOfModuleLoading {mod} { |
| 1080 |
set mod_name [getModuleNameAndVersFromVersSpec $mod] |
| 1081 |
set mod_has_variant [expr {$mod ne $mod_name}] |
| 1082 |
|
| 1083 |
return [expr {$mod_has_variant && [isModuleLoading $mod_name] && ![string\ |
| 1084 |
length [getLoadedMatchingName $mod {} 1]]}] |
| 1085 |
} |
| 1086 |
|
| 1087 |
proc isOtherVariantOfModuleLoaded {mod} { |
| 1088 |
set mod_name [getModuleNameAndVersFromVersSpec $mod] |
| 1089 |
set mod_has_variant [expr {$mod ne $mod_name}] |
| 1090 |
|
| 1091 |
return [expr {$mod_has_variant && [isModuleLoaded $mod_name] && ![string\ |
| 1092 |
length [getLoadedMatchingName $mod]]}] |
| 1093 |
} |
| 1094 |
|
| 1095 |
proc isModuleDotHidden {mod} { |
| 1096 |
foreach elt [split $mod /] { |
| 1097 |
if {[string index $elt 0] eq {.}} { |
| 1098 |
return 1 |
| 1099 |
} |
| 1100 |
} |
| 1101 |
return 0 |
| 1102 |
} |
| 1103 |
|
| 1104 |
proc getModuleHidingLevel {mod fpmod} { |
| 1105 |
# if full path module has been hidden, this hidden level is the base level |
| 1106 |
# value we will return |
| 1107 |
set baselvl [expr {$fpmod ne {} && [info exists\ |
| 1108 |
::g_moduleHideFullPath($fpmod)] ? $::g_moduleHideFullPath($fpmod) :\ |
| 1109 |
{-1}}] |
| 1110 |
|
| 1111 |
set modroot [lindex [file split $mod] 0] |
| 1112 |
# look if mod matches one of the hidden module specs applying to mod root |
| 1113 |
if {[info exists ::g_moduleHideRoot($modroot)]} { |
| 1114 |
for {set lvl 2} {$lvl > -1} {incr lvl -1} { |
| 1115 |
# no need to search anymore if we have reached same hiding level as |
| 1116 |
# one defined on full path module designation |
| 1117 |
if {$lvl == $baselvl} { |
| 1118 |
break |
| 1119 |
} |
| 1120 |
foreach hmodspec [lindex $::g_moduleHideRoot($modroot) $lvl] { |
| 1121 |
if {[modEq $hmodspec $mod eqstart 1 0 1 {}]} { |
| 1122 |
return $lvl |
| 1123 |
} |
| 1124 |
} |
| 1125 |
} |
| 1126 |
} |
| 1127 |
return $baselvl |
| 1128 |
} |
| 1129 |
|
| 1130 |
proc setModspecHidingLevel {modspec lvl} { |
| 1131 |
# skip record if an higher hiding level is already set |
| 1132 |
if {![info exists ::g_moduleHide($modspec)] || $lvl >\ |
| 1133 |
$::g_moduleHide($modspec)} { |
| 1134 |
reportDebug "Record hidden module specification '$modspec' (lvl=$lvl)" |
| 1135 |
set ::g_moduleHide($modspec) $lvl |
| 1136 |
|
| 1137 |
if {[isModuleFullPath $modspec]} { |
| 1138 |
set ::g_moduleHideFullPath($modspec) $lvl |
| 1139 |
} else { |
| 1140 |
# record hidden mod spec for mod root to optimize search |
| 1141 |
set modroot [getModuleRootFromVersSpec $modspec] |
| 1142 |
if {![info exists ::g_moduleHideRoot($modroot)]} { |
| 1143 |
set ::g_moduleHideRoot($modroot) [list [list] [list] [list]] |
| 1144 |
} |
| 1145 |
# record in list corresponding to hidden level to search from |
| 1146 |
# strongest to weakest hidden level |
| 1147 |
set hiderootlvllist [lindex $::g_moduleHideRoot($modroot) $lvl] |
| 1148 |
lappend hiderootlvllist $modspec |
| 1149 |
lset ::g_moduleHideRoot($modroot) $lvl $hiderootlvllist |
| 1150 |
} |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
# test if mod is declared hidden or has one element in its name starting with |
| 1155 |
# dot character. mod is considered hidden depending on their hiding level, |
| 1156 |
# current search query and hiding threshold. when retdetails option is |
| 1157 |
# enabled, mod hiding level and query match hind are also returned |
| 1158 |
# also checks full path module designation if fpmod is set |
| 1159 |
proc isModuleHidden {mod {modspec {}} {retdetails 0} {fpmod {}}} { |
| 1160 |
set defhidlvl [set hidlvl [getModuleHidingLevel $mod $fpmod]] |
| 1161 |
if {$hidlvl >= [getState hiding_threshold]} { |
| 1162 |
# soft hidden mods are considered matched if their root name matches |
| 1163 |
# search query, other kind of hidden mods must fully matches query |
| 1164 |
set hidmatch [expr {$hidlvl == 0 ? [modStartNb $mod $modspec] > 0 :\ |
| 1165 |
[modEq $modspec $mod eqspec]}] |
| 1166 |
} else { |
| 1167 |
set hidlvl -1 |
| 1168 |
set hidmatch 0 |
| 1169 |
} |
| 1170 |
if {$hidlvl < 1 && [set isdot [isModuleDotHidden $mod]] && [getState\ |
| 1171 |
hiding_threshold] < 1} { |
| 1172 |
set hidlvl 1 |
| 1173 |
# dot hidden are considered matched if remaining string part after |
| 1174 |
# search query is not dot hidden |
| 1175 |
set hidmatch [expr {[set i [modStartNb $mod $modspec]] > 0 &&\ |
| 1176 |
![isModuleDotHidden [join [lrange [file split $mod] $i end] /]]}] |
| 1177 |
} |
| 1178 |
# hidden if hiding level greater or equal hiding threshold and not |
| 1179 |
# matched or if matched hard hiding level are kept hidden |
| 1180 |
set ishid [expr {$hidlvl != -1 && (!$hidmatch || $hidlvl > 1)}] |
| 1181 |
|
| 1182 |
# is module hidden by definition (whatever hiding threshold or match) |
| 1183 |
set hidbydef [expr {$defhidlvl > 0 || ([info exists isdot] && $isdot)}] |
| 1184 |
|
| 1185 |
return [expr {$retdetails ? [list $hidlvl $hidmatch $hidbydef $ishid]\ |
| 1186 |
: $ishid}] |
| 1187 |
} |
| 1188 |
|
| 1189 |
# check if module name is specified as a full pathname (not a name relative |
| 1190 |
# to a modulepath) |
| 1191 |
proc isModuleFullPath {mod} { |
| 1192 |
return [regexp {^(|\.|\.\.)/} $mod] |
| 1193 |
} |
| 1194 |
|
| 1195 |
# check if a module corresponds to a virtual module (module name |
| 1196 |
# does not corresponds to end of the modulefile name) |
| 1197 |
proc isModuleVirtual {mod modfile} { |
| 1198 |
return [expr {[string first $mod $modfile end-[string length $mod]] == -1}] |
| 1199 |
} |
| 1200 |
|
| 1201 |
# Return the full pathname and modulename to the module. |
| 1202 |
# Resolve aliases and default versions if the module name is something like |
| 1203 |
# "name/version" or just "name" (find default version). |
| 1204 |
proc getPathToModule {mod {indir {}} {report_issue 1} {look_loaded no}\ |
| 1205 |
{excdir {}}} { |
| 1206 |
reportDebug "finding '$mod' in '$indir' (report_issue=$report_issue,\ |
| 1207 |
look_loaded=$look_loaded, excdir='$excdir')" |
| 1208 |
|
| 1209 |
set vrlist [getVariantList $mod 1 0 1] |
| 1210 |
if {$mod eq {}} { |
| 1211 |
set retlist [list {} {} {} none [getEmptyNameMsg module]] |
| 1212 |
# try first to look at loaded modules if enabled to find matching module |
| 1213 |
# or to find a closest match (used when switching with single name arg) |
| 1214 |
} elseif {$look_loaded ne {no}} { |
| 1215 |
switch -- $look_loaded { |
| 1216 |
exact {set getLoadedNameProc getLoadedExactName} |
| 1217 |
match {set getLoadedNameProc getLoadedEqstartName} |
| 1218 |
close {set getLoadedNameProc getLoadedWithClosestName} |
| 1219 |
} |
| 1220 |
if {[set lm [$getLoadedNameProc $mod $indir]] ne {}} { |
| 1221 |
set vrlist [getVariantList $lm 1] |
| 1222 |
set retlist [list [getModulefileFromLoadedModule $lm] $lm] |
| 1223 |
} else { |
| 1224 |
set retlist [list {} [getModuleNameAndVersFromVersSpec $mod]\ |
| 1225 |
$mod notloaded] |
| 1226 |
} |
| 1227 |
# Check for $mod specified as a full pathname |
| 1228 |
} elseif {[isModuleFullPath $mod]} { |
| 1229 |
set mod [getAbsolutePath $mod] |
| 1230 |
# note that a raw filename as an argument returns the full |
| 1231 |
# path as the module name |
| 1232 |
lassign [checkValidModule $mod] check_valid check_msg |
| 1233 |
switch -- $check_valid { |
| 1234 |
true { |
| 1235 |
set retlist [list $mod $mod] |
| 1236 |
} |
| 1237 |
invalid - accesserr { |
| 1238 |
set retlist [list {} $mod $mod $check_valid $check_msg $mod] |
| 1239 |
} |
| 1240 |
} |
| 1241 |
} else { |
| 1242 |
set dir_list [expr {$indir ne {} ? $indir : [getModulePathList\ |
| 1243 |
exiterronundef]}] |
| 1244 |
# remove excluded directories (already searched) |
| 1245 |
foreach dir $excdir { |
| 1246 |
lrem dir_list $dir |
| 1247 |
} |
| 1248 |
|
| 1249 |
set icase [isIcase] |
| 1250 |
|
| 1251 |
# Now search for $mod in module paths |
| 1252 |
set modspec $mod |
| 1253 |
foreach dir $dir_list { |
| 1254 |
# get list of modules corresponding to searched query |
| 1255 |
array unset mod_list |
| 1256 |
array set mod_list [getModules $dir $mod 0 [list rc_defs_included\ |
| 1257 |
resolve]] |
| 1258 |
|
| 1259 |
set prevmod {} |
| 1260 |
set mod_res {} |
| 1261 |
# loop to resolve correct modulefile in case specified mod is a |
| 1262 |
# directory that should be analyzed to get default mod in it |
| 1263 |
while {$prevmod ne $mod} { |
| 1264 |
##nagelfar ignore Found constant |
| 1265 |
set mod [getEqArrayKey mod_list $mod] |
| 1266 |
set prevmod $mod |
| 1267 |
if {[info exists mod_list($mod)]} { |
| 1268 |
switch -- [lindex $mod_list($mod) 0] { |
| 1269 |
alias - version { |
| 1270 |
set newmod [resolveModuleVersionOrAlias $mod $icase] |
| 1271 |
if {[info exists mod_list($newmod)]} { |
| 1272 |
set mod $newmod |
| 1273 |
} else { |
| 1274 |
# add specified variants to current resolution |
| 1275 |
set newmod [getAndParseModuleWithVariant $newmod\ |
| 1276 |
$vrlist] |
| 1277 |
# restart search on new modulename, constrained to |
| 1278 |
# specified dir if set, if not found in current res |
| 1279 |
return [getPathToModule $newmod $indir $report_issue] |
| 1280 |
} |
| 1281 |
} |
| 1282 |
directory { |
| 1283 |
# is implicit default disabled and none explicitly set? |
| 1284 |
if {[lindex $mod_list($mod) 1] eq {}} { |
| 1285 |
set retlist [list {} $mod $mod none "No default\ |
| 1286 |
version defined for '$mod'"] |
| 1287 |
} else { |
| 1288 |
# Move to default element in directory |
| 1289 |
set mod $mod/[lindex $mod_list($mod) 1] |
| 1290 |
# restart search if default element is an hidden dir |
| 1291 |
if {![info exists mod_list($mod)] && [isModuleHidden\ |
| 1292 |
$mod $modspec 0 $dir/$mod]} { |
| 1293 |
# add specified variants to current resolution |
| 1294 |
set mod [getAndParseModuleWithVariant $mod $vrlist] |
| 1295 |
return [getPathToModule $mod $indir $report_issue] |
| 1296 |
} |
| 1297 |
} |
| 1298 |
} |
| 1299 |
modulefile { |
| 1300 |
# If mod was a file in this path, return that file |
| 1301 |
set retlist [list $dir/$mod $mod] |
| 1302 |
} |
| 1303 |
virtual { |
| 1304 |
# return virtual name with file it targets |
| 1305 |
set retlist [list [lindex $mod_list($mod) 2] $mod] |
| 1306 |
} |
| 1307 |
invalid - accesserr { |
| 1308 |
# may found mod but issue, so end search with error |
| 1309 |
set retlist [list {} $mod $mod {*}$mod_list($mod)] |
| 1310 |
} |
| 1311 |
} |
| 1312 |
} |
| 1313 |
} |
| 1314 |
# break loop if found something (valid or invalid module) |
| 1315 |
# elsewhere go to next path |
| 1316 |
if {[info exists retlist]} { |
| 1317 |
break |
| 1318 |
} |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|
| 1322 |
# set result if nothing found |
| 1323 |
if {![info exists retlist]} { |
| 1324 |
set retlist [list {} $mod $mod none "Unable to locate a modulefile for\ |
| 1325 |
'$mod'"] |
| 1326 |
} else { |
| 1327 |
# build module name and variant with variant specified |
| 1328 |
set modnamevr [getAndParseModuleWithVariant [lindex $retlist 1] $vrlist] |
| 1329 |
# update result if forbidden |
| 1330 |
if {[isModuleTagged $modnamevr forbidden 0 [lindex $retlist 0]]} { |
| 1331 |
set retlist [list {} [lindex $retlist 1] [lindex $retlist 2]\ |
| 1332 |
accesserr [getForbiddenMsg $modnamevr [lindex $retlist 0]]] |
| 1333 |
} |
| 1334 |
} |
| 1335 |
if {[lindex $retlist 0] ne {}} { |
| 1336 |
lappend retlist $modnamevr |
| 1337 |
reportTrace "'[lindex $retlist 1]' ([lindex $retlist 0]) matching\ |
| 1338 |
'$mod'" {Select module} |
| 1339 |
# no error if we look at loaded modules and passed mod not found loaded |
| 1340 |
} elseif {[lindex $retlist 3] ne {notloaded} && $report_issue} { |
| 1341 |
reportIssue {*}[lrange $retlist 3 5] |
| 1342 |
} |
| 1343 |
return $retlist |
| 1344 |
} |
| 1345 |
|
| 1346 |
proc isModuleLoaded {mod} { |
| 1347 |
return [info exists ::g_loadedModules($mod)] |
| 1348 |
} |
| 1349 |
|
| 1350 |
proc getModulefileFromLoadedModule {mod} { |
| 1351 |
if {[isModuleLoaded $mod]} { |
| 1352 |
return $::g_loadedModules($mod) |
| 1353 |
} |
| 1354 |
} |
| 1355 |
|
| 1356 |
proc getModulepathFromLoadedOrLoadingModule {mod} { |
| 1357 |
set modfile [getModulefileFromLoadingModule $mod] |
| 1358 |
if {![string length $modfile]} { |
| 1359 |
set modfile [getModulefileFromLoadedModule $mod] |
| 1360 |
} |
| 1361 |
if {[isModuleVirtual $mod $modfile]} { |
| 1362 |
# an empty string is returned if no enabled modulepath matches modfile |
| 1363 |
return [findModulepathFromModulefile $modfile] |
| 1364 |
} else { |
| 1365 |
return [getModulepathFromModuleName $modfile $mod] |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
proc isModulefileLoaded {modfile} { |
| 1370 |
return [info exists ::g_loadedModuleFiles($modfile)] |
| 1371 |
} |
| 1372 |
|
| 1373 |
proc getModuleFromLoadedModulefile {modfile {idx all}} { |
| 1374 |
if {[isModulefileLoaded $modfile]} { |
| 1375 |
if {$idx eq {all}} { |
| 1376 |
return $::g_loadedModuleFiles($modfile) |
| 1377 |
} else { |
| 1378 |
return [lindex $::g_loadedModuleFiles($modfile) $idx] |
| 1379 |
} |
| 1380 |
} |
| 1381 |
} |
| 1382 |
|
| 1383 |
proc isModuleLoading {mod} { |
| 1384 |
return [expr {$mod in [getLoadingModuleList]}] |
| 1385 |
} |
| 1386 |
|
| 1387 |
proc isModulefileLoading {modfile} { |
| 1388 |
return [expr {$modfile in [getLoadingModuleFileList]}] |
| 1389 |
} |
| 1390 |
|
| 1391 |
proc getModulefileFromLoadingModule {mod} { |
| 1392 |
if {[isModuleLoading $mod]} { |
| 1393 |
set idx [lsearch -exact [getLoadingModuleList] $mod] |
| 1394 |
return [lindex [getLoadingModuleFileList] $idx] |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
proc getModuleFromLoadingModulefile {modfile {idx all}} { |
| 1399 |
if {[isModulefileLoading $modfile]} { |
| 1400 |
set loadingmodlist [getLoadingModuleList] |
| 1401 |
foreach i [lsearch -all -exact [getLoadingModuleFileList] $modfile] { |
| 1402 |
lappend modlist [lindex $loadingmodlist $i] |
| 1403 |
} |
| 1404 |
|
| 1405 |
if {$idx eq {all}} { |
| 1406 |
return $modlist |
| 1407 |
} else { |
| 1408 |
return [lindex $modlist $idx] |
| 1409 |
} |
| 1410 |
} |
| 1411 |
} |
| 1412 |
|
| 1413 |
proc isModuleRefreshQualified {mod} { |
| 1414 |
return $::g_loadedModulesRefresh($mod) |
| 1415 |
} |
| 1416 |
|
| 1417 |
proc getLoadedModulePosition {mod} { |
| 1418 |
if {[info exists ::g_loadedModulePosition($mod)]} { |
| 1419 |
return $::g_loadedModulePosition($mod) |
| 1420 |
} else { |
| 1421 |
return -1 |
| 1422 |
} |
| 1423 |
} |
| 1424 |
|
| 1425 |
proc setLoadedModule {mod modfile uasked modvr refresh {build_dep_chain 1}} { |
| 1426 |
set ::g_loadedModules($mod) $modfile |
| 1427 |
set ::g_loadedModulePosition($mod) [array size ::g_loadedModules] |
| 1428 |
# a loaded modfile may correspond to multiple loaded virtual modules |
| 1429 |
lappend ::g_loadedModuleFiles($modfile) $mod |
| 1430 |
|
| 1431 |
# record if mod has been asked by user and relative loaded/auto-loaded tag |
| 1432 |
set loadedtag [expr {$uasked ? {loaded} : {auto-loaded}}] |
| 1433 |
setModuleAndVariantsTag $mod $modvr $loadedtag |
| 1434 |
|
| 1435 |
# is module qualified for refresh evaluation |
| 1436 |
set ::g_loadedModulesRefresh($mod) $refresh |
| 1437 |
|
| 1438 |
# build information to more efficiently get matching loaded module |
| 1439 |
setLoadedByModroot $mod |
| 1440 |
|
| 1441 |
if {$build_dep_chain} { |
| 1442 |
setModuleDependency $mod |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
proc unsetLoadedModule {mod modfile} { |
| 1447 |
unset ::g_loadedModules($mod) |
| 1448 |
unset ::g_loadedModulePosition($mod) |
| 1449 |
# a loaded modfile may correspond to multiple loaded virtual modules |
| 1450 |
if {[llength $::g_loadedModuleFiles($modfile)] == 1} { |
| 1451 |
unset ::g_loadedModuleFiles($modfile) |
| 1452 |
} else { |
| 1453 |
lrem ::g_loadedModuleFiles($modfile) $mod |
| 1454 |
} |
| 1455 |
|
| 1456 |
unset ::g_loadedModulesRefresh($mod) |
| 1457 |
|
| 1458 |
unsetLoadedByModroot $mod |
| 1459 |
unsetModuleDependency $mod |
| 1460 |
} |
| 1461 |
|
| 1462 |
# return the currently loaded module whose name is the closest to the |
| 1463 |
# name passed as argument. if no loaded module match at least one part |
| 1464 |
# of the passed name, an empty string is returned. |
| 1465 |
proc getLoadedWithClosestName {name modulepath_list} { |
| 1466 |
set ret {} |
| 1467 |
set retmax 1 |
| 1468 |
|
| 1469 |
if {[isModuleFullPath $name]} { |
| 1470 |
set fullname [getAbsolutePath $name] |
| 1471 |
# if module is passed as full modulefile path name, get corresponding |
| 1472 |
# short name from used modulepaths |
| 1473 |
if {[set shortname [findModuleNameFromModulefile $fullname]] ne {}} { |
| 1474 |
set nametosplit $shortname |
| 1475 |
# or look at lmfile names to return the eventual exact match |
| 1476 |
} else { |
| 1477 |
# module may be loaded with its full path name |
| 1478 |
if {[isModuleLoaded $fullname]} { |
| 1479 |
set ret $fullname |
| 1480 |
# or name corresponds to the _lmfiles_ entry of a virtual modules in |
| 1481 |
# which case lastly loaded virtual module is returned |
| 1482 |
} elseif {[isModulefileLoaded $fullname]} { |
| 1483 |
set ret [getModuleFromLoadedModulefile $fullname end] |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} else { |
| 1487 |
set nametosplit $name |
| 1488 |
} |
| 1489 |
|
| 1490 |
if {[info exists nametosplit]} { |
| 1491 |
# compare name to each currently loaded module name |
| 1492 |
##nagelfar ignore Found constant |
| 1493 |
foreach mod [getEnvLoadedModulePropertyParsedList name] { |
| 1494 |
# if module loaded as fullpath but test name not, try to get loaded |
| 1495 |
# mod short name (with currently used modulepaths) to compare it |
| 1496 |
if {[isModuleFullPath $mod] && [set modname\ |
| 1497 |
[findModuleNameFromModulefile $mod]] ne {}} { |
| 1498 |
# no alt name to retrieve if module has been loaded full path |
| 1499 |
set matchmodlist [list $modname] |
| 1500 |
} else { |
| 1501 |
# add alternative names of mod to the matching list |
| 1502 |
set matchmodlist [list $mod {*}[getLoadedAltname $mod]] |
| 1503 |
} |
| 1504 |
|
| 1505 |
# compare each element of the name to find closest answer. in case of |
| 1506 |
# equality, last loaded module will be returned as it overwrites |
| 1507 |
# previously found value |
| 1508 |
foreach matchmod $matchmodlist { |
| 1509 |
if {[set i [modStartNb $matchmod $nametosplit]] >= $retmax} { |
| 1510 |
set retmax $i |
| 1511 |
set ret $mod |
| 1512 |
break |
| 1513 |
} |
| 1514 |
} |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
reportDebug "'$ret' closest to '$name'" |
| 1519 |
return $ret |
| 1520 |
} |
| 1521 |
|
| 1522 |
proc getLoadedExactName {name modulepath_list} { |
| 1523 |
return [getLoadedMatchingName $name {} 0 {} $modulepath_list eqspec] |
| 1524 |
} |
| 1525 |
|
| 1526 |
proc getLoadedEqstartName {name modulepath_list} { |
| 1527 |
return [getLoadedMatchingName $name {} 0 {} $modulepath_list] |
| 1528 |
} |
| 1529 |
|
| 1530 |
# return the currently loaded module whose name is equal or include the name |
| 1531 |
# passed as argument. if no loaded module match, an empty string is returned. |
| 1532 |
# loading: look at currently loading modules instead of loaded if loading == 1 |
| 1533 |
# lmlist: only take into account passed loaded module list not all loaded mods |
| 1534 |
proc getLoadedMatchingName {name {behavior {}} {loading 0} {lmlist {}}\ |
| 1535 |
{modulepath_list {}} {eqtest eqstart}} { |
| 1536 |
set ret {} |
| 1537 |
set retmax 0 |
| 1538 |
# get default behavior from unload_match_order config |
| 1539 |
if {$behavior eq {}} { |
| 1540 |
set behavior [getConf unload_match_order] |
| 1541 |
} |
| 1542 |
|
| 1543 |
# use loading-specific procedures instead of loaded-specific ones |
| 1544 |
if {$loading} { |
| 1545 |
set isModulefileLoaded isModulefileLoading |
| 1546 |
set getModuleFromLoadedModulefile getModuleFromLoadingModulefile |
| 1547 |
set isLoadedMatchSpecificPath isLoadingMatchSpecificPath |
| 1548 |
} else { |
| 1549 |
##nagelfar ignore #4 Found constant |
| 1550 |
set isModulefileLoaded isModulefileLoaded |
| 1551 |
set getModuleFromLoadedModulefile getModuleFromLoadedModulefile |
| 1552 |
set isLoadedMatchSpecificPath isLoadedMatchSpecificPath |
| 1553 |
} |
| 1554 |
|
| 1555 |
# fetch currently loaded/loading module name is no list provided |
| 1556 |
if {![llength $lmlist]} { |
| 1557 |
##nagelfar ignore #2 Badly formed if statement |
| 1558 |
set lmlist [if {$loading} {getLoadingModuleList}\ |
| 1559 |
{getLoadedMatchingModroot $name}] |
| 1560 |
} |
| 1561 |
|
| 1562 |
# if module is passed as full modulefile path name, look at lmfile names |
| 1563 |
# to return the eventual exact match |
| 1564 |
if {[isModuleFullPath $name]} { |
| 1565 |
set mod [getAbsolutePath $name] |
| 1566 |
# if module is loaded with its full path name loadedmodules entry is |
| 1567 |
# equivalent to _lmfiles_ corresponding entry so only check _lmfiles_ |
| 1568 |
if {[$isModulefileLoaded $mod]} { |
| 1569 |
# a loaded modfile may correspond to multiple loaded virtual modules |
| 1570 |
switch -- $behavior { |
| 1571 |
returnlast { |
| 1572 |
# the last loaded/loading module will be returned |
| 1573 |
set ret [$getModuleFromLoadedModulefile $mod end] |
| 1574 |
} |
| 1575 |
returnfirst { |
| 1576 |
# the first loaded/loading module will be returned |
| 1577 |
set ret [$getModuleFromLoadedModulefile $mod 0] |
| 1578 |
} |
| 1579 |
returnall { |
| 1580 |
# all loaded/loading modules will be returned |
| 1581 |
set ret [$getModuleFromLoadedModulefile $mod] |
| 1582 |
} |
| 1583 |
} |
| 1584 |
} |
| 1585 |
} elseif {$name ne {}} { |
| 1586 |
# compare name to each currently loaded/loading module name, if multiple |
| 1587 |
# mod match name: |
| 1588 |
foreach mod $lmlist { |
| 1589 |
# if module loaded as fullpath but test name not, try to get loaded |
| 1590 |
# mod short name (with currently used modulepaths) to compare it |
| 1591 |
if {[isModuleFullPath $mod] && [set modname\ |
| 1592 |
[findModuleNameFromModulefile $mod]] ne {}} { |
| 1593 |
set matchmod $modname |
| 1594 |
} else { |
| 1595 |
set matchmod $mod |
| 1596 |
} |
| 1597 |
# test module matches specified modulepaths |
| 1598 |
if {![$isLoadedMatchSpecificPath $mod $modulepath_list]} { |
| 1599 |
continue |
| 1600 |
} |
| 1601 |
if {[modEq $name $matchmod $eqtest 1 [expr {$loading ? 1 : 2}] 1]} { |
| 1602 |
switch -- $behavior { |
| 1603 |
returnlast { |
| 1604 |
# the last loaded module will be returned |
| 1605 |
set ret $mod |
| 1606 |
} |
| 1607 |
returnfirst { |
| 1608 |
# the first loaded module will be returned |
| 1609 |
set ret $mod |
| 1610 |
break |
| 1611 |
} |
| 1612 |
returnall { |
| 1613 |
# all loaded modules will be returned |
| 1614 |
lappend ret $mod |
| 1615 |
} |
| 1616 |
} |
| 1617 |
} |
| 1618 |
} |
| 1619 |
} |
| 1620 |
|
| 1621 |
reportDebug "'$ret' matches '$name'" |
| 1622 |
return $ret |
| 1623 |
} |
| 1624 |
|
| 1625 |
# return if loaded mod is part of modulepath from specified constrained list |
| 1626 |
proc isLoadedMatchSpecificPath {mod modulepath_list} { |
| 1627 |
set searchid $mod:$modulepath_list |
| 1628 |
if {[info exists ::g_isLoadedMatchSpecificPathMemCache($searchid)]} { |
| 1629 |
return $::g_isLoadedMatchSpecificPathMemCache($searchid) |
| 1630 |
} |
| 1631 |
set mod_file [getModulefileFromLoadedModule $mod] |
| 1632 |
set ::g_isLoadedMatchSpecificPathMemCache($searchid)\ |
| 1633 |
[isModulefileMatchSpecificPath $mod_file $modulepath_list] |
| 1634 |
} |
| 1635 |
|
| 1636 |
proc isLoadingMatchSpecificPath {mod modulepath_list} { |
| 1637 |
set searchid $mod:$modulepath_list |
| 1638 |
if {[info exists ::g_isLoadingMatchSpecificPathMemCache($searchid)]} { |
| 1639 |
return $::g_isLoadingMatchSpecificPathMemCache($searchid) |
| 1640 |
} |
| 1641 |
set mod_file [getModulefileFromLoadingModule $mod] |
| 1642 |
set ::g_isLoadingMatchSpecificPathMemCache($searchid)\ |
| 1643 |
[isModulefileMatchSpecificPath $mod_file $modulepath_list] |
| 1644 |
} |
| 1645 |
|
| 1646 |
proc isModulefileMatchSpecificPath {mod_file modulepath_list} { |
| 1647 |
if {[llength $modulepath_list]} { |
| 1648 |
return [isModulefileInModulepathList $mod_file $modulepath_list] |
| 1649 |
} else { |
| 1650 |
return 1 |
| 1651 |
} |
| 1652 |
} |
| 1653 |
|
| 1654 |
proc setLoadedSourceSh {mod args} { |
| 1655 |
foreach arg $args { |
| 1656 |
# each arg is a list with source-sh call string at index 0 and resulting |
| 1657 |
# modulefile commands at all later index positions |
| 1658 |
set modcontent [lassign $arg shtomodargs] |
| 1659 |
if {![llength [getLoadedSourceShScriptContent $mod $shtomodargs]]} { |
| 1660 |
# filter alias/function/complete definition not to record them |
| 1661 |
set shtomod_entry [list $shtomodargs] |
| 1662 |
foreach modcmdlist $modcontent { |
| 1663 |
set modcmd [lindex $modcmdlist 0] |
| 1664 |
switch -- $modcmd { |
| 1665 |
set-alias - set-function { |
| 1666 |
# set an empty body to make valid unset-* call |
| 1667 |
lappend shtomod_entry [list {*}[lrange $modcmdlist 0 1] {}] |
| 1668 |
} |
| 1669 |
complete { |
| 1670 |
set complist [lrange $modcmdlist 0 2] |
| 1671 |
# ensure only one order is recorded for each shell-name |
| 1672 |
if {![info exists filtcomp($complist)]} { |
| 1673 |
lappend shtomod_entry [list {*}$complist {}] |
| 1674 |
set filtcomp($complist) 1 |
| 1675 |
} |
| 1676 |
} |
| 1677 |
default { |
| 1678 |
lappend shtomod_entry $modcmdlist |
| 1679 |
} |
| 1680 |
} |
| 1681 |
} |
| 1682 |
lappend ::g_loadedModuleSourceSh($mod) $shtomod_entry |
| 1683 |
} |
| 1684 |
} |
| 1685 |
} |
| 1686 |
|
| 1687 |
proc unsetLoadedSourceSh {mod} { |
| 1688 |
if {[info exists ::g_loadedModuleSourceSh($mod)]} { |
| 1689 |
unset ::g_loadedModuleSourceSh($mod) |
| 1690 |
} |
| 1691 |
} |
| 1692 |
|
| 1693 |
proc getLoadedSourceSh {mod} { |
| 1694 |
if {[info exists ::g_loadedModuleSourceSh($mod)]} { |
| 1695 |
return $::g_loadedModuleSourceSh($mod) |
| 1696 |
} |
| 1697 |
} |
| 1698 |
|
| 1699 |
proc getLoadedSourceShScriptContent {mod script} { |
| 1700 |
set content {} |
| 1701 |
foreach shtomod_entry [getLoadedSourceSh $mod] { |
| 1702 |
if {$script eq [lindex $shtomod_entry 0]} { |
| 1703 |
set content [lrange $shtomod_entry 1 end] |
| 1704 |
break |
| 1705 |
} |
| 1706 |
} |
| 1707 |
return $content |
| 1708 |
} |
| 1709 |
|
| 1710 |
proc setLoadedConflict {mod args} { |
| 1711 |
lappendNoDup ::g_loadedModuleConflict($mod) {*}$args |
| 1712 |
setLoadedConflictByModroot $mod {*}$args |
| 1713 |
} |
| 1714 |
|
| 1715 |
proc setLoadedConflictByModroot {mod args} { |
| 1716 |
foreach con_spec $args { |
| 1717 |
# record lower case mod root if icase is enabled |
| 1718 |
set con_mod_root [getModuleRootFromVersSpecLowerIfIcase $con_spec] |
| 1719 |
lappend ::g_loadedConflictByModroot($con_mod_root) $mod $con_spec |
| 1720 |
lappendNoDup ::g_modrootByLoadedConflict($mod) $con_mod_root |
| 1721 |
} |
| 1722 |
} |
| 1723 |
|
| 1724 |
proc unsetLoadedConflict {mod} { |
| 1725 |
if {[info exists ::g_loadedModuleConflict($mod)]} { |
| 1726 |
unset ::g_loadedModuleConflict($mod) |
| 1727 |
} |
| 1728 |
unsetLoadedConflictByModroot $mod |
| 1729 |
} |
| 1730 |
|
| 1731 |
proc unsetLoadedConflictByModroot {mod} { |
| 1732 |
if {[info exists ::g_modrootByLoadedConflict($mod)]} { |
| 1733 |
foreach mod_root $::g_modrootByLoadedConflict($mod) { |
| 1734 |
set with_con_spec_list {} |
| 1735 |
foreach {with_mod con_spec} $::g_loadedConflictByModroot($mod_root) { |
| 1736 |
if {$with_mod ne $mod} { |
| 1737 |
lappend with_con_spec_list $with_mod $con_spec |
| 1738 |
} |
| 1739 |
} |
| 1740 |
if {[llength $with_con_spec_list]} { |
| 1741 |
set ::g_loadedConflictByModroot($mod_root) $with_con_spec_list |
| 1742 |
} else { |
| 1743 |
unset ::g_loadedConflictByModroot($mod_root) |
| 1744 |
} |
| 1745 |
} |
| 1746 |
unset ::g_modrootByLoadedConflict($mod) |
| 1747 |
} |
| 1748 |
} |
| 1749 |
|
| 1750 |
proc getLoadedConflict {mod} { |
| 1751 |
if {[info exists ::g_loadedModuleConflict($mod)]} { |
| 1752 |
return $::g_loadedModuleConflict($mod) |
| 1753 |
} |
| 1754 |
} |
| 1755 |
|
| 1756 |
proc getLoadedConflictMatchingModroot {mod} { |
| 1757 |
set with_con_spec_list {} |
| 1758 |
set mod_root_list [getLoadedAllModroot $mod] |
| 1759 |
foreach mod_root $mod_root_list { |
| 1760 |
if {[info exists ::g_loadedConflictByModroot($mod_root)]} { |
| 1761 |
lappend with_con_spec_list {*}$::g_loadedConflictByModroot($mod_root) |
| 1762 |
} |
| 1763 |
} |
| 1764 |
return $with_con_spec_list |
| 1765 |
} |
| 1766 |
|
| 1767 |
proc getModuleLoadedConflict {mod {modulepath_list {}}} { |
| 1768 |
set mod_con_list {} |
| 1769 |
# get module short name if loaded by its full pathname |
| 1770 |
##nagelfar ignore #2 Badly formed if statement |
| 1771 |
set mod_name [if {[isModuleFullPath $mod]} {findModuleNameFromModulefile\ |
| 1772 |
$mod} {return -level 0 $mod}] |
| 1773 |
|
| 1774 |
# is some loaded or loading modules correspond to conflict defined by mod |
| 1775 |
if {[info exists ::g_loadedModuleConflict($mod)]} { |
| 1776 |
foreach with_mod $::g_loadedModuleConflict($mod) { |
| 1777 |
# skip own reflexive conflict (look at mod main and alternative |
| 1778 |
# names) and those already known |
| 1779 |
if {![modEq $with_mod $mod_name eqstart 1 2 1] && ([set\ |
| 1780 |
lm_mod_list [getLoadedMatchingName $with_mod returnall]] ne {}\ |
| 1781 |
|| [set lm_mod_list [getLoadedMatchingName $with_mod returnall\ |
| 1782 |
1]] ne {})} { |
| 1783 |
# multiple loaded module may match conflict declared name |
| 1784 |
lappendNoDup mod_con_list {*}$lm_mod_list |
| 1785 |
} |
| 1786 |
} |
| 1787 |
} |
| 1788 |
|
| 1789 |
# check if any other loaded module has declared a conflict with mod |
| 1790 |
foreach {with_mod con_spec} [getLoadedConflictMatchingModroot $mod] { |
| 1791 |
# skip already found and own reflexive conflict |
| 1792 |
if {$with_mod ni $mod_con_list && $with_mod ne $mod} { |
| 1793 |
if {[modEq $con_spec $mod_name eqstart 1 2 1]} { |
| 1794 |
lappend mod_con_list $with_mod |
| 1795 |
} |
| 1796 |
} |
| 1797 |
} |
| 1798 |
|
| 1799 |
if {[isOtherVariantOfModuleLoaded $mod] || ([isModuleLoaded $mod] &&\ |
| 1800 |
![isLoadedMatchSpecificPath $mod $modulepath_list])} { |
| 1801 |
lappend mod_con_list [getModuleNameAndVersFromVersSpec $mod] |
| 1802 |
} |
| 1803 |
|
| 1804 |
reportDebug "'$mod' conflicts with '$mod_con_list'" |
| 1805 |
return $mod_con_list |
| 1806 |
} |
| 1807 |
|
| 1808 |
proc setLoadedPrereq {mod args} { |
| 1809 |
lappendNoDup ::g_loadedModulePrereq($mod) {*}$args |
| 1810 |
} |
| 1811 |
|
| 1812 |
proc unsetLoadedPrereq {mod} { |
| 1813 |
if {[info exists ::g_loadedModulePrereq($mod)]} { |
| 1814 |
unset ::g_loadedModulePrereq($mod) |
| 1815 |
} |
| 1816 |
} |
| 1817 |
|
| 1818 |
proc getLoadedPrereq {mod} { |
| 1819 |
if {[info exists ::g_loadedModulePrereq($mod)]} { |
| 1820 |
return $::g_loadedModulePrereq($mod) |
| 1821 |
} |
| 1822 |
} |
| 1823 |
|
| 1824 |
proc setLoadedPrereqPath {mod args} { |
| 1825 |
lappendNoDup ::g_loadedModulePrereqPath($mod) {*}$args |
| 1826 |
} |
| 1827 |
|
| 1828 |
proc unsetLoadedPrereqPath {mod} { |
| 1829 |
if {[info exists ::g_loadedModulePrereqPath($mod)]} { |
| 1830 |
unset ::g_loadedModulePrereqPath($mod) |
| 1831 |
} |
| 1832 |
} |
| 1833 |
|
| 1834 |
proc getLoadedPrereqPath {mod {prereq {}}} { |
| 1835 |
if {[info exists ::g_loadedModulePrereqPath($mod)]} { |
| 1836 |
if {![string length $prereq]} { |
| 1837 |
return $::g_loadedModulePrereqPath($mod) |
| 1838 |
} |
| 1839 |
# return specific entry for given prereq |
| 1840 |
array set prereq_path_arr $::g_loadedModulePrereqPath($mod) |
| 1841 |
if {[info exists prereq_path_arr($prereq)]} { |
| 1842 |
return $prereq_path_arr($prereq) |
| 1843 |
} |
| 1844 |
} |
| 1845 |
} |
| 1846 |
|
| 1847 |
proc setLoadedAltname {mod args} { |
| 1848 |
foreach arg $args { |
| 1849 |
switch -- [lindex $arg 0] { |
| 1850 |
al { |
| 1851 |
lappendNoDup ::g_loadedModuleAliasAltname($mod) [lindex $arg 1] |
| 1852 |
} |
| 1853 |
as { |
| 1854 |
lappendNoDup ::g_loadedModuleAutoAltname($mod) [lindex $arg 1] |
| 1855 |
} |
| 1856 |
default { |
| 1857 |
lappendNoDup ::g_loadedModuleAltname($mod) [lindex $arg 0] |
| 1858 |
} |
| 1859 |
} |
| 1860 |
} |
| 1861 |
} |
| 1862 |
|
| 1863 |
proc unsetLoadedAltname {mod} { |
| 1864 |
if {[info exists ::g_loadedModuleAltname($mod)]} { |
| 1865 |
unset ::g_loadedModuleAltname($mod) |
| 1866 |
} |
| 1867 |
if {[info exists ::g_loadedModuleAliasAltname($mod)]} { |
| 1868 |
unset ::g_loadedModuleAliasAltname($mod) |
| 1869 |
} |
| 1870 |
if {[info exists ::g_loadedModuleAutoAltname($mod)]} { |
| 1871 |
unset ::g_loadedModuleAutoAltname($mod) |
| 1872 |
} |
| 1873 |
} |
| 1874 |
|
| 1875 |
proc getLoadedAltname {mod {typelist {sym alias autosym}} {with_type 0}} { |
| 1876 |
set ret {} |
| 1877 |
if {[info exists ::g_loadedModuleAltname($mod)] && {sym} in $typelist} { |
| 1878 |
if {$with_type} { |
| 1879 |
foreach altname $::g_loadedModuleAltname($mod) { |
| 1880 |
lappend ret [list $altname] |
| 1881 |
} |
| 1882 |
} else { |
| 1883 |
set ret $::g_loadedModuleAltname($mod) |
| 1884 |
} |
| 1885 |
} |
| 1886 |
if {[info exists ::g_loadedModuleAliasAltname($mod)] && {alias} in\ |
| 1887 |
$typelist} { |
| 1888 |
if {$with_type} { |
| 1889 |
foreach altname $::g_loadedModuleAliasAltname($mod) { |
| 1890 |
lappend ret [list al $altname] |
| 1891 |
} |
| 1892 |
} else { |
| 1893 |
lappend ret {*}$::g_loadedModuleAliasAltname($mod) |
| 1894 |
} |
| 1895 |
} |
| 1896 |
if {[info exists ::g_loadedModuleAutoAltname($mod)] && {autosym} in\ |
| 1897 |
$typelist} { |
| 1898 |
if {$with_type} { |
| 1899 |
foreach altname $::g_loadedModuleAutoAltname($mod) { |
| 1900 |
lappend ret [list as $altname] |
| 1901 |
} |
| 1902 |
} else { |
| 1903 |
lappend ret {*}$::g_loadedModuleAutoAltname($mod) |
| 1904 |
} |
| 1905 |
} |
| 1906 |
return $ret |
| 1907 |
} |
| 1908 |
|
| 1909 |
proc getLoadedAllModroot {mod} { |
| 1910 |
set name_list [list $mod {*}[getLoadedAltname $mod]] |
| 1911 |
# get module short name if it is loaded as fullpath and modulepath is used |
| 1912 |
if {[isModuleFullPath $mod]} { |
| 1913 |
set name [findModuleNameFromModulefile $mod] |
| 1914 |
if {[string length $name]} { |
| 1915 |
lappend name_list $name |
| 1916 |
} |
| 1917 |
} |
| 1918 |
set mod_root_list {} |
| 1919 |
foreach name $name_list { |
| 1920 |
# mod root recorded lower case if icase is enabled |
| 1921 |
lappendNoDup mod_root_list [getModuleRootFromVersSpecLowerIfIcase $name] |
| 1922 |
} |
| 1923 |
return $mod_root_list |
| 1924 |
} |
| 1925 |
|
| 1926 |
# get all names of loaded module "mod" and set structure to find all root name |
| 1927 |
# this loaded module matches. use this information to more efficiently get |
| 1928 |
# matching loaded module: only fully test match with modules matching the root |
| 1929 |
# name of search query |
| 1930 |
proc setLoadedByModroot {mod} { |
| 1931 |
set mod_root_list [getLoadedAllModroot $mod] |
| 1932 |
foreach mod_root $mod_root_list { |
| 1933 |
lappend ::g_loadedByModroot($mod_root) $mod |
| 1934 |
} |
| 1935 |
# set special structure to easily unset main one on module unload |
| 1936 |
set ::g_modrootByLoaded($mod) $mod_root_list |
| 1937 |
} |
| 1938 |
|
| 1939 |
proc getLoadedMatchingModroot {name} { |
| 1940 |
# mod root recorded lower case if icase is enabled |
| 1941 |
set mod_root [getModuleRootFromVersSpecLowerIfIcase $name] |
| 1942 |
if {[info exists ::g_loadedByModroot($mod_root)]} { |
| 1943 |
return $::g_loadedByModroot($mod_root) |
| 1944 |
} |
| 1945 |
} |
| 1946 |
|
| 1947 |
proc unsetLoadedByModroot {mod} { |
| 1948 |
foreach mod_root $::g_modrootByLoaded($mod) { |
| 1949 |
lrem ::g_loadedByModroot($mod_root) $mod |
| 1950 |
} |
| 1951 |
unset ::g_modrootByLoaded($mod) |
| 1952 |
} |
| 1953 |
|
| 1954 |
proc setLoadedVariant {mod args} { |
| 1955 |
lappend ::g_loadedModuleVariant($mod) {*}$args |
| 1956 |
} |
| 1957 |
|
| 1958 |
proc unsetLoadedVariant {mod} { |
| 1959 |
if {[info exists ::g_loadedModuleVariant($mod)]} { |
| 1960 |
unset ::g_loadedModuleVariant($mod) |
| 1961 |
} |
| 1962 |
} |
| 1963 |
|
| 1964 |
proc getLoadedVariant {mod} { |
| 1965 |
if {[info exists ::g_loadedModuleVariant($mod)]} { |
| 1966 |
return $::g_loadedModuleVariant($mod) |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
proc getLoadedModuleWithVariantList {} { |
| 1971 |
set modvrlist [list] |
| 1972 |
foreach mod [getEnvLoadedModulePropertyParsedList name] { |
| 1973 |
set modvr [list $mod] |
| 1974 |
set vrlist [getVariantList $mod 5] |
| 1975 |
if {[llength $vrlist]} { |
| 1976 |
lappend modvr {*}$vrlist |
| 1977 |
} |
| 1978 |
lappend modvrlist $modvr |
| 1979 |
} |
| 1980 |
return $modvrlist |
| 1981 |
} |
| 1982 |
|
| 1983 |
proc getLoadedModuleWithVariantSaveTagArrayList {} { |
| 1984 |
array set tag_arr {} |
| 1985 |
foreach mod [getEnvLoadedModulePropertyParsedList name] { |
| 1986 |
set modvr [list $mod] |
| 1987 |
set vrlist [getVariantList $mod 1] |
| 1988 |
if {[llength $vrlist]} { |
| 1989 |
lappend modvr {*}$vrlist |
| 1990 |
} |
| 1991 |
# create entry in array only if tags set |
| 1992 |
set tag_list [getSaveTagList $mod] |
| 1993 |
if {[llength $tag_list]} { |
| 1994 |
set tag_arr($modvr) $tag_list |
| 1995 |
} |
| 1996 |
} |
| 1997 |
return [array get tag_arr] |
| 1998 |
} |
| 1999 |
|
| 2000 |
proc getAndParseLoadedModuleWithVariant {mod} { |
| 2001 |
set vr_list [getVariantList $mod 1] |
| 2002 |
return [getAndParseModuleWithVariant $mod $vr_list] |
| 2003 |
} |
| 2004 |
|
| 2005 |
proc getAndParseModuleWithVariant {mod vr_list} { |
| 2006 |
if {[llength $vr_list]} { |
| 2007 |
lassign [parseModuleSpecification 0 0 0 0 $mod {*}$vr_list] mod_vr |
| 2008 |
} else { |
| 2009 |
set mod_vr $mod |
| 2010 |
} |
| 2011 |
return $mod_vr |
| 2012 |
} |
| 2013 |
|
| 2014 |
proc setLoadedUse {mod args} { |
| 2015 |
lappendNoDup ::g_loadedModuleUse($mod) {*}$args |
| 2016 |
} |
| 2017 |
|
| 2018 |
proc unsetLoadedUse {mod} { |
| 2019 |
if {[info exists ::g_loadedModuleUse($mod)]} { |
| 2020 |
unset ::g_loadedModuleUse($mod) |
| 2021 |
} |
| 2022 |
} |
| 2023 |
|
| 2024 |
proc getLoadedUse {mod} { |
| 2025 |
if {[info exists ::g_loadedModuleUse($mod)]} { |
| 2026 |
return $::g_loadedModuleUse($mod) |
| 2027 |
} |
| 2028 |
} |
| 2029 |
|
| 2030 |
proc getViaListModuleForModulepath {modpath} { |
| 2031 |
set via_list {} |
| 2032 |
while {[string length [set via [getViaModuleForModulepath $modpath]]]} { |
| 2033 |
lappend via_list $via |
| 2034 |
set new_modpath [getViaModuleModulepath $via] |
| 2035 |
# stop if via is enabling its own modulepath |
| 2036 |
if {$modpath eq $new_modpath} { |
| 2037 |
break |
| 2038 |
} |
| 2039 |
set modpath $new_modpath |
| 2040 |
} |
| 2041 |
return [lreverse $via_list] |
| 2042 |
} |
| 2043 |
|
| 2044 |
proc getViaModuleForModulepath {modpath} { |
| 2045 |
lassign [getAllLoadedModuleUsingModulepath $modpath] via |
| 2046 |
if {![string length $via] && $modpath ni [getModulePathList]} { |
| 2047 |
# get via information collected from spider processing |
| 2048 |
set via [getModuleUsingModulepath $modpath] |
| 2049 |
} |
| 2050 |
return $via |
| 2051 |
} |
| 2052 |
|
| 2053 |
proc getModuleUsingModulepath {modpath} { |
| 2054 |
foreach mod [array names ::g_loadedModuleUse] { |
| 2055 |
# no need to resolve variable reference in used path as this resolution |
| 2056 |
# as already been performed when recording in global structure during |
| 2057 |
# spider processing |
| 2058 |
if {$modpath in $::g_loadedModuleUse($mod)} { |
| 2059 |
return $mod |
| 2060 |
} |
| 2061 |
} |
| 2062 |
} |
| 2063 |
|
| 2064 |
proc setViaModuleModulepath {mod modpath} { |
| 2065 |
# global array only used during spider, no need to integrate into push/pop |
| 2066 |
# restore mechanisms |
| 2067 |
set ::g_viaModuleModulepath($mod) $modpath |
| 2068 |
} |
| 2069 |
|
| 2070 |
proc getViaModuleModulepath {mod} { |
| 2071 |
# get modulepath of via module if loaded |
| 2072 |
if {[isModuleLoaded $mod]} { |
| 2073 |
return [getModulepathFromLoadedOrLoadingModule $mod] |
| 2074 |
} |
| 2075 |
# otherwise return via modulepath collected during spider processing |
| 2076 |
if {[info exists ::g_viaModuleModulepath($mod)]} { |
| 2077 |
return $::g_viaModuleModulepath($mod) |
| 2078 |
} |
| 2079 |
} |
| 2080 |
|
| 2081 |
# Return all loaded module that enables given modulepath. Reference counter |
| 2082 |
# is checked to detect if modulepath was enabled prior loading the modules in |
| 2083 |
# which case modulepath is considered not enabled by loaded modules. modpath |
| 2084 |
# may not be currently enabled. |
| 2085 |
proc getAllLoadedModuleUsingModulepath {modpath} { |
| 2086 |
set mod_list {} |
| 2087 |
foreach mod [getEnvLoadedModulePropertyParsedList name] { |
| 2088 |
if {$modpath in [resolvStringListWithEnv [getLoadedUse $mod]]} { |
| 2089 |
lappend mod_list $mod |
| 2090 |
} |
| 2091 |
} |
| 2092 |
set ref_count [getPathReferenceCount MODULEPATH $modpath [getState\ |
| 2093 |
path_separator] 1] |
| 2094 |
if {$ref_count <= [llength $mod_list]} { |
| 2095 |
return $mod_list |
| 2096 |
} |
| 2097 |
} |
| 2098 |
|
| 2099 |
proc unsetEnvLoadedModuleProperty {mod_name prop} { |
| 2100 |
set prop_env_var [getLoadedModulePropertyEnvVarName $prop] |
| 2101 |
set env_loaded_prop_list [getEnvLoadedModulePropertyList $prop] |
| 2102 |
set mod_pattern_in_env_loaded_prop [escapeGlobChars $mod_name][getState\ |
| 2103 |
sub1_separator]* |
| 2104 |
|
| 2105 |
set mod_env_loaded_prop [lsearch -glob -inline $env_loaded_prop_list\ |
| 2106 |
$mod_pattern_in_env_loaded_prop] |
| 2107 |
|
| 2108 |
if {[string length $mod_env_loaded_prop]} { |
| 2109 |
remove-path $prop_env_var $mod_env_loaded_prop |
| 2110 |
} |
| 2111 |
} |
| 2112 |
|
| 2113 |
proc setEnvLoadedModuleProperty {mod_name prop value_list} { |
| 2114 |
set serialize_depth [getEnvLoadedModulePropertyStructDepth $prop] |
| 2115 |
set serialize_proc serialize${serialize_depth}ModulePropertyValue |
| 2116 |
set char_map_list [getEnvLoadedModulePropertyCharMapList $prop] |
| 2117 |
set prop_env_var [getLoadedModulePropertyEnvVarName $prop] |
| 2118 |
|
| 2119 |
if {[llength $value_list]} { |
| 2120 |
set serialized_value_list [$serialize_proc $mod_name $value_list\ |
| 2121 |
$char_map_list] |
| 2122 |
append-path $prop_env_var $serialized_value_list |
| 2123 |
} |
| 2124 |
} |
| 2125 |
|
| 2126 |
proc getEnvLoadedModulePropertyStructDepth {prop} { |
| 2127 |
switch -- $prop { |
| 2128 |
file - init - modulepath - name - refresh { |
| 2129 |
return 0Lvl |
| 2130 |
} |
| 2131 |
conflict - extratag - tag - use { |
| 2132 |
return 1Lvl |
| 2133 |
} |
| 2134 |
altname - prereq - prereqpath - sourcesh - stickyrule - variant { |
| 2135 |
return 2Lvl |
| 2136 |
} |
| 2137 |
} |
| 2138 |
} |
| 2139 |
|
| 2140 |
proc getEnvLoadedModulePropertyCharUnmapList {prop} { |
| 2141 |
set char_unmap_list {} |
| 2142 |
foreach {char mapped} [getEnvLoadedModulePropertyCharMapList $prop] { |
| 2143 |
lappend char_unmap_list $mapped $char |
| 2144 |
} |
| 2145 |
return $char_unmap_list |
| 2146 |
} |
| 2147 |
|
| 2148 |
proc getEnvLoadedModulePropertyCharMapList {prop} { |
| 2149 |
return [switch -- $prop { |
| 2150 |
sourcesh { |
| 2151 |
list [getState path_separator] <EnvModEscPS>\ |
| 2152 |
[getState sub1_separator] <EnvModEscS1>\ |
| 2153 |
[getState sub2_separator] <EnvModEscS2> |
| 2154 |
} |
| 2155 |
default { |
| 2156 |
list : < |
| 2157 |
} |
| 2158 |
}] |
| 2159 |
} |
| 2160 |
|
| 2161 |
proc serialize2LvlModulePropertyValue {mod structured_value_list\ |
| 2162 |
char_map_list} { |
| 2163 |
set sub2_sepa [getState sub2_separator] |
| 2164 |
set serialized_value_list [list] |
| 2165 |
foreach structured_value $structured_value_list { |
| 2166 |
set mapped_structured_value [string map $char_map_list\ |
| 2167 |
$structured_value] |
| 2168 |
lappend serialized_value_list [join $mapped_structured_value $sub2_sepa] |
| 2169 |
} |
| 2170 |
# no character translation as it already occurred here |
| 2171 |
return [serialize1LvlModulePropertyValue $mod $serialized_value_list {}] |
| 2172 |
} |
| 2173 |
|
| 2174 |
proc serialize1LvlModulePropertyValue {mod structured_value_list\ |
| 2175 |
char_map_list} { |
| 2176 |
set serialized_value [join [list $mod {*}$structured_value_list] [getState\ |
| 2177 |
sub1_separator]] |
| 2178 |
return [string map $char_map_list $serialized_value] |
| 2179 |
} |
| 2180 |
|
| 2181 |
proc unserialize2LvlModulePropertyValueList {serialized_value_list\ |
| 2182 |
char_unmap_list} { |
| 2183 |
set lvl1_serialized_value_list [unserialize1LvlModulePropertyValueList\ |
| 2184 |
$serialized_value_list {}] |
| 2185 |
set structured_value_list {} |
| 2186 |
set sub2_sepa [getState sub2_separator] |
| 2187 |
foreach lvl1_serialized_value $lvl1_serialized_value_list { |
| 2188 |
set lvl1_strutured_value {} |
| 2189 |
set first 1 |
| 2190 |
foreach lvl2_serialized_value $lvl1_serialized_value { |
| 2191 |
# keep first element as string (module name) |
| 2192 |
if {$first} { |
| 2193 |
set lvl2_structured_value [string map $char_unmap_list\ |
| 2194 |
$lvl2_serialized_value] |
| 2195 |
set first 0 |
| 2196 |
} else { |
| 2197 |
set lvl2_structured_value {} |
| 2198 |
foreach value [split $lvl2_serialized_value $sub2_sepa] { |
| 2199 |
lappend lvl2_structured_value [string map $char_unmap_list\ |
| 2200 |
$value] |
| 2201 |
} |
| 2202 |
} |
| 2203 |
lappend lvl1_strutured_value $lvl2_structured_value |
| 2204 |
} |
| 2205 |
lappend structured_value_list $lvl1_strutured_value |
| 2206 |
} |
| 2207 |
return $structured_value_list |
| 2208 |
} |
| 2209 |
|
| 2210 |
proc unserialize1LvlModulePropertyValueList {serialized_value_list\ |
| 2211 |
char_unmap_list} { |
| 2212 |
set structured_value_list {} |
| 2213 |
set sub1_sepa [getState sub1_separator] |
| 2214 |
foreach serialized_value $serialized_value_list { |
| 2215 |
set structured_value {} |
| 2216 |
foreach value [split $serialized_value $sub1_sepa] { |
| 2217 |
if {[string length $value]} { |
| 2218 |
lappend structured_value [string map $char_unmap_list $value] |
| 2219 |
} |
| 2220 |
} |
| 2221 |
# ignore empty element (1 is meaningless as first elt is loaded mod) |
| 2222 |
if {[llength $structured_value] > 1} { |
| 2223 |
lappend structured_value_list $structured_value |
| 2224 |
} |
| 2225 |
} |
| 2226 |
return $structured_value_list |
| 2227 |
} |
| 2228 |
|
| 2229 |
proc unserialize0LvlModulePropertyValueList {serialized_value_list\ |
| 2230 |
char_unmap_list} { |
| 2231 |
set value_list {} |
| 2232 |
foreach serialized_value $serialized_value_list { |
| 2233 |
if {[string length $serialized_value]} { |
| 2234 |
lappend value_list [string map $char_unmap_list $serialized_value] |
| 2235 |
} |
| 2236 |
} |
| 2237 |
return $value_list |
| 2238 |
|
| 2239 |
} |
| 2240 |
|
| 2241 |
# get current loaded state to record it as the virtual init collection |
| 2242 |
proc getLoadedInit {} { |
| 2243 |
set ret [formatCollectionContent [getModulePathList returnempty 0]\ |
| 2244 |
[getLoadedModuleWithVariantList]\ |
| 2245 |
[getLoadedModuleWithVariantSaveTagArrayList] {}] |
| 2246 |
|
| 2247 |
# remove ending newline in collection output |
| 2248 |
set ret [string trimright $ret \n] |
| 2249 |
|
| 2250 |
# get init state as a string that can be registered in an env var translate |
| 2251 |
# tag list separator ':' into '<' and line split '\n' into ':' |
| 2252 |
return [string map {: < \n :} $ret] |
| 2253 |
} |
| 2254 |
|
| 2255 |
# get all modules from all enabled modulepaths that matches a specification |
| 2256 |
proc getAllAvailModule {mod} { |
| 2257 |
array set mod_list {} |
| 2258 |
# search is done from lowest to greatest priority path (if result array |
| 2259 |
# content is kept later on, it will hold accurate priority information) |
| 2260 |
foreach dir [lreverse [getModulePathList]] { |
| 2261 |
array set mod_list [getModules $dir $mod 0 [list rc_defs_included]] |
| 2262 |
} |
| 2263 |
return [array names mod_list] |
| 2264 |
} |
| 2265 |
|
| 2266 |
# register conflict violation state between loaded modules |
| 2267 |
proc setModuleConflictViolation {mod modconlist} { |
| 2268 |
reportDebug "set conflict violation state for '$mod'" |
| 2269 |
set ::g_conflictViolation($mod) $modconlist |
| 2270 |
# also update violation state for loaded mod conflicting with mod |
| 2271 |
foreach lmmod $modconlist { |
| 2272 |
if {[lappendNoDup ::g_conflictViolation($lmmod) $mod]} { |
| 2273 |
reportDebug "set/update conflict violation state for '$lmmod'" |
| 2274 |
} |
| 2275 |
} |
| 2276 |
} |
| 2277 |
|
| 2278 |
# unregister conflict violation state between modules |
| 2279 |
proc unsetModuleConflictViolation {mod} { |
| 2280 |
if {[info exists ::g_conflictViolation($mod)]} { |
| 2281 |
# also update violation state for loaded mod conflicting with mod |
| 2282 |
foreach lmmod $::g_conflictViolation($mod) { |
| 2283 |
set convio [replaceFromList\ |
| 2284 |
$::g_conflictViolation($lmmod) $mod] |
| 2285 |
reportDebug "unset/update conflict violation state for '$lmmod'" |
| 2286 |
if {![llength $convio]} { |
| 2287 |
unset ::g_conflictViolation($lmmod) |
| 2288 |
} else { |
| 2289 |
set ::g_conflictViolation($lmmod) $convio |
| 2290 |
} |
| 2291 |
} |
| 2292 |
reportDebug "unset conflict violation state for '$mod'" |
| 2293 |
unset ::g_conflictViolation($mod) |
| 2294 |
} |
| 2295 |
} |
| 2296 |
|
| 2297 |
# build dependency chain between loaded modules based on registered prereqs |
| 2298 |
proc setModuleDependency {mod} { |
| 2299 |
set deplist {} |
| 2300 |
set depnpolist {} |
| 2301 |
|
| 2302 |
foreach prereq_match_aftmatch [getLoadedModulePrereqListAndLoadedMatch\ |
| 2303 |
$mod] { |
| 2304 |
set prereq_item_match_aftmatch_list [lassign $prereq_match_aftmatch\ |
| 2305 |
prereq prereq_path_list] |
| 2306 |
|
| 2307 |
set lmprelist {} |
| 2308 |
set lmnpolist {} |
| 2309 |
foreach {prereq_mod_item bef_loaded_mod_match aft_loaded_mod_match}\ |
| 2310 |
$prereq_item_match_aftmatch_list { |
| 2311 |
if {[string length $bef_loaded_mod_match]} { |
| 2312 |
lappendNoDup lmprelist $bef_loaded_mod_match |
| 2313 |
lappendNoDup lmnpolist $bef_loaded_mod_match |
| 2314 |
} else { |
| 2315 |
reportDebug "set an unmet requirement on '$prereq_mod_item' for\ |
| 2316 |
'$mod'" |
| 2317 |
lappend ::g_moduleUnmetDep($mod) $prereq_mod_item |
| 2318 |
lappend ::g_unmetDepHash($prereq_mod_item) $mod $prereq_path_list |
| 2319 |
} |
| 2320 |
|
| 2321 |
# is requirement loaded after mod (in *No Particular Order*) |
| 2322 |
if {[string length $aft_loaded_mod_match]} { |
| 2323 |
lappendNoDup lmnpolist $aft_loaded_mod_match |
| 2324 |
} |
| 2325 |
} |
| 2326 |
|
| 2327 |
switch -- [llength $lmprelist] { |
| 2328 |
0 { |
| 2329 |
# prereq not satisfied |
| 2330 |
reportDebug "set prereq violation state for '$mod'" |
| 2331 |
lappend ::g_prereqViolation($mod) $prereq |
| 2332 |
} |
| 2333 |
1 { |
| 2334 |
set lmmod [lindex $lmprelist 0] |
| 2335 |
lappend deplist [list $lmmod] |
| 2336 |
# set 'is depended by' relations |
| 2337 |
lappend ::g_dependHash($lmmod) [list $mod] |
| 2338 |
} |
| 2339 |
default { |
| 2340 |
lappend deplist $lmprelist |
| 2341 |
# many modules in prereq list, means they all set an optional dep |
| 2342 |
foreach lmmod $lmprelist { |
| 2343 |
lappend ::g_dependHash($lmmod) [list $mod 1] |
| 2344 |
} |
| 2345 |
} |
| 2346 |
} |
| 2347 |
|
| 2348 |
# build 'is depended by' relations not taking loading order into account |
| 2349 |
switch -- [llength $lmnpolist] { |
| 2350 |
0 { |
| 2351 |
# even on No Particular Order mode, prereq is not satisfied |
| 2352 |
reportDebug "set NPO prereq violation state for '$mod'" |
| 2353 |
lappend ::g_prereqNPOViolation($mod) $prereq |
| 2354 |
} |
| 2355 |
1 { |
| 2356 |
set lmmod [lindex $lmnpolist 0] |
| 2357 |
lappend depnpolist [list $lmmod] |
| 2358 |
# set 'is depended by' relations |
| 2359 |
lappend ::g_dependNPOHash($lmmod) [list $mod] |
| 2360 |
} |
| 2361 |
default { |
| 2362 |
lappend depnpolist $lmnpolist |
| 2363 |
# many modules in prereq list, means they all set an optional dep |
| 2364 |
foreach lmmod $lmnpolist { |
| 2365 |
lappend ::g_dependNPOHash($lmmod) [list $mod 1] |
| 2366 |
} |
| 2367 |
} |
| 2368 |
} |
| 2369 |
} |
| 2370 |
|
| 2371 |
# conflict not satisfied |
| 2372 |
set modconlist [getModuleLoadedConflict $mod] |
| 2373 |
if {[llength $modconlist]} { |
| 2374 |
setModuleConflictViolation $mod $modconlist |
| 2375 |
} |
| 2376 |
|
| 2377 |
# update eventual registered unmet dependencies |
| 2378 |
foreach modpre [array names ::g_unmetDepHash] { |
| 2379 |
if {[modEq $modpre $mod eqstart 1 2 1]} { |
| 2380 |
reportDebug "refresh requirements targeting '$modpre'" |
| 2381 |
foreach {lmmod prereq_path_list} $::g_unmetDepHash($modpre) { |
| 2382 |
if {![isLoadedMatchSpecificPath $mod $prereq_path_list]} { |
| 2383 |
continue |
| 2384 |
} |
| 2385 |
if {$mod in [getDependentLoadedModuleList [list $lmmod] 0 0]} { |
| 2386 |
reportDebug "skip deps refresh for '$lmmod' as dep cycle\ |
| 2387 |
detected with '$mod'" |
| 2388 |
|
| 2389 |
# remove dependency link in no particular order structs to |
| 2390 |
# avoid cycle first in 'is depended by' struct |
| 2391 |
if {[info exists ::g_dependNPOHash($mod)]} { |
| 2392 |
set depmodlist $::g_dependNPOHash($mod) |
| 2393 |
for {set i 0} {$i < [llength $depmodlist]} {incr i 1} { |
| 2394 |
if {[lindex [lindex $depmodlist $i] 0] eq $lmmod} { |
| 2395 |
set depmodlist [lreplace $depmodlist $i $i] |
| 2396 |
break |
| 2397 |
} |
| 2398 |
} |
| 2399 |
set ::g_dependNPOHash($mod) $depmodlist |
| 2400 |
reportDebug "update NPO dependent of '$mod' to\ |
| 2401 |
'$depmodlist'" |
| 2402 |
} |
| 2403 |
# then update 'depend on' struct |
| 2404 |
set lmmoddepnpolist {} |
| 2405 |
foreach depmodlist $::g_moduleNPODepend($lmmod) { |
| 2406 |
if {[set depidx [lsearch -exact $depmodlist $mod]] != -1} { |
| 2407 |
set depmodlist [lreplace $depmodlist $depidx $depidx] |
| 2408 |
# implies to update consistently alternate requirement or |
| 2409 |
# violation state if no alternative loaded |
| 2410 |
switch -- [llength $depmodlist] { |
| 2411 |
0 { |
| 2412 |
# do not know exact prereq name, so use correspond. |
| 2413 |
# loaded module matching it |
| 2414 |
lappend ::g_prereqNPOViolation($lmmod) $mod |
| 2415 |
reportDebug "set NPO prereq violation state for\ |
| 2416 |
'$lmmod'" |
| 2417 |
} |
| 2418 |
1 { |
| 2419 |
# update alternate loaded mod which became a strong |
| 2420 |
# requirement |
| 2421 |
set altmod [lindex $depmodlist 0] |
| 2422 |
set ::g_dependNPOHash($altmod) [replaceFromList\ |
| 2423 |
$::g_dependNPOHash($altmod) [list $lmmod 1]\ |
| 2424 |
$lmmod] |
| 2425 |
reportDebug "update NPO dependent of '$altmod' to\ |
| 2426 |
'$::g_dependNPOHash($altmod)'" |
| 2427 |
} |
| 2428 |
} |
| 2429 |
} |
| 2430 |
lappend lmmoddepnpolist $depmodlist |
| 2431 |
} |
| 2432 |
reportDebug "update NPO requirement of '$lmmod' to\ |
| 2433 |
'$lmmoddepnpolist'" |
| 2434 |
set ::g_moduleNPODepend($lmmod) $lmmoddepnpolist |
| 2435 |
} else { |
| 2436 |
# refresh actual dependencies of targeting mod |
| 2437 |
unsetModuleDependency $lmmod |
| 2438 |
setModuleDependency $lmmod |
| 2439 |
} |
| 2440 |
} |
| 2441 |
} |
| 2442 |
} |
| 2443 |
|
| 2444 |
# set 'depends on' relation |
| 2445 |
reportDebug "set requirements of '$mod' to '$deplist'" |
| 2446 |
set ::g_moduleDepend($mod) $deplist |
| 2447 |
reportDebug "set NPO requirements of '$mod' to '$depnpolist'" |
| 2448 |
set ::g_moduleNPODepend($mod) $depnpolist |
| 2449 |
} |
| 2450 |
|
| 2451 |
# update dependency chain when unloading module |
| 2452 |
proc unsetModuleDependency {mod} { |
| 2453 |
foreach lmmodlist $::g_moduleDepend($mod) { |
| 2454 |
set manymod [expr {[llength $lmmodlist] > 1}] |
| 2455 |
|
| 2456 |
# unset 'is depended by' mod relations |
| 2457 |
foreach lmmod $lmmodlist { |
| 2458 |
if {[info exists ::g_dependHash($lmmod)]} { |
| 2459 |
if {$manymod} { |
| 2460 |
set hashdep [list $mod 1] |
| 2461 |
} else { |
| 2462 |
set hashdep [list $mod] |
| 2463 |
} |
| 2464 |
lrem ::g_dependHash($lmmod) $hashdep |
| 2465 |
if {![llength $::g_dependHash($lmmod)]} { |
| 2466 |
unset ::g_dependHash($lmmod) |
| 2467 |
} |
| 2468 |
} |
| 2469 |
} |
| 2470 |
} |
| 2471 |
# unset mod's 'depends on' relation |
| 2472 |
reportDebug "unset requirements of '$mod'" |
| 2473 |
unset ::g_moduleDepend($mod) |
| 2474 |
|
| 2475 |
foreach lmmodlist $::g_moduleNPODepend($mod) { |
| 2476 |
set manymod [expr {[llength $lmmodlist] > 1}] |
| 2477 |
|
| 2478 |
# unset 'is depended by' mod relations |
| 2479 |
foreach lmmod $lmmodlist { |
| 2480 |
if {[info exists ::g_dependNPOHash($lmmod)]} { |
| 2481 |
if {$manymod} { |
| 2482 |
set hashdep [list $mod 1] |
| 2483 |
} else { |
| 2484 |
set hashdep [list $mod] |
| 2485 |
} |
| 2486 |
lrem ::g_dependNPOHash($lmmod) $hashdep |
| 2487 |
if {![llength $::g_dependNPOHash($lmmod)]} { |
| 2488 |
unset ::g_dependNPOHash($lmmod) |
| 2489 |
} |
| 2490 |
} |
| 2491 |
} |
| 2492 |
} |
| 2493 |
# unset mod's No Particular Order 'depends on' relation |
| 2494 |
reportDebug "unset NPO requirements of '$mod'" |
| 2495 |
unset ::g_moduleNPODepend($mod) |
| 2496 |
|
| 2497 |
# unset eventual violation states |
| 2498 |
if {[info exists ::g_prereqViolation($mod)]} { |
| 2499 |
reportDebug "unset prereq violation state for '$mod'" |
| 2500 |
unset ::g_prereqViolation($mod) |
| 2501 |
} |
| 2502 |
if {[info exists ::g_prereqNPOViolation($mod)]} { |
| 2503 |
reportDebug "unset NPO prereq violation state for '$mod'" |
| 2504 |
unset ::g_prereqNPOViolation($mod) |
| 2505 |
} |
| 2506 |
unsetModuleConflictViolation $mod |
| 2507 |
|
| 2508 |
# unset eventual registered unmet dependencies |
| 2509 |
if {[info exists ::g_moduleUnmetDep($mod)]} { |
| 2510 |
foreach ummod $::g_moduleUnmetDep($mod) { |
| 2511 |
set idx [lsearch -exact $::g_unmetDepHash($ummod) $mod] |
| 2512 |
set ::g_unmetDepHash($ummod) [lreplace $::g_unmetDepHash($ummod)\ |
| 2513 |
$idx $idx+1] |
| 2514 |
if {![llength $::g_unmetDepHash($ummod)]} { |
| 2515 |
unset ::g_unmetDepHash($ummod) |
| 2516 |
} |
| 2517 |
} |
| 2518 |
reportDebug "unset unmet requirements for '$mod'" |
| 2519 |
unset ::g_moduleUnmetDep($mod) |
| 2520 |
} |
| 2521 |
|
| 2522 |
# unset mod's 'is depended by' relations |
| 2523 |
set hashdeplist [getDirectDependentList $mod] |
| 2524 |
if {[llength $hashdeplist]} { |
| 2525 |
reportDebug "refresh dependent of '$mod'" |
| 2526 |
foreach lmmod $hashdeplist { |
| 2527 |
# refresh actual dependencies of targeting mod |
| 2528 |
unsetModuleDependency $lmmod |
| 2529 |
setModuleDependency $lmmod |
| 2530 |
} |
| 2531 |
} |
| 2532 |
} |
| 2533 |
|
| 2534 |
# get from provided loaded module list the one before and the one after |
| 2535 |
# provided loaded position. loaded before will be the lastly loaded before or |
| 2536 |
# the firstly loaded before, depending on ret_last_bef argument |
| 2537 |
proc getLoadedBeforeAndAfter {loaded_mod_list mod_idx ret_last_bef} { |
| 2538 |
set bef_mod {} |
| 2539 |
set aft_mod {} |
| 2540 |
foreach loaded_mod $loaded_mod_list { |
| 2541 |
set loaded_mod_idx [getLoadedModulePosition $loaded_mod] |
| 2542 |
# if mod is loading (idx=-1), no after mod match |
| 2543 |
# if mod has a requirement on itself, add it to the before list |
| 2544 |
if {$mod_idx == -1 || $loaded_mod_idx <= $mod_idx} { |
| 2545 |
# record first or last loaded before mod (depends on ret_last_bef) |
| 2546 |
if {![info exists bef_idx] ||\ |
| 2547 |
($ret_last_bef && $loaded_mod_idx > $bef_idx) ||\ |
| 2548 |
(!$ret_last_bef && $loaded_mod_idx < $bef_idx)} { |
| 2549 |
set bef_mod $loaded_mod |
| 2550 |
set bef_idx $loaded_mod_idx |
| 2551 |
} |
| 2552 |
} else { |
| 2553 |
# record first loaded after mod |
| 2554 |
if {![info exists aft_idx] || $loaded_mod_idx < $aft_idx} { |
| 2555 |
set aft_mod $loaded_mod |
| 2556 |
set aft_idx $loaded_mod_idx |
| 2557 |
} |
| 2558 |
} |
| 2559 |
} |
| 2560 |
return [list $bef_mod $aft_mod] |
| 2561 |
} |
| 2562 |
|
| 2563 |
# return the list of prereqs of a loaded or loading module and the associated |
| 2564 |
# loaded module corresponding to these prereq definitions. The list of each |
| 2565 |
# prereq is returned, each entry is a list of each prereq item definition |
| 2566 |
# associated to the matching module loaded prior passed mod and loaded after |
| 2567 |
proc getLoadedModulePrereqListAndLoadedMatch {mod} { |
| 2568 |
set prereq_match_aftmatch_list {} |
| 2569 |
set prereq_list [getLoadedPrereq $mod] |
| 2570 |
|
| 2571 |
set via_mod_list {} |
| 2572 |
if {[getConf require_via]} { |
| 2573 |
set modpath [getModulepathFromLoadedOrLoadingModule $mod] |
| 2574 |
set via_mod_list [getAllLoadedModuleUsingModulepath $modpath] |
| 2575 |
} |
| 2576 |
|
| 2577 |
# skip processing if no prereq defined |
| 2578 |
if {![llength $prereq_list] && ![llength $via_mod_list]} { |
| 2579 |
return |
| 2580 |
} |
| 2581 |
|
| 2582 |
set mod_idx [getLoadedModulePosition $mod] |
| 2583 |
# do we need lastly loaded before or firsly loaded before |
| 2584 |
set ret_last_bef [expr {[getConf unload_match_order] eq {returnlast}}] |
| 2585 |
|
| 2586 |
foreach prereq $prereq_list { |
| 2587 |
set prereq_path_list [getLoadedPrereqPath $mod $prereq] |
| 2588 |
set prereq_match_aftmatch [list $prereq $prereq_path_list] |
| 2589 |
|
| 2590 |
foreach prereq_mod_item $prereq { |
| 2591 |
# get all loaded modules matching requirement |
| 2592 |
set loaded_mod_match_list {} |
| 2593 |
# compare with loaded mods matching root instead of all loaded mods |
| 2594 |
foreach loaded_mod [getLoadedMatchingModroot $prereq_mod_item] { |
| 2595 |
if {[isLoadedMatchSpecificPath $loaded_mod $prereq_path_list] &&\ |
| 2596 |
[modEq $prereq_mod_item $loaded_mod eqstart 1 2 1]} { |
| 2597 |
lappend loaded_mod_match_list $loaded_mod |
| 2598 |
} |
| 2599 |
} |
| 2600 |
# find before and after matching loaded mod |
| 2601 |
lassign [getLoadedBeforeAndAfter $loaded_mod_match_list $mod_idx\ |
| 2602 |
$ret_last_bef] bef_loaded_mod_match aft_loaded_mod_match |
| 2603 |
|
| 2604 |
lappend prereq_match_aftmatch $prereq_mod_item $bef_loaded_mod_match\ |
| 2605 |
$aft_loaded_mod_match |
| 2606 |
} |
| 2607 |
|
| 2608 |
lappend prereq_match_aftmatch_list $prereq_match_aftmatch |
| 2609 |
} |
| 2610 |
|
| 2611 |
# add via module requirement if enabled and if any |
| 2612 |
if {[llength $via_mod_list]} { |
| 2613 |
lassign [getLoadedBeforeAndAfter $via_mod_list $mod_idx $ret_last_bef]\ |
| 2614 |
bef_loaded_mod_match aft_loaded_mod_match |
| 2615 |
|
| 2616 |
# use "<VIA>" string as prereq specification, this value is used for |
| 2617 |
# unsatisfied requirement, which does not exist for via requirement |
| 2618 |
lappend prereq_match_aftmatch_list [list <VIA> {} <VIA>\ |
| 2619 |
$bef_loaded_mod_match $aft_loaded_mod_match] |
| 2620 |
} |
| 2621 |
|
| 2622 |
return $prereq_match_aftmatch_list |
| 2623 |
} |
| 2624 |
|
| 2625 |
# returns if any loaded module (if passed mod is empty) or passed mod and all |
| 2626 |
# its requirement chain satisfy their loading constraints (prereq & conflict) |
| 2627 |
proc areModuleConstraintsSatisfied {{mod {}} {nporeq 0}} { |
| 2628 |
set ret 1 |
| 2629 |
|
| 2630 |
# are requirements loaded after their dependent included or not |
| 2631 |
if {$nporeq} { |
| 2632 |
set reqVioVar ::g_prereqNPOViolation |
| 2633 |
set reqListVar ::g_moduleNPODepend |
| 2634 |
} else { |
| 2635 |
set reqVioVar ::g_prereqViolation |
| 2636 |
set reqListVar ::g_moduleDepend |
| 2637 |
} |
| 2638 |
|
| 2639 |
# check if any loaded module violates its prereq or conflict constraints |
| 2640 |
##nagelfar vartype reqVioVar varName |
| 2641 |
if {$mod eq {}} { |
| 2642 |
if {[array size ::g_conflictViolation] || [array size $reqVioVar]} { |
| 2643 |
set ret 0 |
| 2644 |
} |
| 2645 |
} else { |
| 2646 |
set fulllist [list $mod] |
| 2647 |
for {set i 0} {$i < [llength $fulllist]} {incr i 1} { |
| 2648 |
set depmod [lindex $fulllist $i] |
| 2649 |
|
| 2650 |
# check if depmod violates its prereq or conflict constraints |
| 2651 |
##nagelfar ignore +2 Suspicious variable name |
| 2652 |
if {[info exists ::g_conflictViolation($depmod)] || [info exists\ |
| 2653 |
${reqVioVar}($depmod)]} { |
| 2654 |
# found violation among the requirement chain of mod so the |
| 2655 |
# constraint of mod are not satisfied |
| 2656 |
set ret 0 |
| 2657 |
break |
| 2658 |
} |
| 2659 |
# add requirements of depmod to the module to check list |
| 2660 |
##nagelfar ignore #2 Suspicious variable name |
| 2661 |
if {[info exists ${reqListVar}($depmod)]} { |
| 2662 |
foreach lmmodlist [set ${reqListVar}($depmod)] { |
| 2663 |
lappendNoDup fulllist {*}$lmmodlist |
| 2664 |
} |
| 2665 |
} |
| 2666 |
} |
| 2667 |
} |
| 2668 |
|
| 2669 |
return $ret |
| 2670 |
} |
| 2671 |
|
| 2672 |
# parse loaded modules information (should be called only once) |
| 2673 |
proc cacheCurrentModules {} { |
| 2674 |
# mark specific as well as generic modules as loaded |
| 2675 |
set i 0 |
| 2676 |
set modfilelist [getEnvLoadedModulePropertyParsedList file] |
| 2677 |
set modlist [getEnvLoadedModulePropertyParsedList name] |
| 2678 |
set refreshlist [getEnvLoadedModulePropertyParsedList refresh] |
| 2679 |
|
| 2680 |
if {[llength $modlist] == [llength $modfilelist]} { |
| 2681 |
# cache declared variant of loaded modules |
| 2682 |
foreach modvrspec [getEnvLoadedModulePropertyParsedList variant] { |
| 2683 |
setLoadedVariant {*}$modvrspec |
| 2684 |
# prepare modvr designation of loaded mod needed in next steps |
| 2685 |
set mod [lindex $modvrspec 0] |
| 2686 |
set vrlist [getVariantList $mod 6] |
| 2687 |
set modvr [list $mod {*}$vrlist] |
| 2688 |
set modvrarr($mod) $modvr |
| 2689 |
} |
| 2690 |
|
| 2691 |
# cache declared tags of loaded modules |
| 2692 |
foreach modtag [getEnvLoadedModulePropertyParsedList tag] { |
| 2693 |
set tag_list [lassign $modtag mod] |
| 2694 |
if {[info exists modvrarr($mod)]} { |
| 2695 |
set mod_with_vr $modvrarr($mod) |
| 2696 |
} else { |
| 2697 |
set mod_with_vr {} |
| 2698 |
} |
| 2699 |
setModuleAndVariantsTag $mod $mod_with_vr {*}$tag_list |
| 2700 |
} |
| 2701 |
foreach modtag [getEnvLoadedModulePropertyParsedList extratag] { |
| 2702 |
set tag_list [lassign $modtag mod] |
| 2703 |
if {[info exists modvrarr($mod)]} { |
| 2704 |
set mod_with_vr $modvrarr($mod) |
| 2705 |
} else { |
| 2706 |
set mod_with_vr {} |
| 2707 |
} |
| 2708 |
setModuleAndVariantsExtraTag $mod $mod_with_vr {*}$tag_list |
| 2709 |
} |
| 2710 |
foreach modstickyrule [getEnvLoadedModulePropertyParsedList\ |
| 2711 |
stickyrule] { |
| 2712 |
set mod [lindex $modstickyrule 0] |
| 2713 |
foreach modtagspeclist [lrange $modstickyrule 1 end] { |
| 2714 |
set modspec_list [lassign $modtagspeclist modtag] |
| 2715 |
foreach modspec $modspec_list { |
| 2716 |
lassign [parseModuleSpecification 0 0 0 0 {*}$modspec]\ |
| 2717 |
parsed_modspec |
| 2718 |
# record tag definition on given module specification |
| 2719 |
setModspecTag $parsed_modspec $modtag |
| 2720 |
} |
| 2721 |
} |
| 2722 |
} |
| 2723 |
|
| 2724 |
# cache declared alternative names of loaded modules |
| 2725 |
foreach modalt [getEnvLoadedModulePropertyParsedList altname] { |
| 2726 |
setLoadedAltname {*}$modalt |
| 2727 |
} |
| 2728 |
|
| 2729 |
# cache declared source-sh of loaded modules |
| 2730 |
foreach modsrcsh [getEnvLoadedModulePropertyParsedList sourcesh] { |
| 2731 |
setLoadedSourceSh {*}$modsrcsh |
| 2732 |
} |
| 2733 |
|
| 2734 |
# cache declared conflict of loaded modules |
| 2735 |
foreach modcon [getEnvLoadedModulePropertyParsedList conflict] { |
| 2736 |
# parse module version specification to record translation |
| 2737 |
foreach modconelt [lrange $modcon 1 end] { |
| 2738 |
parseModuleSpecification 0 0 0 0 {*}$modconelt |
| 2739 |
} |
| 2740 |
setLoadedConflict {*}$modcon |
| 2741 |
} |
| 2742 |
|
| 2743 |
# cache declared prereq of loaded modules, prior to setLoadedModule |
| 2744 |
# which triggers dependency chain build |
| 2745 |
foreach modpre [getEnvLoadedModulePropertyParsedList prereq] { |
| 2746 |
# parse module version specification to record translation |
| 2747 |
foreach modpreeltlist [lrange $modpre 1 end] { |
| 2748 |
foreach modpreelt $modpreeltlist { |
| 2749 |
parseModuleSpecification 0 0 0 0 {*}$modpreelt |
| 2750 |
} |
| 2751 |
} |
| 2752 |
setLoadedPrereq {*}$modpre |
| 2753 |
} |
| 2754 |
foreach modpre_path [getEnvLoadedModulePropertyParsedList prereqpath] { |
| 2755 |
setLoadedPrereqPath {*}$modpre_path |
| 2756 |
} |
| 2757 |
|
| 2758 |
foreach moduse [getEnvLoadedModulePropertyParsedList use] { |
| 2759 |
setLoadedUse {*}$moduse |
| 2760 |
} |
| 2761 |
|
| 2762 |
foreach mod $modlist { |
| 2763 |
# get all tags also recorded on mod and vr designation |
| 2764 |
if {[info exists modvrarr($mod)]} { |
| 2765 |
set modvr $modvrarr($mod) |
| 2766 |
} else { |
| 2767 |
set modvr {} |
| 2768 |
} |
| 2769 |
setLoadedModule $mod [lindex $modfilelist $i] [expr\ |
| 2770 |
{![isModuleTagged $mod auto-loaded 1]}] $modvr [expr {$mod in\ |
| 2771 |
$refreshlist}] 0 |
| 2772 |
incr i |
| 2773 |
} |
| 2774 |
|
| 2775 |
# all positions and mod root search structure are required prior |
| 2776 |
# building dependency chains |
| 2777 |
foreach mod $modlist { |
| 2778 |
setModuleDependency $mod |
| 2779 |
} |
| 2780 |
|
| 2781 |
reportDebug "$i loaded" |
| 2782 |
} else { |
| 2783 |
reportErrorAndExit "Loaded environment state is\ |
| 2784 |
inconsistent\nLOADEDMODULES=$modlist\n_LMFILES_=$modfilelist" |
| 2785 |
} |
| 2786 |
} |
| 2787 |
|
| 2788 |
# This proc resolves module aliases or version aliases to the real module name |
| 2789 |
# and version. |
| 2790 |
proc resolveModuleVersionOrAlias {name icase} { |
| 2791 |
set name [getArrayKey ::g_moduleResolved $name $icase] |
| 2792 |
if {[info exists ::g_moduleResolved($name)]} { |
| 2793 |
set ret $::g_moduleResolved($name) |
| 2794 |
} else { |
| 2795 |
set ret $name |
| 2796 |
} |
| 2797 |
|
| 2798 |
reportTrace "'$name' into '$ret'" Resolve |
| 2799 |
return $ret |
| 2800 |
} |
| 2801 |
|
| 2802 |
proc parseAccessIssue {modfile} { |
| 2803 |
# retrieve and return access issue message |
| 2804 |
if {[regexp {POSIX .* \{(.*)\}$} $::errorCode match errMsg]} { |
| 2805 |
return "[string totitle $errMsg] on '$modfile'" |
| 2806 |
} else { |
| 2807 |
return "Cannot access '$modfile'" |
| 2808 |
} |
| 2809 |
} |
| 2810 |
|
| 2811 |
proc checkValidModule {modfile} { |
| 2812 |
# test file only once, cache result obtained to minimize file query |
| 2813 |
# consider modfile valid without reading it if mcookie_check < always |
| 2814 |
return [expr {[info exists ::g_modfileValid($modfile)]\ |
| 2815 |
? $::g_modfileValid($modfile)\ |
| 2816 |
: [set ::g_modfileValid($modfile) [expr {[getConf mcookie_check] eq\ |
| 2817 |
{always} ? [getModuleValidy $modfile] : [list true {}]}]]}] |
| 2818 |
} |
| 2819 |
|
| 2820 |
# get file modification time, cache it at first query, use cache afterward |
| 2821 |
proc getFileMtime {fpath} { |
| 2822 |
if {[info exists ::g_fileMtime($fpath)]} { |
| 2823 |
return $::g_fileMtime($fpath) |
| 2824 |
} else { |
| 2825 |
# protect 'file mtime' call in case we do not know what we are checking |
| 2826 |
# when mcookie is not checked |
| 2827 |
if {[catch { |
| 2828 |
set mtime [file mtime $fpath] |
| 2829 |
} errMsg ]} { |
| 2830 |
reportError [parseAccessIssue $fpath] |
| 2831 |
set mtime {} |
| 2832 |
} |
| 2833 |
return [set ::g_fileMtime($fpath) $mtime] |
| 2834 |
} |
| 2835 |
} |
| 2836 |
|
| 2837 |
# define proc that will be used as fallback to command provided by extension |
| 2838 |
# library in case this library is not loaded |
| 2839 |
proc __readFile {filename {firstline 0} {must_have_cookie 0}} { |
| 2840 |
set fid [open $filename r] |
| 2841 |
if {$firstline} { |
| 2842 |
set fdata [gets $fid] |
| 2843 |
} else { |
| 2844 |
# read a first data chunk and check if magic cookie is there if |
| 2845 |
# mandatory. skip read of any additional content if mandatory cookie is |
| 2846 |
# not found |
| 2847 |
set fdata [read $fid 4096] |
| 2848 |
if {![eof $fid] && (!$must_have_cookie || [string equal -length 8\ |
| 2849 |
$fdata {#%Module}])} { |
| 2850 |
append fdata [read $fid] |
| 2851 |
} |
| 2852 |
} |
| 2853 |
close $fid |
| 2854 |
return $fdata |
| 2855 |
} |
| 2856 |
|
| 2857 |
proc getModuleValidy {modfile} { |
| 2858 |
if {[catch {lassign [getModuleHeaderAndContent $modfile 1] header}]} { |
| 2859 |
set msg [parseAccessIssue $modfile] |
| 2860 |
set valid accesserr |
| 2861 |
} else { |
| 2862 |
lassign [getModuleHeaderValidity $header] valid msg |
| 2863 |
} |
| 2864 |
return [list $valid $msg] |
| 2865 |
} |
| 2866 |
|
| 2867 |
proc getModuleHeaderAndContent {modfile {only_get_header 0}} { |
| 2868 |
if {[info exists ::g_modfileContent($modfile)]} { |
| 2869 |
set res $::g_modfileContent($modfile) |
| 2870 |
} else { |
| 2871 |
# only read beginning of file if just checking validity and not asked to |
| 2872 |
# always fully read files. when full file should be read cookie is |
| 2873 |
# checked if asked to avoid to fully read non modfile |
| 2874 |
set content [readFile $modfile [expr {$only_get_header &&\ |
| 2875 |
![currentState always_read_full_file]}] 1] |
| 2876 |
# extract magic cookie (first word of modulefile) |
| 2877 |
set header [string trimright [lindex [split [string range $content 0\ |
| 2878 |
32]] 0] #] |
| 2879 |
set res [list $header $content] |
| 2880 |
# cache full file read to minimize file operations |
| 2881 |
if {!$only_get_header || [currentState always_read_full_file]} { |
| 2882 |
set ::g_modfileContent($modfile) $res |
| 2883 |
} |
| 2884 |
} |
| 2885 |
return $res |
| 2886 |
} |
| 2887 |
|
| 2888 |
proc getModuleHeaderValidity {header} { |
| 2889 |
if {![string equal -length 8 $header {#%Module}]} { |
| 2890 |
set msg {Magic cookie '#%Module' missing} |
| 2891 |
set valid invalid |
| 2892 |
# check if specified min version requirement is met |
| 2893 |
} elseif {[string length $header] > 8 && [getConf mcookie_version_check]\ |
| 2894 |
&& [versioncmp [getState modules_release] [string range $header 8 end]]\ |
| 2895 |
< 0} { |
| 2896 |
set msg "Modulefile requires at least Modules version [string range\ |
| 2897 |
$header 8 end]" |
| 2898 |
set valid invalid |
| 2899 |
} else { |
| 2900 |
set msg {} |
| 2901 |
set valid true |
| 2902 |
} |
| 2903 |
return [list $valid $msg] |
| 2904 |
} |
| 2905 |
|
| 2906 |
proc getModuleContent {mod_file} { |
| 2907 |
if {[catch {lassign [getModuleHeaderAndContent $mod_file] mod_header\ |
| 2908 |
mod_content}]} { |
| 2909 |
error [parseAccessIssue $mod_file] {} MODULES_ERR_READ |
| 2910 |
} |
| 2911 |
# raise error if module is not valid |
| 2912 |
lassign [getModuleHeaderValidity $mod_header] mod_valid valid_msg |
| 2913 |
if {$mod_valid ne {true}} { |
| 2914 |
error $valid_msg {} MODULES_ERR_VALIDITY |
| 2915 |
} |
| 2916 |
return $mod_content |
| 2917 |
} |
| 2918 |
|
| 2919 |
# If given module maps to default or other symbolic versions, a list of |
| 2920 |
# those versions is returned. This takes module/version as an argument. |
| 2921 |
proc getVersAliasList {mod} { |
| 2922 |
set sym_list {} |
| 2923 |
if {[info exists ::g_symbolHash($mod)]} { |
| 2924 |
set sym_list $::g_symbolHash($mod) |
| 2925 |
# withdraw hidden symbol from list |
| 2926 |
if {[info exists ::g_hiddenSymHash($mod)]} { |
| 2927 |
lassign [getDiffBetweenList $sym_list $::g_hiddenSymHash($mod)]\ |
| 2928 |
sym_list |
| 2929 |
} |
| 2930 |
} |
| 2931 |
|
| 2932 |
reportDebug "'$mod' has symbolic version list '$sym_list'" |
| 2933 |
return $sym_list |
| 2934 |
} |
| 2935 |
|
| 2936 |
proc doesModuleHaveSym {mod} { |
| 2937 |
# is there any non-hidden symbol for mod |
| 2938 |
return [expr {[info exists ::g_symbolHash($mod)] && (![info exists\ |
| 2939 |
::g_hiddenSymHash($mod)] || [llength [lindex [getDiffBetweenList\ |
| 2940 |
$::g_symbolHash($mod) $::g_hiddenSymHash($mod)] 0]])}] |
| 2941 |
} |
| 2942 |
|
| 2943 |
# test given file path against every ignore pattern recorded: last matching |
| 2944 |
# pattern decides whether element is ignored. patterns registered from |
| 2945 |
# global or user rc files anchor at the root of the walked modulepath |
| 2946 |
proc isPathIgnored {modpath fpelt {isdir 0}} { |
| 2947 |
if {$isdir} { |
| 2948 |
# directories whose name matches ignored_dirs configuration option |
| 2949 |
# are always ignored: negated patterns cannot re-include them and |
| 2950 |
# disabling modulepath_ignore option does not withdraw them from |
| 2951 |
# this check |
| 2952 |
if {![info exists ::g_ignoredDirsArr]} { |
| 2953 |
array set ::g_ignoredDirsArr {} |
| 2954 |
foreach igndir [getConf ignored_dirs] { |
| 2955 |
set ::g_ignoredDirsArr($igndir) 1 |
| 2956 |
} |
| 2957 |
} |
| 2958 |
if {[info exists ::g_ignoredDirsArr([file tail $fpelt])]} { |
| 2959 |
return 1 |
| 2960 |
} |
| 2961 |
} else { |
| 2962 |
set tail [file tail $fpelt] |
| 2963 |
# rc files are exempt from ignore patterns as they drive the walk |
| 2964 |
# itself (a directory bearing such a name is matched like any other |
| 2965 |
# directory) |
| 2966 |
if {$tail in {.modulerc .version}} { |
| 2967 |
return 0 |
| 2968 |
} |
| 2969 |
# backup or version control files are always ignored, like |
| 2970 |
# directories matching ignored_dirs configuration option |
| 2971 |
switch -glob -- $tail { |
| 2972 |
*~ - *,v - \#*\# { |
| 2973 |
return 1 |
| 2974 |
} |
| 2975 |
} |
| 2976 |
} |
| 2977 |
if {![info exists ::g_pathIgnorePatterns] || ![getConf\ |
| 2978 |
modulepath_ignore]} { |
| 2979 |
return 0 |
| 2980 |
} |
| 2981 |
set res 0 |
| 2982 |
foreach entry $::g_pathIgnorePatterns { |
| 2983 |
lassign $entry anchor negated dironly re |
| 2984 |
if {$dironly && !$isdir} { |
| 2985 |
continue |
| 2986 |
} |
| 2987 |
if {$anchor eq {}} { |
| 2988 |
set anchor $modpath |
| 2989 |
} |
| 2990 |
# only apply pattern to elements lying below its anchor directory |
| 2991 |
set rel_start [expr {[string length $anchor] + 1}] |
| 2992 |
if {![string equal -length $rel_start $anchor/ $fpelt]} { |
| 2993 |
continue |
| 2994 |
} |
| 2995 |
if {[regexp -- $re [string range $fpelt $rel_start end]]} { |
| 2996 |
set res [expr {!$negated}] |
| 2997 |
} |
| 2998 |
} |
| 2999 |
return $res |
| 3000 |
} |
| 3001 |
|
| 3002 |
# get list of elements located in a directory passed as argument. a flag is |
| 3003 |
# set after each element to know if it is considered hidden or not. a |
| 3004 |
# fetch_dotversion argument controls whether .version file should be looked at |
| 3005 |
# in directory .proc will be used as a fallback to command provided by |
| 3006 |
# extension library |
| 3007 |
proc __getFilesInDirectory {dir fetch_dotversion} { |
| 3008 |
set dir_list [list] |
| 3009 |
|
| 3010 |
set elt_list [glob -nocomplain -directory $dir *] |
| 3011 |
|
| 3012 |
# Add each element in the current directory to the list |
| 3013 |
foreach elt $elt_list { |
| 3014 |
lappend dir_list $elt 0 |
| 3015 |
} |
| 3016 |
|
| 3017 |
# search for hidden files |
| 3018 |
foreach elt [glob -nocomplain -types hidden -directory $dir -tails *] { |
| 3019 |
switch -- $elt { |
| 3020 |
. - .. { } |
| 3021 |
.modulerc - .version { |
| 3022 |
if {($fetch_dotversion || $elt ne {.version}) && [file readable\ |
| 3023 |
$dir/$elt]} { |
| 3024 |
lappend dir_list $dir/$elt 0 |
| 3025 |
} |
| 3026 |
} |
| 3027 |
default { |
| 3028 |
lappend dir_list $dir/$elt 1 |
| 3029 |
} |
| 3030 |
} |
| 3031 |
} |
| 3032 |
|
| 3033 |
return $dir_list |
| 3034 |
} |
| 3035 |
|
| 3036 |
# check if an existing findModules cache entry matches current search by |
| 3037 |
# evaluating search ids. if an exact match cannot be found, look at saved |
| 3038 |
# searches that contains current search (superset of looked elements), extra |
| 3039 |
# elements will be filtered-out by GetModules |
| 3040 |
proc findModulesInMemCache {searchid} { |
| 3041 |
# exact same search is cached |
| 3042 |
if {[info exists ::g_foundModulesMemCache($searchid)]} { |
| 3043 |
set match_searchid $searchid |
| 3044 |
set mod_list $::g_foundModulesMemCache($searchid) |
| 3045 |
# look for a superset search |
| 3046 |
} else { |
| 3047 |
set match_searchid {} |
| 3048 |
set mod_list {} |
| 3049 |
foreach cacheid [array names ::g_foundModulesMemCache] { |
| 3050 |
# cache id acts as pattern to check if it contains current search |
| 3051 |
if {[string match $cacheid $searchid]} { |
| 3052 |
set match_searchid $cacheid |
| 3053 |
set mod_list $::g_foundModulesMemCache($cacheid) |
| 3054 |
break |
| 3055 |
} |
| 3056 |
} |
| 3057 |
} |
| 3058 |
|
| 3059 |
return [list $match_searchid $mod_list] |
| 3060 |
} |
| 3061 |
|
| 3062 |
# when 'mod_name' is 'stop_mod''s own parent directory, narrow the received |
| 3063 |
# list of this directory's element paths (rc files, already evaluated and |
| 3064 |
# withdrawn by the caller, are not part of it) down to only what is needed |
| 3065 |
# to tell whether stop_mod is the implicit 'default'/'latest' version of |
| 3066 |
# that directory: only the dictionary range from stop_mod up to either the |
| 3067 |
# first higher element that is itself valid and not hidden (stop_mod is |
| 3068 |
# then known not to be default/latest) or the highest element if none |
| 3069 |
# qualifies. List is returned untouched in any other case: this is not |
| 3070 |
# stop_mod's own directory, stop_mod does not exist in it, or it is not |
| 3071 |
# itself a valid modulefile, in which case there is nothing to optimize |
| 3072 |
proc trimElemListForStopmod {dir mod_name stop_mod elt_list} { |
| 3073 |
if {![string length $stop_mod] || $mod_name ne [file dirname\ |
| 3074 |
$stop_mod]} { |
| 3075 |
return $elt_list |
| 3076 |
} |
| 3077 |
|
| 3078 |
set stop_elt $dir/$stop_mod |
| 3079 |
if {$stop_elt ni $elt_list || [lindex [checkValidModule $stop_elt] 0]\ |
| 3080 |
ne {true}} { |
| 3081 |
return $elt_list |
| 3082 |
} |
| 3083 |
|
| 3084 |
set tail_list {} |
| 3085 |
foreach elt $elt_list { |
| 3086 |
lappend tail_list [file tail $elt] |
| 3087 |
} |
| 3088 |
|
| 3089 |
# sort this directory's plain elements and look, starting from the |
| 3090 |
# highest one down to stop_mod, for the first element that is itself |
| 3091 |
# valid and not hidden: whether or not it turns out to be stop_mod |
| 3092 |
# itself, it is this directory's true implicit default/latest, needed |
| 3093 |
# as-is by the caller to correctly resolve it for every module in this |
| 3094 |
# directory, not just stop_mod. Only the elements from that point up to |
| 3095 |
# the highest one need to be kept to reflect it, plus stop_mod's own |
| 3096 |
# element if it lies below that point |
| 3097 |
set stop_tail [file tail $stop_mod] |
| 3098 |
set sorted_tails [lsort -dictionary $tail_list] |
| 3099 |
set stop_idx [lsearch -exact $sorted_tails $stop_tail] |
| 3100 |
set top_idx $stop_idx |
| 3101 |
for {set ti [expr {[llength $sorted_tails] - 1}]} {$ti > $stop_idx}\ |
| 3102 |
{incr ti -1} { |
| 3103 |
set fp_tail [lindex $sorted_tails $ti] |
| 3104 |
set fp_elt $dir/$mod_name/$fp_tail |
| 3105 |
if {[file isdirectory $fp_elt]} { |
| 3106 |
# a nested version directory: its own validity cannot be settled |
| 3107 |
# without recursing into it, give up trying to stop early, keep |
| 3108 |
# everything untouched like usual |
| 3109 |
return $elt_list |
| 3110 |
} |
| 3111 |
if {![isPathIgnored $dir $fp_elt] && [lindex [checkValidModule\ |
| 3112 |
$fp_elt] 0] eq {true} && ![isModuleHidden $mod_name/$fp_tail\ |
| 3113 |
$stop_mod 0 $fp_elt]} { |
| 3114 |
set top_idx $ti |
| 3115 |
break |
| 3116 |
} |
| 3117 |
} |
| 3118 |
|
| 3119 |
# only keep stop_mod and highest element in returned list |
| 3120 |
set trimmed_list [list $stop_elt] |
| 3121 |
if {$top_idx > $stop_idx} { |
| 3122 |
lappend trimmed_list $dir/$mod_name/[lindex $sorted_tails $top_idx] |
| 3123 |
} |
| 3124 |
return $trimmed_list |
| 3125 |
} |
| 3126 |
|
| 3127 |
# Walk through provided list of directories and files to find modules |
| 3128 |
proc findModulesFromDirsAndFiles {dir full_list depthlvl fetch_mtime\ |
| 3129 |
res_arrname {indir_arrname {}} {hidden_listname {}} {fknown_arrname {}}\ |
| 3130 |
{dknown_arrname {}} {stop_mod {}}} { |
| 3131 |
# link to variables/arrays from upper context |
| 3132 |
upvar $res_arrname mod_list |
| 3133 |
if {$indir_arrname ne {}} { |
| 3134 |
upvar $indir_arrname modfile_indir |
| 3135 |
} |
| 3136 |
if {$hidden_listname ne {}} { |
| 3137 |
upvar $hidden_listname hidden_list |
| 3138 |
} |
| 3139 |
if {$fknown_arrname ne {}} { |
| 3140 |
upvar $fknown_arrname fknown_arr |
| 3141 |
} |
| 3142 |
if {$dknown_arrname ne {}} { |
| 3143 |
upvar $dknown_arrname dknown_arr |
| 3144 |
} |
| 3145 |
|
| 3146 |
# evaluate modulepath root rc file prior walking: it may define path |
| 3147 |
# ignore patterns and it is not part of the walked list when only the |
| 3148 |
# limited access elements from a cache file are walked down |
| 3149 |
global g_rcfilesSourced |
| 3150 |
set top_rc_file $dir/.modulerc |
| 3151 |
if {![info exists g_rcfilesSourced($top_rc_file)] && [file readable\ |
| 3152 |
$top_rc_file]} { |
| 3153 |
execute-modulerc $top_rc_file .modulerc .modulerc |
| 3154 |
set g_rcfilesSourced($top_rc_file) 1 |
| 3155 |
} |
| 3156 |
|
| 3157 |
array set mod_list {} |
| 3158 |
|
| 3159 |
# also evaluate rc files already recorded in transmitted result list |
| 3160 |
# (entries coming from an evaluated cache file): these files are not |
| 3161 |
# walked through, as readable when cache was built, but the patterns |
| 3162 |
# they may define apply to the walk down of limited access elements |
| 3163 |
foreach elt [lsort [array names mod_list]] { |
| 3164 |
if {[lindex $mod_list($elt) 0] eq {modulerc} && ![info exists\ |
| 3165 |
g_rcfilesSourced($dir/$elt)]} { |
| 3166 |
execute-modulerc $dir/$elt $elt $elt |
| 3167 |
set g_rcfilesSourced($dir/$elt) 1 |
| 3168 |
} |
| 3169 |
} |
| 3170 |
for {set i 0} {$i < [llength $full_list]} {incr i 1} { |
| 3171 |
set element [lindex $full_list $i] |
| 3172 |
set tail [file tail $element] |
| 3173 |
set modulename [getModuleNameFromModulepath $element $dir] |
| 3174 |
set parentname [file dirname $modulename] |
| 3175 |
set moddepthlvl [llength [file split $modulename]] |
| 3176 |
# check if element is a directory if we do not already know if it is a |
| 3177 |
# dir or a file from transmitted structures |
| 3178 |
set is_elt_dir [expr {[info exists dknown_arr($modulename)] ||\ |
| 3179 |
(![info exists fknown_arr($modulename)] && [file isdirectory\ |
| 3180 |
$element])}] |
| 3181 |
# skip element matching an ignore pattern as if it does not exist |
| 3182 |
if {[isPathIgnored $dir $element $is_elt_dir]} { |
| 3183 |
continue |
| 3184 |
} |
| 3185 |
if {$is_elt_dir} { |
| 3186 |
if {[catch { |
| 3187 |
set elt_list [getFilesInDirectory $element 1] |
| 3188 |
} errMsg]} { |
| 3189 |
set mod_list($modulename) [list accesserr [parseAccessIssue\ |
| 3190 |
$element] $element] |
| 3191 |
} else { |
| 3192 |
array unset elt_arr |
| 3193 |
array set elt_arr $elt_list |
| 3194 |
|
| 3195 |
# evaluate and record this directory's rc files right away |
| 3196 |
# then withdraw them from element array: the hiding or ignore |
| 3197 |
# rules they may define are needed to trim element list for |
| 3198 |
# stop_mod and to filter the elements walked next |
| 3199 |
foreach fptail {.modulerc .version} { |
| 3200 |
set fpelt $element/$fptail |
| 3201 |
if {![info exists elt_arr($fpelt)]} { |
| 3202 |
continue |
| 3203 |
} |
| 3204 |
unset elt_arr($fpelt) |
| 3205 |
# apply same depth restriction on .version files than walk |
| 3206 |
# loop recording below |
| 3207 |
if {$fptail eq {.version} && $depthlvl != 0 &&\ |
| 3208 |
($moddepthlvl + 1) != $depthlvl} { |
| 3209 |
continue |
| 3210 |
} |
| 3211 |
set fpmod $modulename/$fptail |
| 3212 |
if {![info exists g_rcfilesSourced($fpelt)]} { |
| 3213 |
execute-modulerc $fpelt $fpmod $fpmod |
| 3214 |
set g_rcfilesSourced($fpelt) 1 |
| 3215 |
} |
| 3216 |
set mod_list($fpmod) [list modulerc] |
| 3217 |
} |
| 3218 |
|
| 3219 |
# narrow element list down to what is needed to correctly tell |
| 3220 |
# whether stop_mod is the implicit default/latest version of |
| 3221 |
# this directory, when this is stop_mod's own directory (left |
| 3222 |
# untouched in any other case). Remaining element paths are |
| 3223 |
# lexically sorted, as sub-directories are fetched in the |
| 3224 |
# order they are walked in, which rc file evaluation order |
| 3225 |
# depends on |
| 3226 |
set trimmed_list [trimElemListForStopmod $dir $modulename\ |
| 3227 |
$stop_mod [lsort [array names elt_arr]]] |
| 3228 |
|
| 3229 |
# Flag hidden files among elements kept for the walk |
| 3230 |
foreach fpelt $trimmed_list { |
| 3231 |
if {$elt_arr($fpelt)} { |
| 3232 |
set hidden_list($fpelt) 1 |
| 3233 |
} |
| 3234 |
} |
| 3235 |
|
| 3236 |
# Add each element in the current directory to the list right |
| 3237 |
# after current position to walk depth-first: rc files of any |
| 3238 |
# sub-directory are this way evaluated prior those of the |
| 3239 |
# directories lying next to or deeper than this sub-directory |
| 3240 |
# (an append would lead to a breadth-first walk, evaluating |
| 3241 |
# the rc files of all first-level directories prior any |
| 3242 |
# deeper one). Tcl 8.5 requires at least one element on linsert |
| 3243 |
if {[llength $trimmed_list]} { |
| 3244 |
set full_list [linsert $full_list [expr {$i + 1}]\ |
| 3245 |
{*}$trimmed_list] |
| 3246 |
} |
| 3247 |
} |
| 3248 |
} else { |
| 3249 |
switch -glob -- $tail { |
| 3250 |
.modulerc { |
| 3251 |
# rc file has normally been evaluated when its directory |
| 3252 |
# content was fetched: evaluate it here otherwise, when it |
| 3253 |
# is walked directly (limited access rc file from cache) |
| 3254 |
if {![info exists g_rcfilesSourced($element)]} { |
| 3255 |
execute-modulerc $element $modulename $modulename |
| 3256 |
set g_rcfilesSourced($element) 1 |
| 3257 |
} |
| 3258 |
set mod_list($modulename) [list modulerc] |
| 3259 |
} |
| 3260 |
.version { |
| 3261 |
# skip .version file from different depth level than search |
| 3262 |
# targets if no in depth mode is enabled |
| 3263 |
if {$depthlvl == 0 || $moddepthlvl == $depthlvl} { |
| 3264 |
if {![info exists g_rcfilesSourced($element)]} { |
| 3265 |
execute-modulerc $element $modulename $modulename |
| 3266 |
set g_rcfilesSourced($element) 1 |
| 3267 |
} |
| 3268 |
set mod_list($modulename) [list modulerc] |
| 3269 |
} |
| 3270 |
} |
| 3271 |
.modulecache { } |
| 3272 |
default { |
| 3273 |
# skip modfile in no in depth mode search if it does not relate |
| 3274 |
# to targeted depth level and one valid modfile has already be |
| 3275 |
# found for the dirs lying at other depth level |
| 3276 |
if {$depthlvl == 0 || $moddepthlvl == $depthlvl || ![info\ |
| 3277 |
exists modfile_indir($parentname)]} { |
| 3278 |
lassign [checkValidModule $element] check_valid check_msg |
| 3279 |
switch -- $check_valid { |
| 3280 |
true { |
| 3281 |
set mtime [expr {$fetch_mtime ? [getFileMtime\ |
| 3282 |
$element] : {}}] |
| 3283 |
set mod_list($modulename) [list modulefile $mtime\ |
| 3284 |
$element] |
| 3285 |
|
| 3286 |
# a valid modfile has been found in directory |
| 3287 |
if {![info exists hidden_list($element)]} { |
| 3288 |
set modfile_indir($parentname) 1 |
| 3289 |
} |
| 3290 |
} |
| 3291 |
default { |
| 3292 |
# register check error and relative message to get it |
| 3293 |
# in case of direct access of this module element, but |
| 3294 |
# no registering in parent directory structure as |
| 3295 |
# element is not valid |
| 3296 |
set mod_list($modulename) [list $check_valid\ |
| 3297 |
$check_msg $element] |
| 3298 |
} |
| 3299 |
} |
| 3300 |
} |
| 3301 |
} |
| 3302 |
} |
| 3303 |
} |
| 3304 |
} |
| 3305 |
} |
| 3306 |
|
| 3307 |
# finds all module-related files matching mod in the module path dir. |
| 3308 |
# 'stop_mod' helps optimize the search when looking for an exact existing |
| 3309 |
# modulefile |
| 3310 |
proc findModules {dir mod depthlvl fetch_mtime {stop_mod {}}} { |
| 3311 |
reportDebug "finding '$mod' in $dir (depthlvl=$depthlvl,\ |
| 3312 |
fetch_mtime=$fetch_mtime)" |
| 3313 |
|
| 3314 |
# generated search id (for cache search/save) by compacting given args |
| 3315 |
set searchid $dir:$mod:$depthlvl:$fetch_mtime:$stop_mod |
| 3316 |
|
| 3317 |
# look at memory cache for a compatible result |
| 3318 |
lassign [findModulesInMemCache $searchid] cache_searchid cache_list |
| 3319 |
if {$cache_searchid ne {}} { |
| 3320 |
reportDebug "use cache entry '$cache_searchid'" |
| 3321 |
return $cache_list |
| 3322 |
} |
| 3323 |
|
| 3324 |
# look at modulepath cache file |
| 3325 |
lassign [findModulesInCacheFile $dir $mod $depthlvl $fetch_mtime] cache_ok\ |
| 3326 |
cache_list |
| 3327 |
if {$cache_ok} { |
| 3328 |
# record cache file findinds in memory cache |
| 3329 |
reportDebug "create cache entry '$searchid'" |
| 3330 |
set ::g_foundModulesMemCache($searchid) $cache_list |
| 3331 |
return $cache_list |
| 3332 |
} |
| 3333 |
|
| 3334 |
defineModEqStaticProc [isIcase] [getConf extended_default] $mod |
| 3335 |
|
| 3336 |
# every entries are requested |
| 3337 |
set findall [expr {$mod eq {} || $mod eq {*}}] |
| 3338 |
|
| 3339 |
# use catch protection to handle non-readable and non-existent dir |
| 3340 |
if {[catch { |
| 3341 |
set full_list {} |
| 3342 |
foreach {fpelt hid} [getFilesInDirectory $dir 0] { |
| 3343 |
set elt [file tail $fpelt] |
| 3344 |
# include any .modulerc file found at the modulepath root |
| 3345 |
if {$elt eq {.modulerc} || $findall || [modEqStatic $elt match]} { |
| 3346 |
lappend full_list $fpelt |
| 3347 |
} |
| 3348 |
} |
| 3349 |
# walk root elements in lexical order to evaluate the rc files found |
| 3350 |
# down each of them in a deterministic order (see walk loop) |
| 3351 |
set full_list [lsort $full_list] |
| 3352 |
}]} { |
| 3353 |
return {} |
| 3354 |
} |
| 3355 |
|
| 3356 |
# walk through list of dirs and files to find modules |
| 3357 |
findModulesFromDirsAndFiles $dir $full_list $depthlvl $fetch_mtime\ |
| 3358 |
mod_list {} {} {} {} $stop_mod |
| 3359 |
|
| 3360 |
reportDebug "found [array names mod_list]" |
| 3361 |
|
| 3362 |
# cache search results |
| 3363 |
reportDebug "create cache entry '$searchid'" |
| 3364 |
set found_list [array get mod_list] |
| 3365 |
set ::g_foundModulesMemCache($searchid) $found_list |
| 3366 |
|
| 3367 |
return $found_list |
| 3368 |
} |
| 3369 |
|
| 3370 |
proc getModules {dir {mod {}} {fetch_mtime 0} {search {}} {filter {}}} { |
| 3371 |
global g_sourceAlias g_sourceVersion g_sourceVirtual g_rcAlias\ |
| 3372 |
g_moduleAlias g_rcVersion g_moduleVersion g_rcVirtual g_moduleVirtual |
| 3373 |
|
| 3374 |
reportDebug "get '$mod' in $dir (fetch_mtime=$fetch_mtime, search=$search,\ |
| 3375 |
filter=$filter)" |
| 3376 |
|
| 3377 |
# generated search id (for cache search/save) by compacting given args |
| 3378 |
set searchid $dir:$mod:$fetch_mtime:$search:$filter |
| 3379 |
|
| 3380 |
# look at memory cache for a compatible result |
| 3381 |
if {[info exists ::g_gotModulesMemCache($searchid)]} { |
| 3382 |
reportDebug "use cache entry '$searchid'" |
| 3383 |
return $::g_gotModulesMemCache($searchid) |
| 3384 |
} |
| 3385 |
|
| 3386 |
# extract one module name from query |
| 3387 |
set modqe [getOneModuleFromVersSpec $mod] |
| 3388 |
|
| 3389 |
# perform an in depth search or not |
| 3390 |
set indepth [expr {{noindepth} ni $search}] |
| 3391 |
|
| 3392 |
# set a default if none defined on directory entries |
| 3393 |
set implicitdfl [getConf implicit_default] |
| 3394 |
|
| 3395 |
# automatically define latest and default sym for all modules |
| 3396 |
# disable when implicit default or advanced version spec are disabled or |
| 3397 |
# if search query does not contain a module name and version but variant |
| 3398 |
set autosymbol [expr {$implicitdfl && [getConf advanced_version_spec] &&\ |
| 3399 |
![isSpecWildWithVariant $mod]}] |
| 3400 |
|
| 3401 |
# match passed name against any part of avail module names |
| 3402 |
set contains [expr {{contains} in $search}] |
| 3403 |
set mtest [expr {$contains ? {matchin} : {match}}] |
| 3404 |
|
| 3405 |
set icase [isIcase] |
| 3406 |
|
| 3407 |
set wild [expr {{wild} in $search}] |
| 3408 |
|
| 3409 |
# will only keep default or latest elts in the end or remove plain dirs |
| 3410 |
set filtering [expr {$filter eq {noplaindir}}] |
| 3411 |
set keeping [expr {!$filtering && $filter ne {}}] |
| 3412 |
|
| 3413 |
# check search query string corresponds to directory |
| 3414 |
set querydir [string trimright $modqe *] |
| 3415 |
set isquerydir [expr {[string index $querydir end] eq {/}}] |
| 3416 |
set querydir [string trimright $querydir /] |
| 3417 |
set querydepth [countChar $modqe /] |
| 3418 |
|
| 3419 |
# get directory relative to module name |
| 3420 |
set moddir [getModuleNameFromVersSpec $mod] |
| 3421 |
set hasmoddir [expr {$moddir ne {.}}] |
| 3422 |
set modroot [getModuleRootFromVersSpec $mod] |
| 3423 |
|
| 3424 |
# get all in case of contains search or if provided-aliases are included |
| 3425 |
set find_all [expr {$contains || [isEltInReport provided-alias 0]}] |
| 3426 |
|
| 3427 |
set earlyfilter [expr {!$find_all && !$wild && $modroot eq [string\ |
| 3428 |
map {* {} ? {}} $modroot]}] |
| 3429 |
|
| 3430 |
# are result entries gathered in a resolution context ? |
| 3431 |
set resctx [expr {{resolve} in $search}] |
| 3432 |
|
| 3433 |
# need to perform an extra match search? |
| 3434 |
set ems_required [isExtraMatchSearchRequired $mod] |
| 3435 |
|
| 3436 |
# if search for global or user rc alias only, no dir lookup is performed |
| 3437 |
# and aliases from g_rcAlias are returned |
| 3438 |
if {{rc_alias_only} in $search} { |
| 3439 |
set add_rc_defs 1 |
| 3440 |
array set found_list {} |
| 3441 |
} else { |
| 3442 |
# an exact 'name/version' query (no wildcard/contains, no result |
| 3443 |
# filtering), possibly along with a variant or an extra match search |
| 3444 |
# specifier, resolved in a single-module context (unlike a listing |
| 3445 |
# one, e.g. avail/whatis/search) lets findModules shortcut its |
| 3446 |
# directory search (see there); left empty in any other case |
| 3447 |
set stop_mod {} |
| 3448 |
set modnamevers [getModuleNameAndVersFromVersSpec $mod] |
| 3449 |
if {$resctx && $earlyfilter && $filter eq {} && [getCmpSpecFromVersSpec\ |
| 3450 |
$mod] eq {eq} && $querydepth == 1} { |
| 3451 |
set stop_mod $modnamevers |
| 3452 |
} |
| 3453 |
|
| 3454 |
# find modules by searching mod root name in order to catch all module |
| 3455 |
# related entries to correctly computed auto symbols afterward |
| 3456 |
|
| 3457 |
if {$find_all} { |
| 3458 |
set findmod * |
| 3459 |
} else { |
| 3460 |
set findmod $modroot |
| 3461 |
# if searched mod is an empty or flat element append wildcard |
| 3462 |
# character to match anything starting with mod |
| 3463 |
if {$wild && !$hasmoddir && [string index $findmod end] ne {*}} { |
| 3464 |
append findmod * |
| 3465 |
} |
| 3466 |
} |
| 3467 |
|
| 3468 |
# add alias/version definitions from global or user rc to result |
| 3469 |
set add_rc_defs [expr {{rc_defs_included} in $search}] |
| 3470 |
|
| 3471 |
# if no indepth mode search, pass the depth level of the search query |
| 3472 |
# unless EMS need to be performed (findModules should fetch everything) |
| 3473 |
set depthlvl [expr {$indepth || $ems_required ? 0 : $querydepth + 1}] |
| 3474 |
|
| 3475 |
array set found_list [findModules $dir $findmod $depthlvl\ |
| 3476 |
$fetch_mtime $stop_mod] |
| 3477 |
} |
| 3478 |
|
| 3479 |
# Phase #1: consolidate every kind of entries (directory, modulefile, |
| 3480 |
# symbolic version, alias and virtual module) in found_list |
| 3481 |
|
| 3482 |
array set err_list {} |
| 3483 |
array set versmod_list {} |
| 3484 |
|
| 3485 |
# no need to process entries in a sorted order here anymore, as rc files |
| 3486 |
# are not evaluated in this loop but during modulepath walk (they are |
| 3487 |
# still returned by findModules as cachebuild and lint sub-commands need |
| 3488 |
# them) |
| 3489 |
foreach elt [array names found_list] { |
| 3490 |
switch -- [lindex $found_list($elt) 0] { |
| 3491 |
modulerc { |
| 3492 |
# withdraw already evaluated rc files |
| 3493 |
unset found_list($elt) |
| 3494 |
} |
| 3495 |
modulefile { |
| 3496 |
} |
| 3497 |
default { |
| 3498 |
# flag entries with error |
| 3499 |
set err_list($elt) 1 |
| 3500 |
} |
| 3501 |
} |
| 3502 |
} |
| 3503 |
|
| 3504 |
# add all versions found when parsing .version or .modulerc files in this |
| 3505 |
# directory or in global or user rc definitions |
| 3506 |
foreach vers [array names g_moduleVersion] { |
| 3507 |
set versmod $g_moduleVersion($vers) |
| 3508 |
if {($dir ne {} && [string first $dir/ $g_sourceVersion($vers)] == 0)\ |
| 3509 |
|| [info exists g_rcVersion($vers)]} { |
| 3510 |
set found_list($vers) [list version $versmod] |
| 3511 |
|
| 3512 |
# build module symbol list |
| 3513 |
lappend versmod_list($versmod) $vers |
| 3514 |
} |
| 3515 |
} |
| 3516 |
|
| 3517 |
# add aliases found when parsing .version or .modulerc files in this |
| 3518 |
# directory (skip aliases not registered from this directory except if |
| 3519 |
# global or user rc definitions should be included) |
| 3520 |
foreach alias [array names g_moduleAlias] { |
| 3521 |
if {($dir ne {} && [string first $dir/ $g_sourceAlias($alias)] == 0)\ |
| 3522 |
|| ($add_rc_defs && [info exists g_rcAlias($alias)])} { |
| 3523 |
##nagelfar ignore Found constant |
| 3524 |
set found_list($alias) [list alias $g_moduleAlias($alias)] |
| 3525 |
} |
| 3526 |
} |
| 3527 |
|
| 3528 |
# add virtual mods found when parsing .version or .modulerc files in this |
| 3529 |
# directory (skip virtual mods not registered from this directory except if |
| 3530 |
# global or user rc definitions should be included) |
| 3531 |
foreach virt [array names g_moduleVirtual] { |
| 3532 |
if {($dir ne {} && [string first $dir/ $g_sourceVirtual($virt)] == 0)\ |
| 3533 |
|| ($add_rc_defs && [info exists g_rcVirtual($virt)])} { |
| 3534 |
lassign [checkValidModule $g_moduleVirtual($virt)] check_valid\ |
| 3535 |
check_msg |
| 3536 |
switch -- $check_valid { |
| 3537 |
true { |
| 3538 |
set mtime [expr {$fetch_mtime ? [getFileMtime\ |
| 3539 |
$g_moduleVirtual($virt)] : {}}] |
| 3540 |
# set mtime at index 1 like a modulefile entry |
| 3541 |
set found_list($virt) [list virtual $mtime\ |
| 3542 |
$g_moduleVirtual($virt)] |
| 3543 |
} |
| 3544 |
default { |
| 3545 |
# register check error and relative message to get it in |
| 3546 |
# case of direct access of this module element |
| 3547 |
set found_list($virt) [list $check_valid $check_msg\ |
| 3548 |
$g_moduleVirtual($virt)] |
| 3549 |
set err_list($virt) 1 |
| 3550 |
} |
| 3551 |
} |
| 3552 |
} |
| 3553 |
} |
| 3554 |
|
| 3555 |
# Phase #2: early filtering of non-matching elements |
| 3556 |
|
| 3557 |
if {$earlyfilter} { |
| 3558 |
foreach elt [array names found_list] { |
| 3559 |
if {![modEq $modroot $elt eqstart]} { |
| 3560 |
unset found_list($elt) |
| 3561 |
} |
| 3562 |
} |
| 3563 |
} |
| 3564 |
|
| 3565 |
# Phase #3: scan modulefiles if extra match search is needed |
| 3566 |
|
| 3567 |
if {$ems_required} { |
| 3568 |
scanExtraMatchSearch $dir $mod found_list |
| 3569 |
if {[isEltInReport provided-alias 0]} { |
| 3570 |
insertProvidedAliases $dir found_list |
| 3571 |
} |
| 3572 |
} |
| 3573 |
|
| 3574 |
# Phase #4: filter-out dynamically hidden or expired elements |
| 3575 |
|
| 3576 |
# define module name and version comparison procs |
| 3577 |
defineModEqStaticProc $icase [getConf extended_default] $mod |
| 3578 |
|
| 3579 |
# remove hidden elements unless they are (or their symbols) targeted by |
| 3580 |
# search query. |
| 3581 |
foreach elt [array names found_list] { |
| 3582 |
if {[lassign [isModuleHidden $elt $mod 1 [lindex $found_list($elt) 2]]\ |
| 3583 |
hidlvl hidmatch hidbydef]} { |
| 3584 |
# is there a symbol that matches query (bare module name query |
| 3585 |
# matches default symbol on resolve context or if onlydefaults filter |
| 3586 |
# is applied) |
| 3587 |
if {!$hidmatch && [info exists versmod_list($elt)]} { |
| 3588 |
foreach eltsym $versmod_list($elt) { |
| 3589 |
if {[modEqStatic $eltsym] || (($resctx || $filter eq\ |
| 3590 |
{onlydefaults}) && "$mod/default" eq $eltsym)} { |
| 3591 |
set hidmatch 1 |
| 3592 |
break |
| 3593 |
} |
| 3594 |
} |
| 3595 |
} |
| 3596 |
# consider 'default' symbols are explicitly specified if |
| 3597 |
# onlydefaults filter applied or resolving bare module name |
| 3598 |
if {!$hidmatch && [lindex $found_list($elt) 0] eq {version} && [file\ |
| 3599 |
tail $elt] eq {default} && ($filter eq {onlydefaults} || ($resctx\ |
| 3600 |
&& "$mod/default" eq $elt))} { |
| 3601 |
set hidmatch 1 |
| 3602 |
} |
| 3603 |
|
| 3604 |
# not hidden if matched unless if hard hiding apply |
| 3605 |
if {!$hidmatch || $hidlvl > 1} { |
| 3606 |
# record hidden symbol, not to display it in listModules |
| 3607 |
if {[lindex $found_list($elt) 0] eq {version}} { |
| 3608 |
lappend ::g_hiddenSymHash([lindex $found_list($elt) 1]) [file\ |
| 3609 |
tail $elt] |
| 3610 |
} |
| 3611 |
# transform forbidden module in error entry if it specifically |
| 3612 |
# matches search query |
| 3613 |
if {$hidlvl == 2 && $hidmatch && [isModuleTagged $elt forbidden 0\ |
| 3614 |
$dir/$elt]} { |
| 3615 |
set found_list($elt) [list accesserr [getForbiddenMsg $elt\ |
| 3616 |
$dir/$elt]] |
| 3617 |
set err_list($elt) 1 |
| 3618 |
} else { |
| 3619 |
unset found_list($elt) |
| 3620 |
} |
| 3621 |
} |
| 3622 |
} |
| 3623 |
# apply hidden tag if an hidden definition apply to module |
| 3624 |
if {$hidbydef} { |
| 3625 |
setModuleTag $elt hidden |
| 3626 |
} |
| 3627 |
} |
| 3628 |
|
| 3629 |
# Phase #5: elaborate directory content with default element selection |
| 3630 |
|
| 3631 |
array set dir_list {} |
| 3632 |
array set autosym_list {} |
| 3633 |
|
| 3634 |
# build list of elements contained in each directory |
| 3635 |
foreach elt [array names found_list] { |
| 3636 |
# add a ref to element in its parent directory unless element has error |
| 3637 |
# or is a symbolic version then recursively add parent element until |
| 3638 |
# reaching top directory |
| 3639 |
if {![info exists err_list($elt)] && [lindex $found_list($elt) 0] ne\ |
| 3640 |
{version}} { |
| 3641 |
set direlt $elt |
| 3642 |
while {[set pardir [file dirname $direlt]] ne {.}} { |
| 3643 |
lappendNoDup dir_list($pardir) [file tail $direlt] |
| 3644 |
set direlt $pardir |
| 3645 |
} |
| 3646 |
} |
| 3647 |
} |
| 3648 |
|
| 3649 |
# determine default element for each directory and record sorted elt list |
| 3650 |
# unless if an alias or a virtual module has overwritten directory entry |
| 3651 |
# but override alias entry if extra match search is required (as it |
| 3652 |
# withdrawn module aliases) |
| 3653 |
foreach elt [array names dir_list] { |
| 3654 |
if {![info exists found_list($elt)] || ($ems_required && [lindex\ |
| 3655 |
$found_list($elt) 0] eq {alias})} { |
| 3656 |
set dir_list($elt) [lsort -dictionary $dir_list($elt)] |
| 3657 |
# get default element: explicitly defined default (whether it exists |
| 3658 |
# or is in error) or implicit default if enabled |
| 3659 |
if {[info exists found_list($elt/default)] && [lindex\ |
| 3660 |
$found_list($elt/default) 0] eq {version}} { |
| 3661 |
set dfl [file tail [lindex $found_list($elt/default) 1]] |
| 3662 |
} elseif {$implicitdfl} { |
| 3663 |
set dfl [lindex $dir_list($elt) end] |
| 3664 |
} else { |
| 3665 |
set dfl {} |
| 3666 |
} |
| 3667 |
# record directory properties |
| 3668 |
set found_list($elt) [list directory $dfl {*}$dir_list($elt)] |
| 3669 |
|
| 3670 |
# automatically define symbols for all modules matching query if |
| 3671 |
# these names do not exist yet or if in error, in which case only |
| 3672 |
# auto symbol resolution is set |
| 3673 |
if {$autosymbol && (!$hasmoddir || [modEq $modroot $elt eqstart])} { |
| 3674 |
if {![info exists found_list($elt/default)] || [info exists\ |
| 3675 |
err_list($elt/default)]} { |
| 3676 |
if {![info exists found_list($elt/default)]} { |
| 3677 |
set found_list($elt/default) [list version $elt/$dfl] |
| 3678 |
lappend versmod_list($elt/$dfl) $elt/default |
| 3679 |
set autosym_list($elt/default) 1 |
| 3680 |
} |
| 3681 |
setModuleResolution $elt/default $elt/$dfl default 1 1 |
| 3682 |
} |
| 3683 |
if {![info exists found_list($elt/latest)] || [info exists\ |
| 3684 |
err_list($elt/latest)]} { |
| 3685 |
set lat [lindex $dir_list($elt) end] |
| 3686 |
if {![info exists found_list($elt/latest)]} { |
| 3687 |
set found_list($elt/latest) [list version $elt/$lat] |
| 3688 |
lappend versmod_list($elt/$lat) $elt/latest |
| 3689 |
set autosym_list($elt/latest) 1 |
| 3690 |
} |
| 3691 |
setModuleResolution $elt/latest $elt/$lat latest 1 1 |
| 3692 |
} |
| 3693 |
} |
| 3694 |
} |
| 3695 |
} |
| 3696 |
|
| 3697 |
# Phase #6: perform extra match search filtering |
| 3698 |
|
| 3699 |
if {$ems_required} { |
| 3700 |
filterExtraMatchSearch $dir $mod found_list versmod_list |
| 3701 |
} |
| 3702 |
|
| 3703 |
# Phase #7: filter results to keep those matching search query |
| 3704 |
|
| 3705 |
# define module name and version comparison procs |
| 3706 |
defineDoesModMatchAtDepthProc $contains $querydepth $mtest |
| 3707 |
|
| 3708 |
# element to include in output |
| 3709 |
set report_indesym [isEltInReport indesym 0] |
| 3710 |
set report_dirwsym [expr {!$report_indesym && [isEltInReport dirwsym]}] |
| 3711 |
|
| 3712 |
array set mod_list {} |
| 3713 |
array set fdir_list {} |
| 3714 |
array set keep_list {} |
| 3715 |
|
| 3716 |
# keep element matching query, add directory of element matching query, |
| 3717 |
# also add directory to result if query name finishes with trailing slash; |
| 3718 |
# only keep auto syms if fully matched or version not specified in query; |
| 3719 |
# (hidden elements have been filtered on phase 2) |
| 3720 |
foreach elt [array names found_list] { |
| 3721 |
set elt_type [lindex $found_list($elt) 0] |
| 3722 |
if {(($wild && [doesModMatchAtDepth $elt]) || (!$wild && ([modEqStatic\ |
| 3723 |
$elt match /*] || [modEqStatic $elt match] || ($hasmoddir &&\ |
| 3724 |
$elt_type eq {directory} && [modEq $moddir $elt]))) || ($isquerydir\ |
| 3725 |
&& $elt_type eq {directory} && [modEq $querydir $elt match 0])) &&\ |
| 3726 |
(![info exists autosym_list($elt)] || ([countChar $elt /]\ |
| 3727 |
!= $querydepth && !$contains) || [modEqStatic $elt]) && ![info\ |
| 3728 |
exists mod_list($elt)]} { |
| 3729 |
if {$elt_type eq {directory}} { |
| 3730 |
# add matching directory to the result list, its entries will be |
| 3731 |
# computed in a second time and directory will be dropped if it |
| 3732 |
# has no entry in the end |
| 3733 |
set mod_list($elt) [list directory] |
| 3734 |
# add dir to the filter dir list to enable its removal in next |
| 3735 |
# step if dir is empty |
| 3736 |
if {![info exists fdir_list($elt)]} { |
| 3737 |
set fdir_list($elt) {} |
| 3738 |
} |
| 3739 |
} else { |
| 3740 |
set mod_list($elt) $found_list($elt) |
| 3741 |
} |
| 3742 |
|
| 3743 |
# version may matches query but not its target, so it should be in |
| 3744 |
# this case manually added to result (if it exists and unless if |
| 3745 |
# versions should be reported independently) |
| 3746 |
if {$elt_type eq {version} && !$report_indesym} { |
| 3747 |
# resolve eventual icase target |
| 3748 |
set versmod [getArrayKey found_list [lindex $mod_list($elt) 1]\ |
| 3749 |
$icase] |
| 3750 |
# add target to dir struct (not version) if not already recorded |
| 3751 |
set direlt . |
| 3752 |
|
| 3753 |
# recursively add targets to result (process directory content if |
| 3754 |
# target is a directory |
| 3755 |
set tgt_list [list $versmod] |
| 3756 |
for {set i 0} {$i < [llength $tgt_list]} {incr i} { |
| 3757 |
set tgt [lindex $tgt_list $i] |
| 3758 |
|
| 3759 |
if {![info exists mod_list($tgt)]} { |
| 3760 |
if {[info exists found_list($tgt)]} { |
| 3761 |
set mod_list($tgt) $found_list($tgt) |
| 3762 |
# version target is directory: recursively add content |
| 3763 |
if {[lindex $mod_list($tgt) 0] eq {directory}} { |
| 3764 |
foreach tgtelt $dir_list($tgt) { |
| 3765 |
lappend tgt_list $tgt/$tgtelt |
| 3766 |
} |
| 3767 |
# add dir to the filter dir list to enable its removal |
| 3768 |
# in next step if dir is empty |
| 3769 |
if {![info exists fdir_list($tgt)]} { |
| 3770 |
set fdir_list($tgt) {} |
| 3771 |
} |
| 3772 |
} |
| 3773 |
} |
| 3774 |
|
| 3775 |
# record target in dir struct if part of found elts or if |
| 3776 |
# hidden but should not be in error |
| 3777 |
set pardir [file dirname $tgt] |
| 3778 |
# do not test if full path module is hidden as full path |
| 3779 |
# designation cannot be computed (target not in found_list) |
| 3780 |
if {([info exists found_list($tgt)] || ($pardir ne {.} &&\ |
| 3781 |
![info exists found_list($pardir)] && [isModuleHidden\ |
| 3782 |
$tgt $mod])) && ![info exists err_list($tgt)]} { |
| 3783 |
# create parent directory if it does not exist |
| 3784 |
if {$pardir ne {.} && ![info exists\ |
| 3785 |
found_list($pardir)]} { |
| 3786 |
set found_list($pardir) [list directory] |
| 3787 |
set mod_list($pardir) [list directory] |
| 3788 |
} |
| 3789 |
|
| 3790 |
if {$i == 0} { |
| 3791 |
set direlt $tgt |
| 3792 |
} else { |
| 3793 |
lappend fdir_list([file dirname $tgt]) [file tail\ |
| 3794 |
$tgt] |
| 3795 |
} |
| 3796 |
} |
| 3797 |
} |
| 3798 |
} |
| 3799 |
# skip adding element to directory content if in error |
| 3800 |
} elseif {[info exists err_list($elt)]} { |
| 3801 |
set direlt . |
| 3802 |
} else { |
| 3803 |
set direlt $elt |
| 3804 |
} |
| 3805 |
|
| 3806 |
# track directory content, as directory are also reported to their |
| 3807 |
# parent directory the directory structure is also tracked |
| 3808 |
if {[set pardir [file dirname $direlt]] ne {.}} { |
| 3809 |
lappend fdir_list($pardir) [file tail $direlt] |
| 3810 |
# track top level entries that will be kept if result is filtered |
| 3811 |
} elseif {$keeping && $direlt ne {.} && $elt_type ne {directory}} { |
| 3812 |
set keep_list($elt) 1 |
| 3813 |
} |
| 3814 |
} |
| 3815 |
} |
| 3816 |
|
| 3817 |
# determine default element for each directory and record sorted element |
| 3818 |
# list unless directory entry has been overwritten by a different module |
| 3819 |
# kind or unless only matching directory should be part of result |
| 3820 |
foreach elt [lsort -decreasing [array names fdir_list]] { |
| 3821 |
if {[lindex $found_list($elt) 0] eq {directory} && ([info exists\ |
| 3822 |
mod_list($elt)] || $keeping)} { |
| 3823 |
set fdir_list($elt) [lsort -dictionary $fdir_list($elt)] |
| 3824 |
# get default element: explicitly defined default if included in |
| 3825 |
# result or not found or implicit default if enabled |
| 3826 |
if {[info exists found_list($elt/default)] && [lindex\ |
| 3827 |
$found_list($elt/default) 0] eq {version} && ([info exists\ |
| 3828 |
mod_list([set versmod [lindex $found_list($elt/default) 1]])] ||\ |
| 3829 |
![info exists found_list($versmod)])} { |
| 3830 |
set dfl [file tail $versmod] |
| 3831 |
} elseif {$implicitdfl} { |
| 3832 |
set dfl [lindex $fdir_list($elt) end] |
| 3833 |
} else { |
| 3834 |
set dfl {} |
| 3835 |
} |
| 3836 |
# remove empty dirs |
| 3837 |
if {![llength $fdir_list($elt)]} { |
| 3838 |
unset mod_list($elt) |
| 3839 |
unset fdir_list($elt) |
| 3840 |
# remove unset dir reference in parent directory. parent dir |
| 3841 |
# will be treated after unset dir (due to decreasing sort) if it |
| 3842 |
# needs to get in turn unset |
| 3843 |
if {[set pardir [file dirname $elt]] ne {.}} { |
| 3844 |
lrem fdir_list($pardir) [file tail $elt] |
| 3845 |
} |
| 3846 |
} else { |
| 3847 |
# record directory properties |
| 3848 |
set mod_list($elt) [list directory $dfl {*}$fdir_list($elt)] |
| 3849 |
|
| 3850 |
# list elements to keep for filtering step |
| 3851 |
if {$keeping} { |
| 3852 |
if {$filter eq {onlylatest}} { |
| 3853 |
set keepelt $elt/[lindex $fdir_list($elt) end] |
| 3854 |
} elseif {$dfl ne {}} { |
| 3855 |
set keepelt $elt/$dfl |
| 3856 |
} else { |
| 3857 |
set keepelt {} |
| 3858 |
} |
| 3859 |
|
| 3860 |
# keep directory if its element depth is deeper than query |
| 3861 |
if {!$indepth && [countChar $keepelt /] > $querydepth} { |
| 3862 |
set keep_list($elt) 1 |
| 3863 |
# otherwise only keep existing modules (not directories) |
| 3864 |
} elseif {[info exists mod_list($keepelt)] && [lindex\ |
| 3865 |
$mod_list($keepelt) 0] ne {directory}} { |
| 3866 |
set keep_list($keepelt) 1 |
| 3867 |
} |
| 3868 |
# when noplaindir filtering, only keep dirs with syms when indepth |
| 3869 |
# enabled or if corresponds to query depth when indepth disabled |
| 3870 |
} elseif {$filtering && $filter eq {noplaindir} &&\ |
| 3871 |
(($indepth && (!$report_dirwsym || ![doesModuleHaveSym $elt]))\ |
| 3872 |
|| (!$indepth && [countChar $elt /] != $querydepth))} { |
| 3873 |
unset mod_list($elt) |
| 3874 |
} |
| 3875 |
} |
| 3876 |
} |
| 3877 |
} |
| 3878 |
|
| 3879 |
# now all matching modulefiles are settled, only keep those found at search |
| 3880 |
# query depth level if 'noindepth' mode asked |
| 3881 |
if {!$indepth} { |
| 3882 |
# remove entries with more filename path separator than query pattern |
| 3883 |
foreach elt [array names mod_list] { |
| 3884 |
if {[countChar $elt /] > $querydepth} { |
| 3885 |
unset mod_list($elt) |
| 3886 |
} |
| 3887 |
} |
| 3888 |
} |
| 3889 |
|
| 3890 |
# if result should be filtered, only keep marked elements |
| 3891 |
if {$keeping} { |
| 3892 |
foreach elt [array names mod_list] { |
| 3893 |
if {![info exists keep_list($elt)]} { |
| 3894 |
unset mod_list($elt) |
| 3895 |
} |
| 3896 |
} |
| 3897 |
} |
| 3898 |
|
| 3899 |
# Phase #6: consolidate tags set for retained modules |
| 3900 |
|
| 3901 |
# skip collecting tags if already performed for this modulepath or command |
| 3902 |
# is different than avail/spider |
| 3903 |
if {[currentState commandname] in {avail spider} && $dir ni [getState\ |
| 3904 |
tags_collected_in]} { |
| 3905 |
foreach elt [array names mod_list] { |
| 3906 |
switch -- [lindex $mod_list($elt) 0] { |
| 3907 |
alias - modulefile - virtual { |
| 3908 |
# gather all tags applying to elt |
| 3909 |
collectModuleTags $elt |
| 3910 |
} |
| 3911 |
} |
| 3912 |
} |
| 3913 |
} |
| 3914 |
|
| 3915 |
reportTrace "{[array names mod_list]} matching '$mod' in '$dir'" {Get\ |
| 3916 |
modules} |
| 3917 |
|
| 3918 |
# cache search results |
| 3919 |
reportDebug "create cache entry '$searchid'" |
| 3920 |
set got_list [array get mod_list] |
| 3921 |
set ::g_gotModulesMemCache($searchid) $got_list |
| 3922 |
|
| 3923 |
return $got_list |
| 3924 |
} |
| 3925 |
|
| 3926 |
proc getMatchingAnyModules {dir pattern_list fetch_mtime search filter} { |
| 3927 |
set mod_list {} |
| 3928 |
foreach pattern $pattern_list { |
| 3929 |
lappend mod_list {*}[getModules $dir $pattern $fetch_mtime $search\ |
| 3930 |
$filter] |
| 3931 |
} |
| 3932 |
return $mod_list |
| 3933 |
} |
| 3934 |
|
| 3935 |
# ;;; Local Variables: |
| 3936 |
# ;;; Mode: tcl-mode |
| 3937 |
# ;;; tcl-indent-level: 3 |
| 3938 |
# ;;; tcl-continued-indent-level: 3 |
| 3939 |
# ;;; indent-tabs-mode: nil |
| 3940 |
# ;;; End: |
| 3941 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |