From f7d56021c627cab9e81af42c9eb9e8401a2f38dd Mon Sep 17 00:00:00 2001 From: KristofferC Date: Tue, 11 Nov 2025 16:14:29 +0100 Subject: [PATCH 1/5] ensure sources take prio over manifest information, take 2 --- src/Operations.jl | 56 ++++++++++++++++++----------- src/Types.jl | 14 +++++++- test/sources.jl | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 22 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index 2c452e222f..3cdbdf7bb4 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -200,9 +200,40 @@ function load_project_deps( end for (name::String, uuid::UUID) in project.deps - findfirst(pkg -> pkg.uuid == uuid, pkgs) === nothing || continue # do not duplicate packages + # Check if package already exists in pkgs (from up_load_manifest_info! etc) + existing_idx = findfirst(pkg -> pkg.uuid == uuid, pkgs) + path, repo = get_path_repo(project, project_file, manifest_file, name) entry = manifest_info(manifest, uuid) + + # Track when [sources] entries should override manifest data + sources_has_path = path !== nothing + sources_has_repo = repo != GitRepo() + repo_overrides_entry = sources_has_repo && (entry === nothing || repo != entry.repo) + clear_tree_hash = sources_has_path || repo_overrides_entry + tree_hash = entry === nothing ? nothing : + clear_tree_hash ? nothing : + entry.tree_hash + final_repo = repo == GitRepo() ? (entry === nothing ? GitRepo() : entry.repo) : repo + + if existing_idx !== nothing + # Package already in pkgs - update it with sources info + existing_pkg = pkgs[existing_idx] + # Update tree_hash when we purposely cleared it for sources overrides + if clear_tree_hash + existing_pkg.tree_hash = tree_hash + end + # Update path if from sources + if path !== nothing + existing_pkg.path = path + end + # Update repo if from sources + if sources_has_repo + existing_pkg.repo = final_repo + end + continue + end + push!( pkgs_direct, entry === nothing ? PackageSpec(; uuid, name, path, repo) : @@ -210,9 +241,9 @@ function load_project_deps( uuid = uuid, name = name, path = path === nothing ? entry.path : path, - repo = repo == GitRepo() ? entry.repo : repo, + repo = final_repo, pinned = entry.pinned, - tree_hash = entry.tree_hash, # TODO should tree_hash be changed too? + tree_hash = tree_hash, version = load_version(entry.version, isfixed(entry), preserve), ) ) @@ -248,24 +279,7 @@ function load_all_deps( preserve::PreserveLevel = PRESERVE_ALL ) pkgs = load_manifest_deps(env.manifest, pkgs; preserve = preserve) - # Sources takes presedence over the manifest... - for pkg in pkgs - path, repo = get_path_repo(env.project, env.project_file, env.manifest_file, pkg.name) - if path !== nothing - # Path from [sources] takes precedence - clear tree_hash and repo from manifest - pkg.tree_hash = nothing - pkg.repo = GitRepo() # Clear any repo info - pkg.path = path - end - if repo.source !== nothing - # Repo from [sources] takes precedence - clear path from manifest - pkg.path = nothing - pkg.repo.source = repo.source - end - if repo.rev !== nothing - pkg.repo.rev = repo.rev - end - end + # load_direct_deps will apply sources and update tree_hash via load_project_deps return load_direct_deps(env, pkgs; preserve = preserve) end diff --git a/src/Types.jl b/src/Types.jl index ba783d0d4d..0a8c6107f3 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -667,13 +667,18 @@ function load_workspace_weak_deps(env::EnvCache) return weakdeps end -# only hash the deps and compat fields as they are the only fields that affect a resolve +# hash the deps, compat, and sources fields as they affect a resolve function workspace_resolve_hash(env::EnvCache) # Handle deps in both [deps] and [weakdeps] deps = Dict(pkg.name => pkg.uuid for pkg in Pkg.Operations.load_direct_deps(env)) weakdeps = load_workspace_weak_deps(env) alldeps = merge(deps, weakdeps) compats = Dict(name => Pkg.Operations.get_compat_workspace(env, name) for (name, uuid) in alldeps) + # Collect sources from project and workspace + sources = copy(env.project.sources) + for (_, proj) in env.workspace + merge!(sources, proj.sources) + end iob = IOBuffer() for (name, uuid) in sort!(collect(deps); by = first) println(iob, name, "=", uuid) @@ -686,6 +691,13 @@ function workspace_resolve_hash(env::EnvCache) for (name, compat) in sort!(collect(compats); by = first) println(iob, name, "=", compat) end + println(iob) + for (name, source_dict) in sort!(collect(sources); by = first) + # Sort the source attributes for deterministic hashing + for (key, val) in sort!(collect(source_dict); by = first) + println(iob, name, ".", key, "=", val) + end + end str = String(take!(iob)) return bytes2hex(sha1(str)) end diff --git a/test/sources.jl b/test/sources.jl index e5b5508ec3..7bb8128a2b 100644 --- a/test/sources.jl +++ b/test/sources.jl @@ -238,6 +238,98 @@ temp_pkg_dir() do project_path end end end + + @testset "changing rev in sources updates project_hash and git-tree-sha1 (#4157)" begin + isolate() do + mktempdir() do tmp + # Create a test package with two commits + test_pkg_dir = joinpath(tmp, "TestPkg") + mkpath(test_pkg_dir) + cd(test_pkg_dir) do + write( + "Project.toml", """ + name = "TestPkg" + uuid = "b4017d7c-a742-4580-99f2-e286571e6290" + version = "0.1.0" + """ + ) + mkpath("src") + write( + "src/TestPkg.jl", """ + module TestPkg + greet() = "Hello, World!" + end + """ + ) + run(`git init -q`) + run(`git add .`) + run(`git commit -q -m "Initial commit"`) + first_commit = readchomp(`git rev-parse HEAD`) + # Get tree hash by parsing git log + first_tree_hash = match(r"tree ([0-9a-f]+)", readchomp(`git cat-file -p $first_commit`))[1] + + # Make a second commit + write("README.md", "# TestPkg\n") + run(`git add .`) + run(`git commit -q -m "Add README"`) + second_commit = readchomp(`git rev-parse HEAD`) + second_tree_hash = match(r"tree ([0-9a-f]+)", readchomp(`git cat-file -p $second_commit`))[1] + + # Create consumer project + consumer_dir = joinpath(tmp, "consumer") + mkpath(consumer_dir) + cd(consumer_dir) do + # Start with first revision + write( + "Project.toml", """ + [deps] + TestPkg = "b4017d7c-a742-4580-99f2-e286571e6290" + + [sources] + TestPkg = { url = "$test_pkg_dir", rev = "$first_commit" } + """ + ) + + Pkg.activate(".") + Pkg.resolve() + @test isfile("Manifest.toml") + manifest = Pkg.Types.read_manifest("Manifest.toml") + first_project_hash = manifest.project_hash + + # Verify first state + test_pkg_uuid = UUID("b4017d7c-a742-4580-99f2-e286571e6290") + @test haskey(manifest.deps, test_pkg_uuid) + test_pkg_entry = manifest[test_pkg_uuid] + @test test_pkg_entry.tree_hash !== nothing + @test string(test_pkg_entry.tree_hash) == first_tree_hash + @test test_pkg_entry.repo.rev == first_commit + + # Change to second revision + write( + "Project.toml", """ + [deps] + TestPkg = "b4017d7c-a742-4580-99f2-e286571e6290" + + [sources] + TestPkg = { url = "$test_pkg_dir", rev = "$second_commit" } + """ + ) + + Pkg.resolve() + manifest = Pkg.Types.read_manifest("Manifest.toml") + second_project_hash = manifest.project_hash + + # Verify second state - both project_hash and git-tree-sha1 should change + test_pkg_entry = manifest[test_pkg_uuid] + @test test_pkg_entry.tree_hash !== nothing + @test string(test_pkg_entry.tree_hash) == second_tree_hash + @test test_pkg_entry.repo.rev == second_commit + @test second_project_hash != first_project_hash + end + end + end + end + end end end # module From afcdc4f9180678a5314427b14be257c8281f4d03 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Mon, 17 Nov 2025 15:10:24 +0100 Subject: [PATCH 2/5] fix some hashing related things --- src/Operations.jl | 14 ++++---------- src/Types.jl | 22 ++++++++++++++++------ test/workspaces.jl | 5 ++++- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index 3cdbdf7bb4..b90a45df59 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -385,7 +385,7 @@ function update_manifest!(env::EnvCache, pkgs::Vector{PackageSpec}, deps_map, ju env.manifest.registries = registry_entries env.manifest.manifest_format = v"2.1.0" - return record_project_hash(env) + return end # This has to be done after the packages have been downloaded @@ -1666,10 +1666,6 @@ function prune_deps(iterator, keep::Set{UUID}) return end -function record_project_hash(env::EnvCache) - return env.manifest.other["project_hash"] = Types.workspace_resolve_hash(env) -end - ######### # Build # ######### @@ -1962,7 +1958,6 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode::PackageMode) end # only keep reachable manifest entries prune_manifest(ctx.env) - record_project_hash(ctx.env) # update project & manifest write_env(ctx.env) return show_update(ctx.env, ctx.registries; io = ctx.io) @@ -2242,7 +2237,6 @@ function add( # if env is a package add compat entries add_compat_entries!(ctx, pkgs) - record_project_hash(ctx.env) write_env(ctx.env) show_update(ctx.env, ctx.registries; io = ctx.io) @@ -2264,14 +2258,12 @@ function add( # if env is a package add compat entries add_compat_entries!(ctx, pkgs) - record_project_hash(ctx.env) # compat entries changed the hash after it was last recorded in update_manifest! write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) build_versions(ctx, union(new_apply, new_git)) allow_autoprecomp && Pkg._auto_precompile(ctx, pkgs) else - record_project_hash(ctx.env) write_env(ctx.env) names_str = join(names, ", ") printpkgstyle(ctx.io, :Added, "$names_str to [$(target)]") @@ -2663,7 +2655,9 @@ function sandbox_preserve(env::EnvCache, target::PackageSpec, test_project::Stri project = read_project(test_project) keep = Set([target.uuid]) union!(keep, values(project.deps)) - record_project_hash(env) + # Sync sources and record hash + Types.sync_sources_from_manifest!(env) + Types.record_project_hash(env) # prune and return return prune_manifest(env.manifest, keep) end diff --git a/src/Types.jl b/src/Types.jl index 0a8c6107f3..d008792519 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -1385,12 +1385,8 @@ manifest_info(::Manifest, uuid::Nothing) = nothing function manifest_info(manifest::Manifest, uuid::UUID)::Union{PackageEntry, Nothing} return get(manifest, uuid, nothing) end -function write_env( - env::EnvCache; update_undo = true, - skip_writing_project::Bool = false, - skip_readonly_check::Bool = false - ) - # Verify that the generated manifest is consistent with `sources` +function sync_sources_from_manifest!(env::EnvCache) + # Sync sources in the project with what's in the manifest for (pkg, uuid) in env.project.deps path, repo = get_path_repo(env.project, env.project_file, env.manifest_file, pkg) entry = manifest_info(env.manifest, uuid) @@ -1419,6 +1415,20 @@ function write_env( end end end +end + +function record_project_hash(env::EnvCache) + return env.manifest.other["project_hash"] = workspace_resolve_hash(env) +end + +function write_env( + env::EnvCache; update_undo = true, + skip_writing_project::Bool = false, + skip_readonly_check::Bool = false + ) + # Sync sources from manifest and record hash before writing + sync_sources_from_manifest!(env) + record_project_hash(env) # Check if the environment is readonly before attempting to write if env.project.readonly && !skip_readonly_check diff --git a/test/workspaces.jl b/test/workspaces.jl index 14935b0eb5..66c75488d4 100644 --- a/test/workspaces.jl +++ b/test/workspaces.jl @@ -130,7 +130,10 @@ temp_pkg_dir() do project_path env = Pkg.Types.EnvCache() hash_4 = Pkg.Types.workspace_resolve_hash(env) - @test hash_1 == hash_2 == hash_3 == hash_4 + # hash_1, hash_2, hash_3 should be equal, but hash_4 differs because + # "test" has TestSpecificPackage in sources while "PrivatePackage/test" doesn't + @test hash_1 == hash_2 == hash_3 + @test hash_4 != hash_3 # Test that the subprojects are working depot_path_string = join(Base.DEPOT_PATH, Sys.iswindows() ? ";" : ":") From b36690a57aa2e142497e3c2f13c1728c51c598e7 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Mon, 17 Nov 2025 15:17:26 +0100 Subject: [PATCH 3/5] use libgit2 --- src/Types.jl | 1 + test/sources.jl | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Types.jl b/src/Types.jl index d008792519..f392ec7267 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -1415,6 +1415,7 @@ function sync_sources_from_manifest!(env::EnvCache) end end end + return end function record_project_hash(env::EnvCache) diff --git a/test/sources.jl b/test/sources.jl index 7bb8128a2b..2070a2c06a 100644 --- a/test/sources.jl +++ b/test/sources.jl @@ -4,6 +4,7 @@ import ..Pkg # ensure we are using the correct Pkg using Test, Pkg using ..Utils using UUIDs +using LibGit2 temp_pkg_dir() do project_path @testset "test Project.toml [sources]" begin @@ -261,19 +262,21 @@ temp_pkg_dir() do project_path end """ ) - run(`git init -q`) - run(`git add .`) - run(`git commit -q -m "Initial commit"`) - first_commit = readchomp(`git rev-parse HEAD`) - # Get tree hash by parsing git log - first_tree_hash = match(r"tree ([0-9a-f]+)", readchomp(`git cat-file -p $first_commit`))[1] + + first_commit = string(git_init_and_commit(test_pkg_dir; msg = "Initial commit")) + first_tree_hash = LibGit2.with(LibGit2.GitRepo(test_pkg_dir)) do repo + string(LibGit2.GitHash(LibGit2.peel(LibGit2.GitTree, LibGit2.GitCommit(repo, first_commit)))) + end # Make a second commit write("README.md", "# TestPkg\n") - run(`git add .`) - run(`git commit -q -m "Add README"`) - second_commit = readchomp(`git rev-parse HEAD`) - second_tree_hash = match(r"tree ([0-9a-f]+)", readchomp(`git cat-file -p $second_commit`))[1] + second_commit = LibGit2.with(LibGit2.GitRepo(test_pkg_dir)) do repo + LibGit2.add!(repo, "README.md") + string(LibGit2.commit(repo, "Add README"; author = TEST_SIG, committer = TEST_SIG)) + end + second_tree_hash = LibGit2.with(LibGit2.GitRepo(test_pkg_dir)) do repo + string(LibGit2.GitHash(LibGit2.peel(LibGit2.GitTree, LibGit2.GitCommit(repo, second_commit)))) + end # Create consumer project consumer_dir = joinpath(tmp, "consumer") From ad763024840af9763f1a32824a62e66ba67bd16b Mon Sep 17 00:00:00 2001 From: KristofferC Date: Mon, 17 Nov 2025 16:49:11 +0100 Subject: [PATCH 4/5] hash fixes take 2 --- src/Operations.jl | 20 +++++++++++++++++--- src/Types.jl | 8 -------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index b90a45df59..ae42576116 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -1666,6 +1666,15 @@ function prune_deps(iterator, keep::Set{UUID}) return end +function record_project_hash(env::EnvCache) + return env.manifest.other["project_hash"] = Types.workspace_resolve_hash(env) +end + +function finalize_resolve!(env::EnvCache) + Types.sync_sources_from_manifest!(env) + return record_project_hash(env) +end + ######### # Build # ######### @@ -2237,6 +2246,7 @@ function add( # if env is a package add compat entries add_compat_entries!(ctx, pkgs) + finalize_resolve!(ctx.env) write_env(ctx.env) show_update(ctx.env, ctx.registries; io = ctx.io) @@ -2259,11 +2269,13 @@ function add( # if env is a package add compat entries add_compat_entries!(ctx, pkgs) + finalize_resolve!(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) build_versions(ctx, union(new_apply, new_git)) allow_autoprecomp && Pkg._auto_precompile(ctx, pkgs) else + finalize_resolve!(ctx.env) write_env(ctx.env) names_str = join(names, ", ") printpkgstyle(ctx.io, :Added, "$names_str to [$(target)]") @@ -2288,6 +2300,7 @@ function develop( new_apply = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx; platform = platform, julia_version = ctx.julia_version) + finalize_resolve!(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) return build_versions(ctx, union(new_apply, new_git)) @@ -2442,6 +2455,7 @@ function up( new_apply = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx, julia_version = ctx.julia_version) + finalize_resolve!(ctx.env) write_env(ctx.env; skip_writing_project) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io, hidden_upgrades_info = true) @@ -2516,6 +2530,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}) new = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx; julia_version = ctx.julia_version) + finalize_resolve!(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) return build_versions(ctx, new) @@ -2566,6 +2581,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; err_if_free = true) new = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx) + finalize_resolve!(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) build_versions(ctx, new) @@ -2655,9 +2671,7 @@ function sandbox_preserve(env::EnvCache, target::PackageSpec, test_project::Stri project = read_project(test_project) keep = Set([target.uuid]) union!(keep, values(project.deps)) - # Sync sources and record hash - Types.sync_sources_from_manifest!(env) - Types.record_project_hash(env) + finalize_resolve!(env) # prune and return return prune_manifest(env.manifest, keep) end diff --git a/src/Types.jl b/src/Types.jl index f392ec7267..e72e1c17e8 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -1418,19 +1418,11 @@ function sync_sources_from_manifest!(env::EnvCache) return end -function record_project_hash(env::EnvCache) - return env.manifest.other["project_hash"] = workspace_resolve_hash(env) -end - function write_env( env::EnvCache; update_undo = true, skip_writing_project::Bool = false, skip_readonly_check::Bool = false ) - # Sync sources from manifest and record hash before writing - sync_sources_from_manifest!(env) - record_project_hash(env) - # Check if the environment is readonly before attempting to write if env.project.readonly && !skip_readonly_check pkgerror("Cannot modify a readonly environment. The project at $(env.project_file) is marked as readonly.") From e46777d494d8a9762364bc37e8fff4e48f5cbf19 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Tue, 18 Nov 2025 18:05:01 +0100 Subject: [PATCH 5/5] who needs correct hash anyway --- src/Operations.jl | 24 ++++++++++-------------- src/Types.jl | 14 +------------- test/sources.jl | 7 ++----- test/workspaces.jl | 5 +---- 4 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index ae42576116..8148ef3f52 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -385,7 +385,7 @@ function update_manifest!(env::EnvCache, pkgs::Vector{PackageSpec}, deps_map, ju env.manifest.registries = registry_entries env.manifest.manifest_format = v"2.1.0" - return + return record_project_hash(env) end # This has to be done after the packages have been downloaded @@ -1670,11 +1670,6 @@ function record_project_hash(env::EnvCache) return env.manifest.other["project_hash"] = Types.workspace_resolve_hash(env) end -function finalize_resolve!(env::EnvCache) - Types.sync_sources_from_manifest!(env) - return record_project_hash(env) -end - ######### # Build # ######### @@ -1967,6 +1962,7 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode::PackageMode) end # only keep reachable manifest entries prune_manifest(ctx.env) + record_project_hash(ctx.env) # update project & manifest write_env(ctx.env) return show_update(ctx.env, ctx.registries; io = ctx.io) @@ -2246,7 +2242,7 @@ function add( # if env is a package add compat entries add_compat_entries!(ctx, pkgs) - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env) show_update(ctx.env, ctx.registries; io = ctx.io) @@ -2269,13 +2265,13 @@ function add( # if env is a package add compat entries add_compat_entries!(ctx, pkgs) - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) build_versions(ctx, union(new_apply, new_git)) allow_autoprecomp && Pkg._auto_precompile(ctx, pkgs) else - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env) names_str = join(names, ", ") printpkgstyle(ctx.io, :Added, "$names_str to [$(target)]") @@ -2300,7 +2296,7 @@ function develop( new_apply = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx; platform = platform, julia_version = ctx.julia_version) - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) return build_versions(ctx, union(new_apply, new_git)) @@ -2455,7 +2451,7 @@ function up( new_apply = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx, julia_version = ctx.julia_version) - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env; skip_writing_project) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io, hidden_upgrades_info = true) @@ -2530,7 +2526,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}) new = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx; julia_version = ctx.julia_version) - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) return build_versions(ctx, new) @@ -2581,7 +2577,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; err_if_free = true) new = download_source(ctx) fixups_from_projectfile!(ctx) download_artifacts(ctx) - finalize_resolve!(ctx.env) + record_project_hash(ctx.env) write_env(ctx.env) # write env before building show_update(ctx.env, ctx.registries; io = ctx.io) build_versions(ctx, new) @@ -2671,7 +2667,7 @@ function sandbox_preserve(env::EnvCache, target::PackageSpec, test_project::Stri project = read_project(test_project) keep = Set([target.uuid]) union!(keep, values(project.deps)) - finalize_resolve!(env) + record_project_hash(env) # prune and return return prune_manifest(env.manifest, keep) end diff --git a/src/Types.jl b/src/Types.jl index e72e1c17e8..bd9eee6e16 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -667,18 +667,13 @@ function load_workspace_weak_deps(env::EnvCache) return weakdeps end -# hash the deps, compat, and sources fields as they affect a resolve +# only hash the deps and compat fields as they are the only fields that affect a resolve function workspace_resolve_hash(env::EnvCache) # Handle deps in both [deps] and [weakdeps] deps = Dict(pkg.name => pkg.uuid for pkg in Pkg.Operations.load_direct_deps(env)) weakdeps = load_workspace_weak_deps(env) alldeps = merge(deps, weakdeps) compats = Dict(name => Pkg.Operations.get_compat_workspace(env, name) for (name, uuid) in alldeps) - # Collect sources from project and workspace - sources = copy(env.project.sources) - for (_, proj) in env.workspace - merge!(sources, proj.sources) - end iob = IOBuffer() for (name, uuid) in sort!(collect(deps); by = first) println(iob, name, "=", uuid) @@ -691,13 +686,6 @@ function workspace_resolve_hash(env::EnvCache) for (name, compat) in sort!(collect(compats); by = first) println(iob, name, "=", compat) end - println(iob) - for (name, source_dict) in sort!(collect(sources); by = first) - # Sort the source attributes for deterministic hashing - for (key, val) in sort!(collect(source_dict); by = first) - println(iob, name, ".", key, "=", val) - end - end str = String(take!(iob)) return bytes2hex(sha1(str)) end diff --git a/test/sources.jl b/test/sources.jl index 2070a2c06a..ce8cd50f55 100644 --- a/test/sources.jl +++ b/test/sources.jl @@ -240,7 +240,7 @@ temp_pkg_dir() do project_path end end - @testset "changing rev in sources updates project_hash and git-tree-sha1 (#4157)" begin + @testset "changing rev in sources updates git-tree-sha1 (#4157)" begin isolate() do mktempdir() do tmp # Create a test package with two commits @@ -297,7 +297,6 @@ temp_pkg_dir() do project_path Pkg.resolve() @test isfile("Manifest.toml") manifest = Pkg.Types.read_manifest("Manifest.toml") - first_project_hash = manifest.project_hash # Verify first state test_pkg_uuid = UUID("b4017d7c-a742-4580-99f2-e286571e6290") @@ -320,14 +319,12 @@ temp_pkg_dir() do project_path Pkg.resolve() manifest = Pkg.Types.read_manifest("Manifest.toml") - second_project_hash = manifest.project_hash - # Verify second state - both project_hash and git-tree-sha1 should change + # Verify second state - git-tree-sha1 should change test_pkg_entry = manifest[test_pkg_uuid] @test test_pkg_entry.tree_hash !== nothing @test string(test_pkg_entry.tree_hash) == second_tree_hash @test test_pkg_entry.repo.rev == second_commit - @test second_project_hash != first_project_hash end end end diff --git a/test/workspaces.jl b/test/workspaces.jl index 66c75488d4..14935b0eb5 100644 --- a/test/workspaces.jl +++ b/test/workspaces.jl @@ -130,10 +130,7 @@ temp_pkg_dir() do project_path env = Pkg.Types.EnvCache() hash_4 = Pkg.Types.workspace_resolve_hash(env) - # hash_1, hash_2, hash_3 should be equal, but hash_4 differs because - # "test" has TestSpecificPackage in sources while "PrivatePackage/test" doesn't - @test hash_1 == hash_2 == hash_3 - @test hash_4 != hash_3 + @test hash_1 == hash_2 == hash_3 == hash_4 # Test that the subprojects are working depot_path_string = join(Base.DEPOT_PATH, Sys.iswindows() ? ";" : ":")