Skip to content

Commit 60ec94a

Browse files
committed
Fix usage of Pkg internals for Julia >= 1.6.2, fixes #224.
1 parent 488bcb4 commit 60ec94a

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

src/SymbolServer.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, p
3030
if download
3131
manifest_filename = isfile(joinpath(environment_path, "JuliaManifest.toml")) ? joinpath(environment_path, "JuliaManifest.toml") : joinpath(environment_path, "Manifest.toml")
3232
if isfile(manifest_filename)
33-
let manifest = Pkg.Types.read_manifest(manifest_filename)
33+
let manifest = read_manifest(manifest_filename); if manifest !== nothing
3434
asyncmap(collect(validate_disc_store(ssi.store_path, manifest)), ntasks = 10) do pkg
3535
uuid = packageuuid(pkg)
3636
get_file_from_cloud(manifest, uuid, environment_path, ssi.depot_path, ssi.store_path, ssi.store_path)
37-
end
37+
end end
3838
end
3939
end
4040
end
@@ -144,16 +144,8 @@ function load_project_packages_into_store!(ssi::SymbolServerInstance, environmen
144144
end
145145

146146
manifest_filename = isfile(joinpath(environment_path, "JuliaManifest.toml")) ? joinpath(environment_path, "JuliaManifest.toml") : joinpath(environment_path, "Manifest.toml")
147-
manifest = try
148-
Pkg.API.read_manifest(manifest_filename)
149-
catch err
150-
if err isa Pkg.Types.PkgError
151-
@warn "Could not load manifest."
152-
return
153-
else
154-
rethrow(err)
155-
end
156-
end
147+
manifest = read_manifest(manifest_filename)
148+
manifest === nothing && return
157149

158150
for uuid in values(deps(project))
159151
load_package_from_cache_into_store!(ssi, uuid, manifest, store)

src/server.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ for (pk_name, uuid) in toplevel_pkgs
6262
cache_path = joinpath(server.storedir, SymbolServer.get_cache_path(manifest(ctx), uuid)...)
6363

6464
if isfile(cache_path)
65-
if is_package_deved(ctx.env.manifest, uuid)
65+
if is_package_deved(manifest(ctx), uuid)
6666
try
6767
cached_version = open(cache_path) do io
6868
CacheStore.read(io)
6969
end
70-
if sha_pkg(frommanifest(ctx.env.manifest, uuid)) != cached_version.sha
70+
if sha_pkg(frommanifest(manifest(ctx), uuid)) != cached_version.sha
7171
@info "Outdated sha, will recache package $pk_name ($uuid)"
7272
push!(packages_to_load, uuid)
7373
else

src/utils.jl

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,40 @@ end
66

77
"""
88
manifest(c::Pkg.Types.Context)
9-
Retrieves the manifest of a Context.
9+
Retrieves the UUID -> PackageEntry map from the manifest of a Context.
1010
"""
11-
manifest(c::Pkg.Types.Context) = c.env.manifest
11+
function manifest(c::Pkg.Types.Context)
12+
m = c.env.manifest
13+
if VERSION < v"1.6.2"
14+
return m
15+
else
16+
return m.deps
17+
end
18+
end
19+
20+
"""
21+
read_manifest(manifest_filename)
22+
23+
Read the manifest from the path and return the UUID -> PackageEntry map.
24+
If the file can't be read, return `nothing`.
25+
"""
26+
function read_manifest(manifest_filename)
27+
try
28+
m = Pkg.API.read_manifest(manifest_filename)
29+
if VERSION < v"1.6.2"
30+
return m
31+
else
32+
return m.deps
33+
end
34+
catch err
35+
if err isa Pkg.Types.PkgError
36+
@warn "Could not load manifest."
37+
return nothing
38+
else
39+
rethrow(err)
40+
end
41+
end
42+
end
1243

1344
"""
1445
project(c::Pkg.Types.Context)
@@ -49,7 +80,7 @@ function isinmanifest end
4980

5081
packagename(pkg::Pair{String,Any})::String = first(pkg)
5182
function packagename(c::Pkg.Types.Context, uuid)
52-
for (n, p) in c.env.manifest
83+
for (n, p) in manifest(c)
5384
if get(first(p), "uuid", "") == string(uuid)
5485
return n
5586
end
@@ -79,8 +110,8 @@ function isinmanifest end
79110
version(pe::PackageEntry) = get(pe[1], "version", nothing)
80111
tree_hash(pe) = get(pe[1], "git-tree-sha1", nothing)
81112

82-
frommanifest(c::Pkg.Types.Context, uuid) = frommanifest(c.env.manifest, uuid)
83-
113+
frommanifest(c::Pkg.Types.Context, uuid) = frommanifest(manifest(c), uuid)
114+
84115
function frommanifest(manifest::Dict{String,Any}, uuid)
85116
for p in values(manifest)
86117
if get(first(p), "uuid", "") == string(uuid)
@@ -548,7 +579,7 @@ end
548579

549580
function write_cache(uuid, pkg::Package, ctx, storedir)
550581
isinmanifest(ctx, uuid) || return ""
551-
cache_paths = get_cache_path(ctx.env.manifest, uuid)
582+
cache_paths = get_cache_path(manifest(ctx), uuid)
552583
!isdir(joinpath(storedir, cache_paths[1])) && mkdir(joinpath(storedir, cache_paths[1]))
553584
!isdir(joinpath(storedir, cache_paths[1], cache_paths[2])) && mkdir(joinpath(storedir, cache_paths[1], cache_paths[2]))
554585
@info "Now writing to disc $uuid"

0 commit comments

Comments
 (0)