Skip to content

Commit 39d2654

Browse files
authored
Merge pull request #286 from tpgillam/tg/manifest_path_fix
Correctly compute project SHA when Manifest contains paths starting with `../`
2 parents 1a5c8ba + 06cfa96 commit 39d2654

File tree

9 files changed

+93
-20
lines changed

9 files changed

+93
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
*.jl.*.cov
33
*.jl.mem
44
.vscode
5-
./Manifest.toml
5+
/Manifest.toml
66
registryindexcache

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymbolServer"
22
uuid = "cf896787-08d5-524d-9de7-132aaa0cb996"
3-
version = "7.3.0"
3+
version = "7.3.1"
44

55
[deps]
66
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/server.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ server = Server(store_path, ctx, Dict{UUID,Package}())
5555
written_caches = String[] # List of caches that have already been written
5656
toplevel_pkgs = deps(project(ctx)) # First get a list of all package UUIds that we want to cache
5757
packages_to_load = []
58-
# Next make sure the cache is up-to-date for all of these
58+
59+
# Obtain the directory containing the active Manifest.toml. Any 'develop'ed dependencies
60+
# will contain a path that is relative to this directory.
61+
manifest_dir = dirname(ctx.env.manifest_file)
62+
63+
# Next make sure the cache is up-to-date for all of these.
5964
for (pk_name, uuid) in toplevel_pkgs
6065
uuid isa UUID || (uuid = UUID(uuid))
6166
if !isinmanifest(ctx, uuid)
@@ -71,7 +76,7 @@ for (pk_name, uuid) in toplevel_pkgs
7176
cached_version = open(cache_path) do io
7277
CacheStore.read(io)
7378
end
74-
if sha_pkg(frommanifest(manifest(ctx), uuid)) != cached_version.sha
79+
if sha_pkg(manifest_dir, frommanifest(manifest(ctx), uuid)) != cached_version.sha
7580
@info "Outdated sha, will recache package $pk_name ($uuid)"
7681
push!(packages_to_load, uuid)
7782
else
@@ -118,7 +123,7 @@ for (pkg_name, cache) in env_symbols
118123
!isinmanifest(ctx, String(pkg_name)) && continue
119124
uuid = packageuuid(ctx, String(pkg_name))
120125
pe = frommanifest(ctx, uuid)
121-
server.depot[uuid] = Package(String(pkg_name), cache, uuid, sha_pkg(pe))
126+
server.depot[uuid] = Package(String(pkg_name), cache, uuid, sha_pkg(manifest_dir, pe))
122127
end
123128

124129
write_depot(server, server.context, written_caches)

src/utils.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ function sha2_256_dir(path, sha=zeros(UInt8, 32))
189189
return sha
190190
end
191191

192-
function sha_pkg(pe::PackageEntry)
193-
path(pe) isa String && isdir(path(pe)) && isdir(joinpath(path(pe), "src")) ? sha2_256_dir(joinpath(path(pe), "src")) : nothing
192+
function sha_pkg(manifest_dir::AbstractString, pe::PackageEntry)
193+
relpath = path(pe)
194+
isa(relpath, String) || return nothing
195+
src_path = normpath(joinpath(manifest_dir, relpath, "src"))
196+
return isdir(src_path) ? sha2_256_dir(src_path) : nothing
194197
end
195198

196199
function _doc(binding::Base.Docs.Binding)

test/runtests.jl

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using SymbolServer, Pkg
22
using SymbolServer: packagename, packageuuid, deps, manifest, project, version, Package, frommanifest, VarRef, _lookup
3-
using Base:UUID
3+
using Base: UUID
44
using Test
55

66
allns = SymbolServer.getallns()
@@ -141,6 +141,47 @@ end
141141
@test length(readdir(store_path)) == 0
142142
end
143143

144+
if VERSION >= v"1.6"
145+
# The test-case uses a Manifest format that is incompatible with older versions of
146+
# Julia.
147+
@testset "issues/285" begin
148+
mktempdir() do path
149+
cp(joinpath(@__DIR__, "testenv2"), path; force=true)
150+
151+
project_path = joinpath(path, "proj")
152+
153+
store_path = joinpath(path, "store")
154+
mkpath(store_path)
155+
156+
jl_cmd = joinpath(Sys.BINDIR, Base.julia_exename())
157+
withenv("JULIA_PKG_PRECOMPILE_AUTO" => 0) do
158+
run(`$jl_cmd --project=$project_path --startup-file=no -e 'using Pkg; Pkg.instantiate()'`)
159+
end
160+
161+
ssi = SymbolServerInstance("", store_path)
162+
ret_status, store = getstore(ssi, project_path; download=false)
163+
@test ret_status == :success
164+
@test length(store) == 4
165+
@test haskey(store, :Core)
166+
@test haskey(store, :Base)
167+
@test haskey(store, :Main)
168+
@test haskey(store, :A)
169+
170+
# Inspect the cached version, and check that the package SHA has been computed
171+
# correctly.
172+
cache_path = joinpath(store_path, "A", "A_94f385dd-073b-49fe-b7ed-f824d09b3331", "v0.1.0_nothing.jstore")
173+
@test isfile(cache_path)
174+
175+
cached_version = open(SymbolServer.CacheStore.read, cache_path)
176+
@test !isnothing(cached_version.sha)
177+
@test cached_version.sha == SymbolServer.sha2_256_dir(joinpath(path, "A", "src"))
178+
179+
SymbolServer.clear_disc_store(ssi)
180+
@test length(readdir(store_path)) == 0
181+
end
182+
end
183+
end
184+
144185
@test SymbolServer.stdlibs[:Base][:Sort][:sort] isa SymbolServer.FunctionStore
145186

146187
@testset "symbol documentation" begin
@@ -158,7 +199,7 @@ end
158199

159200
if VERSION >= v"1.1-"
160201
@testset "Excluding private packages from cache download requests" begin
161-
pkgs = Dict{Base.UUID, Pkg.Types.PackageEntry}()
202+
pkgs = Dict{Base.UUID,Pkg.Types.PackageEntry}()
162203
if VERSION < v"1.3-"
163204
pkgs[UUID("7876af07-990d-54b4-ab0e-23690620f79a")] = Pkg.Types.PackageEntry(name="Example", other=Dict("git-tree-sha1" => Base.SHA1("0"^40)))
164205
pkgs[UUID("3e13f8c9-a9aa-412e-8b2a-fda000b375e2")] = Pkg.Types.PackageEntry(name="NotInGeneral", other=Dict("git-tree-sha1" => Base.SHA1("0"^40)))
@@ -188,7 +229,7 @@ end
188229
using SymbolServer: FakeTypeName
189230

190231
@testset "TypeofVararg" begin
191-
Ts = Any[Vararg, Vararg{Bool,3}, NTuple{N,Any} where N]
232+
Ts = Any[Vararg, Vararg{Bool,3}, NTuple{N,Any} where {N}]
192233
isdefined(Core, :TypeofVararg) && append!(Ts, Any[Vararg{Int}, Vararg{Rational}])
193234

194235
for ((i, T1), (j, T2)) in Iterators.product(enumerate.((Ts, Ts))...)
@@ -212,23 +253,26 @@ import UUIDs
212253
else
213254
tmp_access = try
214255
n = "/tmp/" * string(UUIDs.uuid4())
215-
touch(n); rm(n)
256+
touch(n)
257+
rm(n)
216258
true
217259
catch
218260
false
219261
end
220262
too_long = joinpath(tempdir(), string(UUIDs.uuid4())^3)
221263
mkdir(too_long)
222-
for TEMPDIR in (tempdir(), too_long); withenv("TEMPDIR" => TEMPDIR) do
223-
p = SymbolServer.pipe_name()
224-
# TEMPDIR + / + prefix + UUID[1:13]
225-
if length(tempdir()) + 1 + length("vscjlsymserv-") + 13 < 92 || !tmp_access
226-
@test startswith(p, tempdir())
227-
@test occursin(r"^vscjlsymserv-\w{8}-\w{4}$", basename(p))
228-
else
229-
@test occursin(r"^/tmp/vscjlsymserv-\w{8}(?:-\w{4}){3}-\w{12}$", p)
264+
for TEMPDIR in (tempdir(), too_long)
265+
withenv("TEMPDIR" => TEMPDIR) do
266+
p = SymbolServer.pipe_name()
267+
# TEMPDIR + / + prefix + UUID[1:13]
268+
if length(tempdir()) + 1 + length("vscjlsymserv-") + 13 < 92 || !tmp_access
269+
@test startswith(p, tempdir())
270+
@test occursin(r"^vscjlsymserv-\w{8}-\w{4}$", basename(p))
271+
else
272+
@test occursin(r"^/tmp/vscjlsymserv-\w{8}(?:-\w{4}){3}-\w{12}$", p)
273+
end
230274
end
231-
end end
275+
end
232276
rm(too_long; recursive=true)
233277
end
234278
end

test/testenv2/A/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "A"
2+
uuid = "94f385dd-073b-49fe-b7ed-f824d09b3331"
3+
authors = ["Tom Gillam <[email protected]>"]
4+
version = "0.1.0"

test/testenv2/A/src/A.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module A
2+
3+
moo() = 42
4+
5+
end # module A

test/testenv2/proj/Manifest.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
julia_version = "1.10.1"
4+
manifest_format = "2.0"
5+
project_hash = "c82015c2e523eeff7aaad9dc94d1d3baa11cc7bd"
6+
7+
[[deps.A]]
8+
path = "../A"
9+
uuid = "94f385dd-073b-49fe-b7ed-f824d09b3331"
10+
version = "0.1.0"

test/testenv2/proj/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
A = "94f385dd-073b-49fe-b7ed-f824d09b3331"

0 commit comments

Comments
 (0)