diff --git a/src/julia-1.9/activate_set.jl b/src/julia-1.9/activate_set.jl index 20cc47f..b065311 100644 --- a/src/julia-1.9/activate_set.jl +++ b/src/julia-1.9/activate_set.jl @@ -11,12 +11,24 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true) # 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") + source_path = pkgspec.path::String + sandbox_path = joinpath(source_path, "test") sandbox_project = projectfile_path(sandbox_path) + sandbox_preferences = nothing + if isfile(sandbox_project) + with_load_path([sandbox_path, Base.LOAD_PATH...]) do + sandbox_preferences = Base.get_preferences() + end + else + with_load_path([something(projectfile_path(source_path)), Base.LOAD_PATH...]) do + sandbox_preferences = Base.get_preferences() + end + end tmp = mktempdir() tmp_project = projectfile_path(tmp) tmp_manifest = manifestfile_path(tmp) + tmp_preferences = joinpath(tmp, first(Base.preferences_names)) # Copy env info over to temp env if sandbox_project_override !== nothing @@ -48,6 +60,13 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true) end Types.write_manifest(working_manifest, tmp_manifest) + # Copy over preferences + if sandbox_preferences !== nothing + open(tmp_preferences, "w") do io + # TODO: should we separately import TOML? + Pkg.TOML.print(io, sandbox_preferences::Dict{String, Any}) + end + end Base.ACTIVE_PROJECT[] = tmp_project @@ -73,3 +92,14 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true) return Base.active_project() end + +with_load_path(f::Function, new_load_path::String) = with_load_path(f, [new_load_path]) +function with_load_path(f::Function, new_load_path::Vector{String}) + old_load_path = copy(Base.LOAD_PATH) + copy!(Base.LOAD_PATH, new_load_path) + try + f() + finally + copy!(LOAD_PATH, old_load_path) + end +end