Skip to content

Commit 21e5a26

Browse files
authored
also set the version in pkgorigins (#44318)
1 parent 8ae9dd5 commit 21e5a26

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

base/loading.jl

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ const project_names = ("JuliaProject.toml", "Project.toml")
411411
const manifest_names = ("JuliaManifest.toml", "Manifest.toml")
412412
const preferences_names = ("JuliaLocalPreferences.toml", "LocalPreferences.toml")
413413

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+
414424
# classify the LOAD_PATH entry to be one of:
415425
# - `false`: nonexistant / nothing to see here
416426
# - `true`: `env` is an implicit environment
@@ -423,14 +433,7 @@ function env_project_file(env::String)::Union{Bool,String}
423433
project_file === nothing || return project_file
424434
end
425435
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)
434437
elseif basename(env) in project_names && isfile_casesensitive(env)
435438
project_file = env
436439
else
@@ -1069,11 +1072,11 @@ function require(into::Module, mod::Symbol)
10691072
end
10701073

10711074
mutable struct PkgOrigin
1072-
# version::VersionNumber
10731075
path::Union{String,Nothing}
10741076
cachepath::Union{String,Nothing}
1077+
version::Union{VersionNumber,Nothing}
10751078
end
1076-
PkgOrigin() = PkgOrigin(nothing, nothing)
1079+
PkgOrigin() = PkgOrigin(nothing, nothing, nothing)
10771080
const pkgorigins = Dict{PkgId,PkgOrigin}()
10781081

10791082
require(uuidkey::PkgId) = @lock require_lock _require_prelocked(uuidkey)
@@ -1147,6 +1150,21 @@ function unreference_module(key::PkgId)
11471150
end
11481151
end
11491152

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+
11501168
# Returns `nothing` or the name of the newly-created cachefile
11511169
function _require(pkg::PkgId)
11521170
# handle recursive calls to require
@@ -1163,7 +1181,7 @@ function _require(pkg::PkgId)
11631181
toplevel_load[] = false
11641182
# perform the search operation to select the module file require intends to load
11651183
path = locate_package(pkg)
1166-
get!(PkgOrigin, pkgorigins, pkg).path = path
1184+
set_pkgorigin_version_path(pkg, path)
11671185
if path === nothing
11681186
throw(ArgumentError("""
11691187
Package $pkg is required but does not seem to be installed:
@@ -1934,11 +1952,11 @@ get_compiletime_preferences(::Nothing) = String[]
19341952
else
19351953
@label locate_branch
19361954
path = locate_package(req_key)
1937-
get!(PkgOrigin, pkgorigins, req_key).path = path
19381955
if path === nothing
19391956
@debug "Rejecting cache file $cachefile because dependency $req_key not found."
19401957
return true # Won't be able to fulfill dependency
19411958
end
1959+
set_pkgorigin_version_path(req_key, path)
19421960
depmods[i] = (path, req_key, req_build_id)
19431961
end
19441962
end

test/TestPkg/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TestPkg"
22
uuid = "69145d58-7df6-11e8-0660-cf7622583916"
3-
3+
version = "1.2.3"
44

55
[deps]
66
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

test/loading.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ finally
651651
Base.set_active_project(old_act_proj)
652652
popfirst!(LOAD_PATH)
653653
end
654+
@test Base.pkgorigins[Base.PkgId(UUID("69145d58-7df6-11e8-0660-cf7622583916"), "TestPkg")].version == v"1.2.3"
654655

655656
@testset "--project and JULIA_PROJECT paths should be absolutified" begin
656657
mktempdir() do dir; cd(dir) do

0 commit comments

Comments
 (0)