From 2402762c6f12a44ec6c4ddb07910927366747879 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 3 Jan 2024 16:29:56 -0800 Subject: [PATCH] julia.withPackages: fix transitive weak-deps resolving --- .../julia-modules/package-closure.nix | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/pkgs/development/julia-modules/package-closure.nix b/pkgs/development/julia-modules/package-closure.nix index 2862e30f0b8b..d1138394e993 100644 --- a/pkgs/development/julia-modules/package-closure.nix +++ b/pkgs/development/julia-modules/package-closure.nix @@ -78,23 +78,27 @@ let pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, PRESERVE_NONE, ctx.julia_version) if VERSION >= VersionNumber("1.9") - # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs. - # Build up weak_name_to_uuid - uuid_to_name = Dict() - for pkg in pkgs - uuid_to_name[pkg.uuid] = pkg.name - end - weak_name_to_uuid = Dict() - for (uuid, deps) in pairs(deps_map) - for (dep_name, dep_uuid) in pairs(deps) - if !haskey(uuid_to_name, dep_uuid) - weak_name_to_uuid[dep_name] = dep_uuid + while true + # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs. + # Build up weak_name_to_uuid + uuid_to_name = Dict() + for pkg in pkgs + uuid_to_name[pkg.uuid] = pkg.name + end + weak_name_to_uuid = Dict() + for (uuid, deps) in pairs(deps_map) + for (dep_name, dep_uuid) in pairs(deps) + if !haskey(uuid_to_name, dep_uuid) + weak_name_to_uuid[dep_name] = dep_uuid + end end end - end - # If we have nontrivial weak dependencies, add each one to the initial pkgs and then re-run _resolve - if !isempty(weak_name_to_uuid) + if isempty(weak_name_to_uuid) + break + end + + # We have nontrivial weak dependencies, so add each one to the initial pkgs and then re-run _resolve println("Found weak dependencies: $(keys(weak_name_to_uuid))") orig_uuids = Set([pkg.uuid for pkg in orig_pkgs]) @@ -113,7 +117,7 @@ let orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, false) end - pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version) + global pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version) end end '';