Skip to content

Commit f41e5aa

Browse files
committed
Use requirement modpath info to compute dependencies
Use the modulepath-specific property of the requirements to correctly compute module dependencies. Especially to determine if a loaded or loading module is an actual dependency of another module. g_unmetDepHash array structure is updated to hold the specific modulepath list next to the loaded module name. Split isLoadedMatchSpecificPath to create isModulefileMatchSpecificPath procedure. Useful when working on a *not-yet loaded* context.
1 parent 6aa74aa commit f41e5aa

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

tcl/modeval.tcl

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ proc sortModulePerLoadedAndDepOrder {modlist {nporeq 0} {loading 0}} {
316316

317317
# return list of loaded modules having an unmet requirement on passed mod
318318
# and their recursive dependent
319-
proc getUnmetDependentLoadedModuleList {modnamevr} {
319+
proc getUnmetDependentLoadedModuleList {modnamevr mod_file} {
320320
set unmetdeplist {}
321321
set depmodlist {}
322322
defineModEqProc [isIcase] [getConf extended_default] 1
@@ -328,7 +328,12 @@ proc getUnmetDependentLoadedModuleList {modnamevr} {
328328
if {![llength $modconlist]} {
329329
foreach ummod [array names ::g_unmetDepHash] {
330330
if {[modEq $ummod $mod eqstart 1 2 1 $vrlist]} {
331-
foreach depmod $::g_unmetDepHash($ummod) {
331+
foreach {depmod prereq_path_list} $::g_unmetDepHash($ummod) {
332+
if {![isModulefileMatchSpecificPath $mod_file\
333+
$prereq_path_list]} {
334+
continue
335+
}
336+
332337
lappend depmodlist $depmod
333338
# temporarily remove prereq violation of depmod if mod
334339
# load solves it (no other prereq is missing)
@@ -441,11 +446,13 @@ proc getDirectDependentList {mod {strong 0} {nporeq 0} {loading 0}\
441446
}
442447
foreach loadingmod [getLoadingModuleList] {
443448
foreach prereq [getLoadedPrereq $loadingmod] {
449+
set prereq_path_list [getLoadedPrereqPath $loadingmod $prereq]
444450
set lmprelist {}
445451
set moddep 0
446452
foreach modpre $prereq {
447453
foreach lmmod $modlist {
448-
if {[modEq $modpre $lmmod eqstart 1 2 1]} {
454+
if {[isLoadedMatchSpecificPath $lmmod $prereq_path_list 0]\
455+
&& [modEq $modpre $lmmod eqstart 1 2 1]} {
449456
lappend lmprelist $lmmod
450457
if {$lmmod eq $mod} {
451458
set moddep 1
@@ -786,8 +793,9 @@ proc savePropsOfReloadingModule {mod} {
786793
set extra_tag_list [getExtraTagList $mod]
787794
set conflict_list [getLoadedConflict $mod]
788795
set prereq_list [getLoadedPrereq $mod]
796+
set prereq_path_list [getLoadedPrereqPath $mod]
789797
set ::g_savedPropsOfReloadMod($mod) [list $is_user_asked $vr_list\
790-
$tag_list $extra_tag_list $conflict_list $prereq_list]
798+
$tag_list $extra_tag_list $conflict_list $prereq_list $prereq_path_list]
791799
}
792800

793801
proc getSavedPropsOfReloadingModule {mod} {
@@ -839,15 +847,15 @@ proc reloadModuleListLoadPhase {mod_list {errmsgtpl {}} {context load}} {
839847
setConf auto_handling 0
840848
foreach mod $mod_list {
841849
lassign [getSavedPropsOfReloadingModule $mod] is_user_asked vr_list\
842-
tag_list extra_tag_list conflict_list prereq_list
850+
tag_list extra_tag_list conflict_list prereq_list prereq_path_list
843851
# if an auto set default was excluded, module spec need parsing
844852
lassign [parseModuleSpecification 0 0 0 0 $mod {*}$vr_list] modnamevr
845853

846854
# do not try to reload DepRe module if requirements are not satisfied
847855
# unless if sticky
848856
if {$context eq {depre} && ![isModuleLoadable $mod $modnamevr\
849-
$conflict_list $prereq_list] && ![isModuleStickyFromTagList\
850-
{*}$tag_list {*}$extra_tag_list]} {
857+
$conflict_list $prereq_list $prereq_path_list] &&\
858+
![isModuleStickyFromTagList {*}$tag_list {*}$extra_tag_list]} {
851859
continue
852860
}
853861

@@ -871,7 +879,8 @@ proc reloadModuleListLoadPhase {mod_list {errmsgtpl {}} {context load}} {
871879
setConf auto_handling 1
872880
}
873881

874-
proc isModuleLoadable {mod mod_vr conflict_list prereq_list} {
882+
proc isModuleLoadable {mod mod_vr conflict_list prereq_list\
883+
prereq_path_list} {
875884
setLoadedConflict $mod {*}$conflict_list
876885
set is_conflicting [llength [getModuleLoadedConflict $mod]]
877886
unsetLoadedConflict $mod
@@ -880,13 +889,20 @@ proc isModuleLoadable {mod mod_vr conflict_list prereq_list} {
880889
return 0
881890
}
882891

892+
array set prereq_path_arr $prereq_path_list
883893
foreach prereq_arg $prereq_list {
894+
if {[info exists prereq_path_arr($prereq_arg)]} {
895+
set prereq_arg_path $prereq_path_arr($prereq_arg)
896+
} else {
897+
set prereq_arg_path {}
898+
}
884899
set is_requirement_loaded 0
885900
foreach req_mod $prereq_arg {
886901
# is requirement loaded, loading or optional
887-
if {[string length [getLoadedMatchingName $req_mod returnfirst 0]]\
888-
|| [string length [getLoadedMatchingName $req_mod returnfirst\
889-
1]] || $req_mod eq $mod} {
902+
if {[string length [getLoadedMatchingName $req_mod returnfirst 0 {}\
903+
$prereq_arg_path]] || [string length [getLoadedMatchingName\
904+
$req_mod returnfirst 1 {} $prereq_arg_path]] || $req_mod eq\
905+
$mod} {
890906
set is_requirement_loaded 1
891907
break
892908
}

tcl/modfind.tcl.in

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,12 +1540,16 @@ proc getLoadedMatchingName {name {behavior {}} {loading 0} {lmlist {}}\
15401540
# return if loaded (or loading) module is part of modulepath from specified
15411541
# constrained list
15421542
proc isLoadedMatchSpecificPath {mod modulepath_list loading} {
1543+
if {$loading} {
1544+
set mod_file [getModulefileFromLoadingModule $mod]
1545+
} else {
1546+
set mod_file [getModulefileFromLoadedModule $mod]
1547+
}
1548+
return [isModulefileMatchSpecificPath $mod_file $modulepath_list]
1549+
}
1550+
1551+
proc isModulefileMatchSpecificPath {mod_file modulepath_list} {
15431552
if {[llength $modulepath_list]} {
1544-
if {$loading} {
1545-
set mod_file [getModulefileFromLoadingModule $mod]
1546-
} else {
1547-
set mod_file [getModulefileFromLoadedModule $mod]
1548-
}
15491553
return [isModulefileInModulepathList $mod_file $modulepath_list]
15501554
} else {
15511555
return 1
@@ -2050,13 +2054,15 @@ proc setModuleDependency {mod} {
20502054
set depnpolist {}
20512055

20522056
foreach prereq [getLoadedPrereq $mod] {
2057+
set prereq_path_list [getLoadedPrereqPath $mod $prereq]
20532058
# get corresponding loaded module for each element of the prereq order
20542059
set lmprelist {}
20552060
set lmnpolist {}
20562061
foreach modpre $prereq {
20572062
set lmfound {}
20582063
foreach lmmod $modlist {
2059-
if {[modEq $modpre $lmmod eqstart 1 2 1]} {
2064+
if {[isLoadedMatchSpecificPath $lmmod $prereq_path_list 0] &&\
2065+
[modEq $modpre $lmmod eqstart 1 2 1]} {
20602066
set lmfound $lmmod
20612067
break
20622068
}
@@ -2066,7 +2072,7 @@ proc setModuleDependency {mod} {
20662072
if {$lmfound eq {}} {
20672073
reportDebug "set an unmet requirement on '$modpre' for '$mod'"
20682074
lappend ::g_moduleUnmetDep($mod) $modpre
2069-
lappend ::g_unmetDepHash($modpre) $mod
2075+
lappend ::g_unmetDepHash($modpre) $mod $prereq_path_list
20702076
# add matching mod elsewhere
20712077
} else {
20722078
appendNoDupToList lmprelist $lmfound
@@ -2075,7 +2081,8 @@ proc setModuleDependency {mod} {
20752081

20762082
# look if requirement can be found in the No Particular Order list
20772083
foreach lmmod $modnpolist {
2078-
if {[modEq $modpre $lmmod eqstart 1 2 1]} {
2084+
if {[isLoadedMatchSpecificPath $lmmod $prereq_path_list 0] &&\
2085+
[modEq $modpre $lmmod eqstart 1 2 1]} {
20792086
appendNoDupToList lmnpolist $lmmod
20802087
break
20812088
}
@@ -2136,7 +2143,10 @@ proc setModuleDependency {mod} {
21362143
foreach modpre [array names ::g_unmetDepHash] {
21372144
if {[modEq $modpre $mod eqstart 1 2 1]} {
21382145
reportDebug "refresh requirements targeting '$modpre'"
2139-
foreach lmmod $::g_unmetDepHash($modpre) {
2146+
foreach {lmmod prereq_path_list} $::g_unmetDepHash($modpre) {
2147+
if {![isLoadedMatchSpecificPath $mod $prereq_path_list 0]} {
2148+
continue
2149+
}
21402150
if {$mod in [getDependentLoadedModuleList [list $lmmod] 0 0]} {
21412151
reportDebug "skip deps refresh for '$lmmod' as dep cycle\
21422152
detected with '$mod'"
@@ -2266,8 +2276,9 @@ proc unsetModuleDependency {mod} {
22662276
if {[info exists ::g_moduleUnmetDep($mod)]} {
22672277
foreach ummod $::g_moduleUnmetDep($mod) {
22682278
if {[info exists ::g_unmetDepHash($ummod)]} {
2269-
set ::g_unmetDepHash($ummod) [replaceFromList\
2270-
$::g_unmetDepHash($ummod) $mod]
2279+
set idx [lsearch -exact $::g_unmetDepHash($ummod) $mod]
2280+
set ::g_unmetDepHash($ummod) [lreplace $::g_unmetDepHash($ummod)\
2281+
$idx $idx+1]
22712282
if {![llength $::g_unmetDepHash($ummod)]} {
22722283
unset ::g_unmetDepHash($ummod)
22732284
}

tcl/subcmd.tcl.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,8 @@ proc cmdModuleLoad {context uasked tryload loadany tag_list modulepath_list\
12311231

12321232
# get loaded modules holding a requirement on modname and able to
12331233
# be reloaded
1234-
set depre_list [getUnmetDependentLoadedModuleList $modnamevr]
1234+
set depre_list [getUnmetDependentLoadedModuleList $modnamevr\
1235+
$modfile]
12351236
reportDebug "depre mod list is '$depre_list'"
12361237

12371238
if {[isTopEvaluation]} {

0 commit comments

Comments
 (0)