Skip to content

Commit

Permalink
only store version of packages during load time when generating sysimage
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Sep 13, 2022
1 parent 70bfa3f commit 9c129f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
37 changes: 25 additions & 12 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,18 @@ function pkgdir(m::Module, paths::String...)
return joinpath(dirname(dirname(path)), paths...)
end

function get_pkgversion_from_path(path)
project_file = locate_project_file(path)
if project_file isa String
d = parsed_toml(project_file)
v = get(d, "version", nothing)
if v !== nothing
return VersionNumber(v::String)
end
end
return nothing
end

"""
pkgversion(m::Module)
Expand All @@ -477,12 +489,17 @@ the form `pkgversion(@__MODULE__)` can be used.
This function was introduced in Julia 1.9.
"""
function pkgversion(m::Module)
rootmodule = moduleroot(m)
pkg = PkgId(rootmodule)
pkgorigin = @lock require_lock begin
get(pkgorigins, pkg, nothing)
path = pkgdir(m)
path === nothing && return nothing
@lock require_lock begin
v = get_pkgversion_from_path(path)
pkgorigin = get(pkgorigins, PkgId(moduleroot(m)), nothing)
# Cache the version
if pkgorigin !== nothing && pkgorigin.version === nothing
pkgorigin.version = v
end
return v
end
return pkgorigin === nothing ? nothing : pkgorigin.version
end

## generic project & manifest API ##
Expand Down Expand Up @@ -1356,13 +1373,9 @@ function set_pkgorigin_version_path(pkg::PkgId, path::Union{String,Nothing})
assert_havelock(require_lock)
pkgorigin = get!(PkgOrigin, pkgorigins, pkg)
if path !== nothing
project_file = locate_project_file(joinpath(dirname(path), ".."))
if project_file isa String
d = parsed_toml(project_file)
v = get(d, "version", nothing)
if v !== nothing
pkgorigin.version = VersionNumber(v::AbstractString)
end
# Pkg needs access to the version of packages in the sysimage.
if Core.Compiler.generating_sysimg()
pkgorigin.version = get_pkgversion_from_path(joinpath(dirname(path), ".."))
end
end
pkgorigin.path = path
Expand Down
2 changes: 1 addition & 1 deletion test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ finally
Base.set_active_project(old_act_proj)
popfirst!(LOAD_PATH)
end
@test Base.pkgorigins[Base.PkgId(UUID("69145d58-7df6-11e8-0660-cf7622583916"), "TestPkg")].version == v"1.2.3"
@test pkgversion(TestPkg) == v"1.2.3"

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

0 comments on commit 9c129f4

Please sign in to comment.