@@ -460,7 +460,9 @@ the form `pkgversion(@__MODULE__)` can be used.
460
460
function pkgversion (m:: Module )
461
461
rootmodule = moduleroot (m)
462
462
pkg = PkgId (rootmodule)
463
- pkgorigin = get (pkgorigins, pkg, nothing )
463
+ pkgorigin = @lock require_lock begin
464
+ get (pkgorigins, pkg, nothing )
465
+ end
464
466
return pkgorigin === nothing ? nothing : pkgorigin. version
465
467
end
466
468
@@ -952,8 +954,8 @@ function _tryrequire_from_serialized(modkey::PkgId, build_id::UInt64)
952
954
try
953
955
modpath = locate_package (modkey)
954
956
modpath === nothing && return nothing
957
+ set_pkgorigin_version_path (modkey, String (modpath))
955
958
loaded = _require_search_from_serialized (modkey, String (modpath), build_id)
956
- get! (PkgOrigin, pkgorigins, modkey). path = modpath
957
959
finally
958
960
loading = pop! (package_locks, modkey)
959
961
notify (loading, loaded, all= true )
971
973
972
974
# loads a precompile cache file, ignoring stale_cachefile tests
973
975
# assuming all depmods are already loaded and everything is valid
974
- function _tryrequire_from_serialized (modkey:: PkgId , path:: String , depmods:: Vector{Any} )
976
+ function _tryrequire_from_serialized (modkey:: PkgId , path:: String , sourcepath :: String , depmods:: Vector{Any} )
975
977
assert_havelock (require_lock)
976
978
loaded = nothing
977
979
if root_module_exists (modkey)
@@ -992,6 +994,7 @@ function _tryrequire_from_serialized(modkey::PkgId, path::String, depmods::Vecto
992
994
end
993
995
package_locks[modkey] = Threads. Condition (require_lock)
994
996
try
997
+ set_pkgorigin_version_path (modkey, sourcepath)
995
998
loaded = _include_from_serialized (modkey, path, depmods)
996
999
finally
997
1000
loading = pop! (package_locks, modkey)
@@ -1059,7 +1062,7 @@ end
1059
1062
continue
1060
1063
end
1061
1064
modstaledeps = modstaledeps:: Vector{Any}
1062
- staledeps[i] = (modkey, modpath_to_try, modstaledeps)
1065
+ staledeps[i] = (modpath, modkey, modpath_to_try, modstaledeps)
1063
1066
modfound = true
1064
1067
break
1065
1068
end
@@ -1081,8 +1084,8 @@ end
1081
1084
for i in 1 : length (staledeps)
1082
1085
dep = staledeps[i]
1083
1086
dep isa Module && continue
1084
- modkey, modpath_to_try, modstaledeps = dep:: Tuple{PkgId, String, Vector{Any}}
1085
- dep = _tryrequire_from_serialized (modkey, modpath_to_try, modstaledeps)
1087
+ modpath, modkey, modpath_to_try, modstaledeps = dep:: Tuple{String, PkgId, String, Vector{Any}}
1088
+ dep = _tryrequire_from_serialized (modkey, modpath_to_try, modpath, modstaledeps)
1086
1089
if ! isa (dep, Module)
1087
1090
@debug " Rejecting cache file $path_to_try because required dependency $modkey failed to load from cache file for $modpath ." exception= dep
1088
1091
staledeps = true
@@ -1324,7 +1327,9 @@ function unreference_module(key::PkgId)
1324
1327
end
1325
1328
end
1326
1329
1327
- function set_pkgorigin_version_path (pkg, path)
1330
+ # whoever takes the package_locks[pkg] must call this function immediately
1331
+ function set_pkgorigin_version_path (pkg:: PkgId , path:: Union{String,Nothing} )
1332
+ assert_havelock (require_lock)
1328
1333
pkgorigin = get! (PkgOrigin, pkgorigins, pkg)
1329
1334
if path != = nothing
1330
1335
project_file = locate_project_file (joinpath (dirname (path), " .." ))
@@ -1337,6 +1342,7 @@ function set_pkgorigin_version_path(pkg, path)
1337
1342
end
1338
1343
end
1339
1344
pkgorigin. path = path
1345
+ nothing
1340
1346
end
1341
1347
1342
1348
# Returns `nothing` or the new(ish) module
@@ -1356,13 +1362,13 @@ function _require(pkg::PkgId)
1356
1362
toplevel_load[] = false
1357
1363
# perform the search operation to select the module file require intends to load
1358
1364
path = locate_package (pkg)
1359
- set_pkgorigin_version_path (pkg, path)
1360
1365
if path === nothing
1361
1366
throw (ArgumentError ("""
1362
1367
Package $pkg is required but does not seem to be installed:
1363
1368
- Run `Pkg.instantiate()` to install all recorded dependencies.
1364
1369
""" ))
1365
1370
end
1371
+ set_pkgorigin_version_path (pkg, path)
1366
1372
1367
1373
# attempt to load the module file via the precompile cache locations
1368
1374
if JLOptions (). use_compiled_modules != 0
@@ -1436,6 +1442,7 @@ end
1436
1442
1437
1443
function _require_from_serialized (uuidkey:: PkgId , path:: String )
1438
1444
@lock require_lock begin
1445
+ set_pkgorigin_version_path (uuidkey, nothing )
1439
1446
newm = _tryrequire_from_serialized (uuidkey, path)
1440
1447
newm isa Module || throw (newm)
1441
1448
# After successfully loading, notify downstream consumers
@@ -2160,7 +2167,6 @@ end
2160
2167
@debug " Rejecting cache file $cachefile because dependency $req_key not found."
2161
2168
return true # Won't be able to fulfill dependency
2162
2169
end
2163
- set_pkgorigin_version_path (req_key, path)
2164
2170
depmods[i] = (path, req_key, req_build_id)
2165
2171
end
2166
2172
end
0 commit comments