···1010}:
11111212let
1313- resolveCode = ''
1414- import Pkg.API: handle_package_input!
1515- import Pkg.Types: PRESERVE_NONE, UUID, VersionSpec, project_deps_resolve!, registry_resolve!, stdlib_resolve!, ensure_resolved
1616- import Pkg.Operations: _resolve, assert_can_add, update_package_add
1717- import TOML
1818-1919- foreach(handle_package_input!, pkgs)
2020-2121- # The handle_package_input! call above clears pkg.path, so we have to apply package overrides after
2222- overrides = Dict{String, String}(${builtins.concatStringsSep ", " (lib.mapAttrsToList (name: path: ''"${name}" => "${path}"'') packageOverrides)})
2323- println("Package overrides: ")
2424- println(overrides)
2525- for pkg in pkgs
2626- if pkg.name in keys(overrides)
2727- pkg.path = overrides[pkg.name]
2828-2929- # Try to read the UUID from $(pkg.path)/Project.toml. If successful, put the package into ctx.env.project.deps.
3030- # This is necessary for the ensure_resolved call below to succeed, and will allow us to use an override even
3131- # if it does not appear in the registry.
3232- # See https://github.com/NixOS/nixpkgs/issues/279853
3333- project_toml = joinpath(pkg.path, "Project.toml")
3434- if isfile(project_toml)
3535- toml_data = TOML.parsefile(project_toml)
3636- if haskey(toml_data, "uuid")
3737- ctx.env.project.deps[pkg.name] = UUID(toml_data["uuid"])
3838- end
3939- end
4040- end
4141- end
4242-4343- project_deps_resolve!(ctx.env, pkgs)
4444- registry_resolve!(ctx.registries, pkgs)
4545- stdlib_resolve!(pkgs)
4646- ensure_resolved(ctx, ctx.env.manifest, pkgs, registry=true)
4747-4848- assert_can_add(ctx, pkgs)
4949-5050- for (i, pkg) in pairs(pkgs)
5151- entry = Pkg.Types.manifest_info(ctx.env.manifest, pkg.uuid)
5252- is_dep = any(uuid -> uuid == pkg.uuid, [uuid for (name, uuid) in ctx.env.project.deps])
5353- pkgs[i] = update_package_add(ctx, pkg, entry, is_dep)
5454- end
5555-5656- foreach(pkg -> ctx.env.project.deps[pkg.name] = pkg.uuid, pkgs)
5757-5858- # Save the original pkgs for later. We might need to augment it with the weak dependencies
5959- orig_pkgs = pkgs
6060-6161- pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, PRESERVE_NONE, ctx.julia_version)
6262-6363- if VERSION >= VersionNumber("1.9")
6464- while true
6565- # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs.
6666- # Build up weak_name_to_uuid
6767- uuid_to_name = Dict()
6868- for pkg in pkgs
6969- uuid_to_name[pkg.uuid] = pkg.name
7070- end
7171- weak_name_to_uuid = Dict()
7272- for (uuid, deps) in pairs(deps_map)
7373- for (dep_name, dep_uuid) in pairs(deps)
7474- if !haskey(uuid_to_name, dep_uuid)
7575- weak_name_to_uuid[dep_name] = dep_uuid
7676- end
7777- end
7878- end
7979-8080- if isempty(weak_name_to_uuid)
8181- break
8282- end
8383-8484- # We have nontrivial weak dependencies, so add each one to the initial pkgs and then re-run _resolve
8585- println("Found weak dependencies: $(keys(weak_name_to_uuid))")
8686-8787- orig_uuids = Set([pkg.uuid for pkg in orig_pkgs])
8888-8989- for (name, uuid) in pairs(weak_name_to_uuid)
9090- if uuid in orig_uuids
9191- continue
9292- end
9393-9494- pkg = PackageSpec(name, uuid)
9595-9696- push!(orig_uuids, uuid)
9797- push!(orig_pkgs, pkg)
9898- ctx.env.project.deps[name] = uuid
9999- entry = Pkg.Types.manifest_info(ctx.env.manifest, uuid)
100100- orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, false)
101101- end
102102-103103- global pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version)
104104- end
105105- end
106106- '';
107107-10813 juliaExpression = packageNames: ''
10914 import Pkg
11015 Pkg.Registry.add(Pkg.RegistrySpec(path="${augmentedRegistry}"))
···1253012631 ctx = Context()
12732128128- ${resolveCode}
3333+ overrides = Dict{String, String}(${builtins.concatStringsSep ", " (lib.mapAttrsToList (name: path: ''"${name}" => "${path}"'') packageOverrides)})
3434+ ${builtins.readFile ./resolve_packages.jl}
1293513036 open(ENV["out"], "w") do io
13137 for spec in pkgs
···11+import Pkg.API: handle_package_input!
22+import Pkg.Types: PRESERVE_NONE, UUID, VersionSpec, project_deps_resolve!, registry_resolve!, stdlib_resolve!, ensure_resolved
33+import Pkg.Operations: _resolve, assert_can_add, update_package_add
44+import TOML
55+66+foreach(handle_package_input!, pkgs)
77+88+# The handle_package_input! call above clears pkg.path, so we have to apply package overrides after
99+println("Package overrides: ")
1010+println(overrides)
1111+for pkg in pkgs
1212+ if pkg.name in keys(overrides)
1313+ pkg.path = overrides[pkg.name]
1414+1515+ # Try to read the UUID from $(pkg.path)/Project.toml. If successful, put the package into ctx.env.project.deps.
1616+ # This is necessary for the ensure_resolved call below to succeed, and will allow us to use an override even
1717+ # if it does not appear in the registry.
1818+ # See https://github.com/NixOS/nixpkgs/issues/279853
1919+ project_toml = joinpath(pkg.path, "Project.toml")
2020+ if isfile(project_toml)
2121+ toml_data = TOML.parsefile(project_toml)
2222+ if haskey(toml_data, "uuid")
2323+ ctx.env.project.deps[pkg.name] = UUID(toml_data["uuid"])
2424+ end
2525+ end
2626+ end
2727+end
2828+2929+project_deps_resolve!(ctx.env, pkgs)
3030+registry_resolve!(ctx.registries, pkgs)
3131+stdlib_resolve!(pkgs)
3232+ensure_resolved(ctx, ctx.env.manifest, pkgs, registry=true)
3333+3434+assert_can_add(ctx, pkgs)
3535+3636+for (i, pkg) in pairs(pkgs)
3737+ entry = Pkg.Types.manifest_info(ctx.env.manifest, pkg.uuid)
3838+ is_dep = any(uuid -> uuid == pkg.uuid, [uuid for (name, uuid) in ctx.env.project.deps])
3939+ pkgs[i] = update_package_add(ctx, pkg, entry, is_dep)
4040+end
4141+4242+foreach(pkg -> ctx.env.project.deps[pkg.name] = pkg.uuid, pkgs)
4343+4444+# Save the original pkgs for later. We might need to augment it with the weak dependencies
4545+orig_pkgs = pkgs
4646+4747+pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, PRESERVE_NONE, ctx.julia_version)
4848+4949+if VERSION >= VersionNumber("1.9")
5050+ while true
5151+ # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs.
5252+ # Build up weak_name_to_uuid
5353+ uuid_to_name = Dict()
5454+ for pkg in pkgs
5555+ uuid_to_name[pkg.uuid] = pkg.name
5656+ end
5757+ weak_name_to_uuid = Dict()
5858+ for (uuid, deps) in pairs(deps_map)
5959+ for (dep_name, dep_uuid) in pairs(deps)
6060+ if !haskey(uuid_to_name, dep_uuid)
6161+ weak_name_to_uuid[dep_name] = dep_uuid
6262+ end
6363+ end
6464+ end
6565+6666+ if isempty(weak_name_to_uuid)
6767+ break
6868+ end
6969+7070+ # We have nontrivial weak dependencies, so add each one to the initial pkgs and then re-run _resolve
7171+ println("Found weak dependencies: $(keys(weak_name_to_uuid))")
7272+7373+ orig_uuids = Set([pkg.uuid for pkg in orig_pkgs])
7474+7575+ for (name, uuid) in pairs(weak_name_to_uuid)
7676+ if uuid in orig_uuids
7777+ continue
7878+ end
7979+8080+ pkg = PackageSpec(name, uuid)
8181+8282+ push!(orig_uuids, uuid)
8383+ push!(orig_pkgs, pkg)
8484+ ctx.env.project.deps[name] = uuid
8585+ entry = Pkg.Types.manifest_info(ctx.env.manifest, uuid)
8686+ orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, false)
8787+ end
8888+8989+ global pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version)
9090+ end
9191+end