lol

julia.withPackages: move julia resolve code to its own file

authored by

thomasjm and committed by
Nick Cao
c61ac9e1 ff29338a

+93 -96
+2 -96
pkgs/development/julia-modules/package-closure.nix
··· 10 10 }: 11 11 12 12 let 13 - resolveCode = '' 14 - import Pkg.API: handle_package_input! 15 - import Pkg.Types: PRESERVE_NONE, UUID, VersionSpec, project_deps_resolve!, registry_resolve!, stdlib_resolve!, ensure_resolved 16 - import Pkg.Operations: _resolve, assert_can_add, update_package_add 17 - import TOML 18 - 19 - foreach(handle_package_input!, pkgs) 20 - 21 - # The handle_package_input! call above clears pkg.path, so we have to apply package overrides after 22 - overrides = Dict{String, String}(${builtins.concatStringsSep ", " (lib.mapAttrsToList (name: path: ''"${name}" => "${path}"'') packageOverrides)}) 23 - println("Package overrides: ") 24 - println(overrides) 25 - for pkg in pkgs 26 - if pkg.name in keys(overrides) 27 - pkg.path = overrides[pkg.name] 28 - 29 - # Try to read the UUID from $(pkg.path)/Project.toml. If successful, put the package into ctx.env.project.deps. 30 - # This is necessary for the ensure_resolved call below to succeed, and will allow us to use an override even 31 - # if it does not appear in the registry. 32 - # See https://github.com/NixOS/nixpkgs/issues/279853 33 - project_toml = joinpath(pkg.path, "Project.toml") 34 - if isfile(project_toml) 35 - toml_data = TOML.parsefile(project_toml) 36 - if haskey(toml_data, "uuid") 37 - ctx.env.project.deps[pkg.name] = UUID(toml_data["uuid"]) 38 - end 39 - end 40 - end 41 - end 42 - 43 - project_deps_resolve!(ctx.env, pkgs) 44 - registry_resolve!(ctx.registries, pkgs) 45 - stdlib_resolve!(pkgs) 46 - ensure_resolved(ctx, ctx.env.manifest, pkgs, registry=true) 47 - 48 - assert_can_add(ctx, pkgs) 49 - 50 - for (i, pkg) in pairs(pkgs) 51 - entry = Pkg.Types.manifest_info(ctx.env.manifest, pkg.uuid) 52 - is_dep = any(uuid -> uuid == pkg.uuid, [uuid for (name, uuid) in ctx.env.project.deps]) 53 - pkgs[i] = update_package_add(ctx, pkg, entry, is_dep) 54 - end 55 - 56 - foreach(pkg -> ctx.env.project.deps[pkg.name] = pkg.uuid, pkgs) 57 - 58 - # Save the original pkgs for later. We might need to augment it with the weak dependencies 59 - orig_pkgs = pkgs 60 - 61 - pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, PRESERVE_NONE, ctx.julia_version) 62 - 63 - if VERSION >= VersionNumber("1.9") 64 - while true 65 - # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs. 66 - # Build up weak_name_to_uuid 67 - uuid_to_name = Dict() 68 - for pkg in pkgs 69 - uuid_to_name[pkg.uuid] = pkg.name 70 - end 71 - weak_name_to_uuid = Dict() 72 - for (uuid, deps) in pairs(deps_map) 73 - for (dep_name, dep_uuid) in pairs(deps) 74 - if !haskey(uuid_to_name, dep_uuid) 75 - weak_name_to_uuid[dep_name] = dep_uuid 76 - end 77 - end 78 - end 79 - 80 - if isempty(weak_name_to_uuid) 81 - break 82 - end 83 - 84 - # We have nontrivial weak dependencies, so add each one to the initial pkgs and then re-run _resolve 85 - println("Found weak dependencies: $(keys(weak_name_to_uuid))") 86 - 87 - orig_uuids = Set([pkg.uuid for pkg in orig_pkgs]) 88 - 89 - for (name, uuid) in pairs(weak_name_to_uuid) 90 - if uuid in orig_uuids 91 - continue 92 - end 93 - 94 - pkg = PackageSpec(name, uuid) 95 - 96 - push!(orig_uuids, uuid) 97 - push!(orig_pkgs, pkg) 98 - ctx.env.project.deps[name] = uuid 99 - entry = Pkg.Types.manifest_info(ctx.env.manifest, uuid) 100 - orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, false) 101 - end 102 - 103 - global pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version) 104 - end 105 - end 106 - ''; 107 - 108 13 juliaExpression = packageNames: '' 109 14 import Pkg 110 15 Pkg.Registry.add(Pkg.RegistrySpec(path="${augmentedRegistry}")) ··· 125 30 126 31 ctx = Context() 127 32 128 - ${resolveCode} 33 + overrides = Dict{String, String}(${builtins.concatStringsSep ", " (lib.mapAttrsToList (name: path: ''"${name}" => "${path}"'') packageOverrides)}) 34 + ${builtins.readFile ./resolve_packages.jl} 129 35 130 36 open(ENV["out"], "w") do io 131 37 for spec in pkgs
+91
pkgs/development/julia-modules/resolve_packages.jl
··· 1 + import Pkg.API: handle_package_input! 2 + import Pkg.Types: PRESERVE_NONE, UUID, VersionSpec, project_deps_resolve!, registry_resolve!, stdlib_resolve!, ensure_resolved 3 + import Pkg.Operations: _resolve, assert_can_add, update_package_add 4 + import TOML 5 + 6 + foreach(handle_package_input!, pkgs) 7 + 8 + # The handle_package_input! call above clears pkg.path, so we have to apply package overrides after 9 + println("Package overrides: ") 10 + println(overrides) 11 + for pkg in pkgs 12 + if pkg.name in keys(overrides) 13 + pkg.path = overrides[pkg.name] 14 + 15 + # Try to read the UUID from $(pkg.path)/Project.toml. If successful, put the package into ctx.env.project.deps. 16 + # This is necessary for the ensure_resolved call below to succeed, and will allow us to use an override even 17 + # if it does not appear in the registry. 18 + # See https://github.com/NixOS/nixpkgs/issues/279853 19 + project_toml = joinpath(pkg.path, "Project.toml") 20 + if isfile(project_toml) 21 + toml_data = TOML.parsefile(project_toml) 22 + if haskey(toml_data, "uuid") 23 + ctx.env.project.deps[pkg.name] = UUID(toml_data["uuid"]) 24 + end 25 + end 26 + end 27 + end 28 + 29 + project_deps_resolve!(ctx.env, pkgs) 30 + registry_resolve!(ctx.registries, pkgs) 31 + stdlib_resolve!(pkgs) 32 + ensure_resolved(ctx, ctx.env.manifest, pkgs, registry=true) 33 + 34 + assert_can_add(ctx, pkgs) 35 + 36 + for (i, pkg) in pairs(pkgs) 37 + entry = Pkg.Types.manifest_info(ctx.env.manifest, pkg.uuid) 38 + is_dep = any(uuid -> uuid == pkg.uuid, [uuid for (name, uuid) in ctx.env.project.deps]) 39 + pkgs[i] = update_package_add(ctx, pkg, entry, is_dep) 40 + end 41 + 42 + foreach(pkg -> ctx.env.project.deps[pkg.name] = pkg.uuid, pkgs) 43 + 44 + # Save the original pkgs for later. We might need to augment it with the weak dependencies 45 + orig_pkgs = pkgs 46 + 47 + pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, PRESERVE_NONE, ctx.julia_version) 48 + 49 + if VERSION >= VersionNumber("1.9") 50 + while true 51 + # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs. 52 + # Build up weak_name_to_uuid 53 + uuid_to_name = Dict() 54 + for pkg in pkgs 55 + uuid_to_name[pkg.uuid] = pkg.name 56 + end 57 + weak_name_to_uuid = Dict() 58 + for (uuid, deps) in pairs(deps_map) 59 + for (dep_name, dep_uuid) in pairs(deps) 60 + if !haskey(uuid_to_name, dep_uuid) 61 + weak_name_to_uuid[dep_name] = dep_uuid 62 + end 63 + end 64 + end 65 + 66 + if isempty(weak_name_to_uuid) 67 + break 68 + end 69 + 70 + # We have nontrivial weak dependencies, so add each one to the initial pkgs and then re-run _resolve 71 + println("Found weak dependencies: $(keys(weak_name_to_uuid))") 72 + 73 + orig_uuids = Set([pkg.uuid for pkg in orig_pkgs]) 74 + 75 + for (name, uuid) in pairs(weak_name_to_uuid) 76 + if uuid in orig_uuids 77 + continue 78 + end 79 + 80 + pkg = PackageSpec(name, uuid) 81 + 82 + push!(orig_uuids, uuid) 83 + push!(orig_pkgs, pkg) 84 + ctx.env.project.deps[name] = uuid 85 + entry = Pkg.Types.manifest_info(ctx.env.manifest, uuid) 86 + orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, false) 87 + end 88 + 89 + global pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version) 90 + end 91 + end