Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only store version of packages during load time when generating sysimage #46738

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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