@@ -411,6 +411,16 @@ const project_names = ("JuliaProject.toml", "Project.toml")
411
411
const manifest_names = (" JuliaManifest.toml" , " Manifest.toml" )
412
412
const preferences_names = (" JuliaLocalPreferences.toml" , " LocalPreferences.toml" )
413
413
414
+ function locate_project_file (env:: String )
415
+ for proj in project_names
416
+ project_file = joinpath (env, proj)
417
+ if isfile_casesensitive (project_file)
418
+ return project_file
419
+ end
420
+ end
421
+ return true
422
+ end
423
+
414
424
# classify the LOAD_PATH entry to be one of:
415
425
# - `false`: nonexistant / nothing to see here
416
426
# - `true`: `env` is an implicit environment
@@ -423,14 +433,7 @@ function env_project_file(env::String)::Union{Bool,String}
423
433
project_file === nothing || return project_file
424
434
end
425
435
if isdir (env)
426
- for proj in project_names
427
- maybe_project_file = joinpath (env, proj)
428
- if isfile_casesensitive (maybe_project_file)
429
- project_file = maybe_project_file
430
- break
431
- end
432
- end
433
- project_file = true
436
+ project_file = locate_project_file (env)
434
437
elseif basename (env) in project_names && isfile_casesensitive (env)
435
438
project_file = env
436
439
else
@@ -1069,11 +1072,11 @@ function require(into::Module, mod::Symbol)
1069
1072
end
1070
1073
1071
1074
mutable struct PkgOrigin
1072
- # version::VersionNumber
1073
1075
path:: Union{String,Nothing}
1074
1076
cachepath:: Union{String,Nothing}
1077
+ version:: Union{VersionNumber,Nothing}
1075
1078
end
1076
- PkgOrigin () = PkgOrigin (nothing , nothing )
1079
+ PkgOrigin () = PkgOrigin (nothing , nothing , nothing )
1077
1080
const pkgorigins = Dict {PkgId,PkgOrigin} ()
1078
1081
1079
1082
require (uuidkey:: PkgId ) = @lock require_lock _require_prelocked (uuidkey)
@@ -1147,6 +1150,21 @@ function unreference_module(key::PkgId)
1147
1150
end
1148
1151
end
1149
1152
1153
+ function set_pkgorigin_version_path (pkg, path)
1154
+ pkgorigin = get! (PkgOrigin, pkgorigins, pkg)
1155
+ if path != = nothing
1156
+ project_file = locate_project_file (joinpath (dirname (path), " .." ))
1157
+ if project_file isa String
1158
+ d = parsed_toml (project_file)
1159
+ v = get (d, " version" , nothing )
1160
+ if v != = nothing
1161
+ pkgorigin. version = VersionNumber (v)
1162
+ end
1163
+ end
1164
+ end
1165
+ pkgorigin. path = path
1166
+ end
1167
+
1150
1168
# Returns `nothing` or the name of the newly-created cachefile
1151
1169
function _require (pkg:: PkgId )
1152
1170
# handle recursive calls to require
@@ -1163,7 +1181,7 @@ function _require(pkg::PkgId)
1163
1181
toplevel_load[] = false
1164
1182
# perform the search operation to select the module file require intends to load
1165
1183
path = locate_package (pkg)
1166
- get! (PkgOrigin, pkgorigins, pkg) . path = path
1184
+ set_pkgorigin_version_path (pkg, path)
1167
1185
if path === nothing
1168
1186
throw (ArgumentError ("""
1169
1187
Package $pkg is required but does not seem to be installed:
@@ -1934,11 +1952,11 @@ get_compiletime_preferences(::Nothing) = String[]
1934
1952
else
1935
1953
@label locate_branch
1936
1954
path = locate_package (req_key)
1937
- get! (PkgOrigin, pkgorigins, req_key). path = path
1938
1955
if path === nothing
1939
1956
@debug " Rejecting cache file $cachefile because dependency $req_key not found."
1940
1957
return true # Won't be able to fulfill dependency
1941
1958
end
1959
+ set_pkgorigin_version_path (req_key, path)
1942
1960
depmods[i] = (path, req_key, req_build_id)
1943
1961
end
1944
1962
end
0 commit comments