Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1import Pkg.API: handle_package_input! 2import Pkg.Types: PRESERVE_NONE, UUID, VersionSpec, project_deps_resolve!, registry_resolve!, stdlib_resolve!, ensure_resolved 3import Pkg.Operations: _resolve, assert_can_add, update_package_add 4import TOML 5 6foreach(handle_package_input!, pkgs) 7 8# The handle_package_input! call above clears pkg.path, so we have to apply package overrides after 9println("Package overrides: ") 10println(overrides) 11for 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 27end 28 29project_deps_resolve!(ctx.env, pkgs) 30registry_resolve!(ctx.registries, pkgs) 31stdlib_resolve!(pkgs) 32ensure_resolved(ctx, ctx.env.manifest, pkgs, registry=true) 33 34assert_can_add(ctx, pkgs) 35 36for (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 if VERSION >= VersionNumber("1.11") 40 pkgs[i] = update_package_add(ctx, pkg, entry, nothing, nothing, is_dep) 41 else 42 pkgs[i] = update_package_add(ctx, pkg, entry, is_dep) 43 end 44end 45 46foreach(pkg -> ctx.env.project.deps[pkg.name] = pkg.uuid, pkgs) 47 48# Save the original pkgs for later. We might need to augment it with the weak dependencies 49orig_pkgs = pkgs 50 51pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, pkgs, PRESERVE_NONE, ctx.julia_version) 52 53if VERSION >= VersionNumber("1.9") 54 while true 55 # Check for weak dependencies, which appear on the RHS of the deps_map but not in pkgs. 56 # Build up weak_name_to_uuid 57 uuid_to_name = Dict() 58 for pkg in pkgs 59 uuid_to_name[pkg.uuid] = pkg.name 60 end 61 weak_name_to_uuid = Dict() 62 for (uuid, deps) in pairs(deps_map) 63 for (dep_name, dep_uuid) in pairs(deps) 64 if !haskey(uuid_to_name, dep_uuid) 65 weak_name_to_uuid[dep_name] = dep_uuid 66 end 67 end 68 end 69 70 if isempty(weak_name_to_uuid) 71 break 72 end 73 74 # We have nontrivial weak dependencies, so add each one to the initial pkgs and then re-run _resolve 75 println("Found weak dependencies: $(keys(weak_name_to_uuid))") 76 77 orig_uuids = Set([pkg.uuid for pkg in orig_pkgs]) 78 79 for (name, uuid) in pairs(weak_name_to_uuid) 80 if uuid in orig_uuids 81 continue 82 end 83 84 pkg = PackageSpec(name, uuid) 85 86 push!(orig_uuids, uuid) 87 push!(orig_pkgs, pkg) 88 ctx.env.project.deps[name] = uuid 89 entry = Pkg.Types.manifest_info(ctx.env.manifest, uuid) 90 if VERSION >= VersionNumber("1.11") 91 orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, nothing, nothing, false) 92 else 93 orig_pkgs[length(orig_pkgs)] = update_package_add(ctx, pkg, entry, false) 94 end 95 end 96 97 global pkgs, deps_map = _resolve(ctx.io, ctx.env, ctx.registries, orig_pkgs, PRESERVE_NONE, ctx.julia_version) 98 end 99end