Skip to content

Commit afcdc4f

Browse files
author
KristofferC
committed
fix some hashing related things
1 parent f7d5602 commit afcdc4f

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

src/Operations.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ function update_manifest!(env::EnvCache, pkgs::Vector{PackageSpec}, deps_map, ju
385385

386386
env.manifest.registries = registry_entries
387387
env.manifest.manifest_format = v"2.1.0"
388-
return record_project_hash(env)
388+
return
389389
end
390390

391391
# This has to be done after the packages have been downloaded
@@ -1666,10 +1666,6 @@ function prune_deps(iterator, keep::Set{UUID})
16661666
return
16671667
end
16681668

1669-
function record_project_hash(env::EnvCache)
1670-
return env.manifest.other["project_hash"] = Types.workspace_resolve_hash(env)
1671-
end
1672-
16731669
#########
16741670
# Build #
16751671
#########
@@ -1962,7 +1958,6 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode::PackageMode)
19621958
end
19631959
# only keep reachable manifest entries
19641960
prune_manifest(ctx.env)
1965-
record_project_hash(ctx.env)
19661961
# update project & manifest
19671962
write_env(ctx.env)
19681963
return show_update(ctx.env, ctx.registries; io = ctx.io)
@@ -2242,7 +2237,6 @@ function add(
22422237
# if env is a package add compat entries
22432238
add_compat_entries!(ctx, pkgs)
22442239

2245-
record_project_hash(ctx.env)
22462240
write_env(ctx.env)
22472241
show_update(ctx.env, ctx.registries; io = ctx.io)
22482242

@@ -2264,14 +2258,12 @@ function add(
22642258

22652259
# if env is a package add compat entries
22662260
add_compat_entries!(ctx, pkgs)
2267-
record_project_hash(ctx.env) # compat entries changed the hash after it was last recorded in update_manifest!
22682261

22692262
write_env(ctx.env) # write env before building
22702263
show_update(ctx.env, ctx.registries; io = ctx.io)
22712264
build_versions(ctx, union(new_apply, new_git))
22722265
allow_autoprecomp && Pkg._auto_precompile(ctx, pkgs)
22732266
else
2274-
record_project_hash(ctx.env)
22752267
write_env(ctx.env)
22762268
names_str = join(names, ", ")
22772269
printpkgstyle(ctx.io, :Added, "$names_str to [$(target)]")
@@ -2663,7 +2655,9 @@ function sandbox_preserve(env::EnvCache, target::PackageSpec, test_project::Stri
26632655
project = read_project(test_project)
26642656
keep = Set([target.uuid])
26652657
union!(keep, values(project.deps))
2666-
record_project_hash(env)
2658+
# Sync sources and record hash
2659+
Types.sync_sources_from_manifest!(env)
2660+
Types.record_project_hash(env)
26672661
# prune and return
26682662
return prune_manifest(env.manifest, keep)
26692663
end

src/Types.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,12 +1385,8 @@ manifest_info(::Manifest, uuid::Nothing) = nothing
13851385
function manifest_info(manifest::Manifest, uuid::UUID)::Union{PackageEntry, Nothing}
13861386
return get(manifest, uuid, nothing)
13871387
end
1388-
function write_env(
1389-
env::EnvCache; update_undo = true,
1390-
skip_writing_project::Bool = false,
1391-
skip_readonly_check::Bool = false
1392-
)
1393-
# Verify that the generated manifest is consistent with `sources`
1388+
function sync_sources_from_manifest!(env::EnvCache)
1389+
# Sync sources in the project with what's in the manifest
13941390
for (pkg, uuid) in env.project.deps
13951391
path, repo = get_path_repo(env.project, env.project_file, env.manifest_file, pkg)
13961392
entry = manifest_info(env.manifest, uuid)
@@ -1419,6 +1415,20 @@ function write_env(
14191415
end
14201416
end
14211417
end
1418+
end
1419+
1420+
function record_project_hash(env::EnvCache)
1421+
return env.manifest.other["project_hash"] = workspace_resolve_hash(env)
1422+
end
1423+
1424+
function write_env(
1425+
env::EnvCache; update_undo = true,
1426+
skip_writing_project::Bool = false,
1427+
skip_readonly_check::Bool = false
1428+
)
1429+
# Sync sources from manifest and record hash before writing
1430+
sync_sources_from_manifest!(env)
1431+
record_project_hash(env)
14221432

14231433
# Check if the environment is readonly before attempting to write
14241434
if env.project.readonly && !skip_readonly_check

test/workspaces.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ temp_pkg_dir() do project_path
130130
env = Pkg.Types.EnvCache()
131131
hash_4 = Pkg.Types.workspace_resolve_hash(env)
132132

133-
@test hash_1 == hash_2 == hash_3 == hash_4
133+
# hash_1, hash_2, hash_3 should be equal, but hash_4 differs because
134+
# "test" has TestSpecificPackage in sources while "PrivatePackage/test" doesn't
135+
@test hash_1 == hash_2 == hash_3
136+
@test hash_4 != hash_3
134137

135138
# Test that the subprojects are working
136139
depot_path_string = join(Base.DEPOT_PATH, Sys.iswindows() ? ";" : ":")

0 commit comments

Comments
 (0)