Skip to content

Commit

Permalink
load_path_setup_code(): utility to replicate depot and load paths.
Browse files Browse the repository at this point in the history
We do this in a number of places, now you can update the code for
this in a single place and fix all of the usages. This unsets the
home and active projects but puts the fully expanded values of
Base.load_path() into LOAD_PATH and similarly with DEPOT_PATH.
  • Loading branch information
StefanKarpinski committed Jul 3, 2018
1 parent d81031a commit cfdad77
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
21 changes: 15 additions & 6 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,20 @@ function evalfile(path::AbstractString, args::Vector{String}=String[])
end
evalfile(path::AbstractString, args::Vector) = evalfile(path, String[args...])

function load_path_setup_code(load_path::Bool=true)
code = """
append!(empty!(Base.DEPOT_PATH), $(repr(map(abspath, DEPOT_PATH))))
append!(empty!(Base.DL_LOAD_PATH), $(repr(map(abspath, DL_LOAD_PATH))))
"""
if load_path
code *= """
append!(empty!(Base.LOAD_PATH), $(repr(map(abspath, Base.load_path()))))
Base.HOME_PROJECT[] = Base.ACTIVE_PROJECT[] = nothing
"""
end
return code
end

function create_expr_cache(input::String, output::String, concrete_deps::typeof(_concrete_dependencies), uuid::Union{Nothing,UUID})
rm(output, force=true) # Remove file if it exists
code_object = """
Expand All @@ -1091,12 +1105,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
write(in, """
begin
import OldPkg
empty!(Base.LOAD_PATH)
append!(Base.LOAD_PATH, $(repr(LOAD_PATH, context=:module=>nothing)))
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH)))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(DL_LOAD_PATH)))
$(Base.load_path_setup_code())
Base._track_dependencies[] = true
empty!(Base._concrete_dependencies)
""")
Expand Down
7 changes: 1 addition & 6 deletions stdlib/OldPkg/src/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,7 @@ function build(pkg::AbstractString, build_file::AbstractString, errfile::Abstrac
# a separate process. Errors are written to errfile for later reporting.
code = """
import OldPkg
empty!(Base.LOAD_PATH)
append!(Base.LOAD_PATH, $(repr(LOAD_PATH, context=:module=>nothing)))
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH)))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(Base.DL_LOAD_PATH)))
$(Base.load_path_setup_code())
open("$(escape_string(errfile))", "a") do f
pkg, build_file = "$pkg", "$(escape_string(build_file))"
try
Expand Down
7 changes: 1 addition & 6 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,7 @@ function precompile(ctx::Context)
for (i, pkg) in enumerate(needs_to_be_precompiled)
code = """
import OldPkg
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(map(abspath, DEPOT_PATH))))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(map(abspath, Base.DL_LOAD_PATH))))
empty!(Base.LOAD_PATH)
append!(Base.LOAD_PATH, $(repr(Base.LOAD_PATH)))
$(Base.load_path_setup_code())
import $pkg
"""
printpkgstyle(ctx, :Precompiling, pkg * " [$i of $(length(needs_to_be_precompiled))]")
Expand Down
10 changes: 2 additions & 8 deletions stdlib/Pkg/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,7 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
printpkgstyle(ctx, :Building,
rpad(name * " ", max_name + 1, "") * "" * Types.pathrepr(ctx, log_file))
code = """
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(map(abspath, DEPOT_PATH))))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(map(abspath, Base.DL_LOAD_PATH))))
$(Base.load_path_setup_code(false))
cd($(repr(dirname(build_file))))
include($(repr(build_file)))
"""
Expand Down Expand Up @@ -1191,10 +1188,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false)
continue
end
code = """
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(map(abspath, DEPOT_PATH))))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(map(abspath, Base.DL_LOAD_PATH))))
$(Base.load_path_setup_code(false))
cd($(repr(dirname(testfile))))
include($(repr(testfile)))
"""
Expand Down

0 comments on commit cfdad77

Please sign in to comment.