-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathactivate_set.jl
More file actions
80 lines (66 loc) · 2.84 KB
/
activate_set.jl
File metadata and controls
80 lines (66 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Originally from Pkg.Operations.sandbox
"""
TestEnv.activate([pkg]; allow_reresolve=true)
Activate the test enviroment of `pkg` (defaults to current enviroment).
"""
function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
ctx, pkgspec = ctx_and_pkgspec(pkg)
# This needs to be first as `gen_target_project` fixes `pkgspec.path` if it is nothing
sandbox_project_override = maybe_gen_project_override!(ctx, pkgspec)
sandbox_path = joinpath(pkgspec.path::String, "test")
sandbox_project = projectfile_path(sandbox_path)
tmp = mktempdir()
tmp_project = projectfile_path(tmp)
tmp_manifest = manifestfile_path(tmp)
# Copy env info over to temp env
if sandbox_project_override !== nothing
Types.write_project(sandbox_project_override, tmp_project)
elseif isfile(sandbox_project)
cp(sandbox_project, tmp_project)
chmod(tmp_project, 0o600)
end
# create merged manifest
# - copy over active subgraph
# - abspath! to maintain location of all deved nodes
working_manifest = abspath!(ctx.env, sandbox_preserve(ctx.env, pkgspec, tmp_project))
# - copy over fixed subgraphs from test subgraph
# really only need to copy over "special" nodes
sandbox_env = Types.EnvCache(projectfile_path(sandbox_path))
sandbox_manifest = abspath!(sandbox_env, sandbox_env.manifest)
for (name, uuid) in sandbox_env.project.deps
entry = get(sandbox_manifest, uuid, nothing)
if entry !== nothing && isfixed(entry)
subgraph = Pkg.Operations.prune_manifest(sandbox_manifest, [uuid])
for (uuid, entry) in subgraph
if haskey(working_manifest, uuid)
Pkg.Operations.pkgerror("can not merge projects")
end
working_manifest[uuid] = entry
end
end
end
Types.write_manifest(working_manifest, tmp_manifest)
Base.ACTIVE_PROJECT[] = tmp_project
temp_ctx = Context()
temp_ctx.env.project.deps[pkgspec.name] = pkgspec.uuid
try
Pkg.resolve(temp_ctx; io=devnull)
@debug "Using _parent_ dep graph"
catch err# TODO
allow_reresolve || rethrow()
@debug err
@warn "Could not use exact versions of packages in manifest, re-resolving"
temp_ctx.env.manifest.deps = Dict(
uuid => entry for
(uuid, entry) in temp_ctx.env.manifest.deps if isfixed(entry)
)
Pkg.resolve(temp_ctx; io=devnull)
@debug "Using _clean_ dep graph"
end
# Now that we have set up the sandbox environment, precompile all its packages:
# (Reconnect the `io` back to the original context so the caller can see the
# precompilation progress.)
Pkg._auto_precompile(temp_ctx; already_instantiated=true)
write_env(temp_ctx.env; update_undo=false)
return Base.active_project()
end