From 7d84e46cbeb7e78d71372aaa6ea4a3596c0f5016 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 24 Aug 2018 21:12:14 +0200 Subject: [PATCH] Absolutify project path specified with --project and JULIA_PROJECT. (#28625) (cherry picked from commit eb8a9333b040b8dc86b2ed7a93bb23e70830cf14) --- base/initdefs.jl | 3 ++- src/init.c | 2 ++ test/loading.jl | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/base/initdefs.jl b/base/initdefs.jl index 0846a47534886..d93590af4d63c 100644 --- a/base/initdefs.jl +++ b/base/initdefs.jl @@ -138,8 +138,9 @@ function init_load_path() unsafe_string(Base.JLOptions().project) : get(ENV, "JULIA_PROJECT", nothing)) HOME_PROJECT[] = + project == nothing ? nothing : project == "" ? nothing : - project == "@." ? current_project() : project + project == "@." ? current_project() : abspath(project) append!(empty!(LOAD_PATH), paths) end diff --git a/src/init.c b/src/init.c index b293ab1a44b88..64a82792b685f 100644 --- a/src/init.c +++ b/src/init.c @@ -592,6 +592,8 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel) jl_options.outputbc = abspath(jl_options.outputbc, 0); if (jl_options.machine_file) jl_options.machine_file = abspath(jl_options.machine_file, 0); + if (jl_options.project && strncmp(jl_options.project, "@.", strlen(jl_options.project)) != 0) + jl_options.project = abspath(jl_options.project, 0); const char **cmdp = jl_options.cmds; if (cmdp) { diff --git a/test/loading.jl b/test/loading.jl index 289c25e582b0a..259f55a87c999 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -547,6 +547,22 @@ finally popfirst!(LOAD_PATH) end +@testset "--project and JULIA_PROJECT paths should be absolutified" begin + mktempdir() do dir; cd(dir) do + mkdir("foo") + script = """ + using Test + old = Base.active_project() + cd("foo") + @test Base.active_project() == old + """ + @test success(`$(Base.julia_cmd()) --project=foo -e $(script)`) + withenv("JULIA_PROJECT" => "foo") do + @test success(`$(Base.julia_cmd()) -e $(script)`) + end + end; end +end + ## cleanup after tests ## for env in keys(envs)