From d031439b25def84dec64239377ad2ee0c6dc222a Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Fri, 15 Dec 2017 04:42:52 -0500 Subject: [PATCH] rename JULIA_HOME => Sys.BINDIR [fix #20899] ENV["JULIA_HOME"] => ENV["JULIA_BINDIR"] --- NEWS.md | 7 ++++-- base/client.jl | 8 +++--- base/deprecated.jl | 2 ++ base/exports.jl | 1 - base/initdefs.jl | 18 +++++--------- base/interactiveutil.jl | 2 +- base/libgit2/libgit2.jl | 2 +- base/loading.jl | 2 +- base/options.jl | 2 +- base/sysimg.jl | 2 +- base/sysinfo.jl | 15 ++++++++++-- base/util.jl | 2 +- contrib/build_sysimg.jl | 6 ++--- contrib/julia-config.jl | 4 +-- contrib/mac/juliarc.jl | 4 +-- doc/src/devdocs/sysimg.md | 2 +- doc/src/manual/embedding.md | 4 +-- doc/src/manual/environment-variables.md | 20 +++++++-------- doc/src/manual/unicode-input.md | 2 +- doc/src/stdlib/constants.md | 2 +- examples/embedding/Makefile | 2 +- examples/embedding/embedding-test.jl | 2 +- src/codegen.cpp | 2 +- src/dlload.c | 2 +- src/init.c | 27 ++++++++++++++------- src/jlapi.c | 8 +++--- src/jloptions.c | 6 ++--- src/julia.h | 4 +-- stdlib/Distributed/src/cluster.jl | 2 +- stdlib/Distributed/src/managers.jl | 4 +-- stdlib/Distributed/test/distributed_exec.jl | 6 ++--- stdlib/Distributed/test/runtests.jl | 2 +- stdlib/SharedArrays/test/runtests.jl | 2 +- stdlib/SuiteSparse/test/cholmod.jl | 2 +- test/choosetests.jl | 4 +-- test/cmdlineargs.jl | 12 ++++----- test/examples.jl | 2 +- test/spawn.jl | 2 +- test/testenv.jl | 2 +- 39 files changed, 109 insertions(+), 91 deletions(-) diff --git a/NEWS.md b/NEWS.md index 46fa26c0721c7..d1395d0ff2556 100644 --- a/NEWS.md +++ b/NEWS.md @@ -461,6 +461,9 @@ Compiler/Runtime improvements Deprecated or removed --------------------- + * The `JULIA_HOME` environment variable has been renamed to `JULIA_BINDIR` and + `Base.JULIA_HOME` has been moved to `Sys.BINDIR` ([#20899]). + * The keyword `immutable` is fully deprecated to `struct`, and `type` is fully deprecated to `mutable struct` ([#19157], [#20418]). @@ -613,8 +616,8 @@ Deprecated or removed `serialize` ([#6466]). * The default `juliarc.jl` file on Windows has been removed. Now must explicitly include the - full path if you need access to executables or libraries in the `JULIA_HOME` directory, e.g. - `joinpath(JULIA_HOME, "7z.exe")` for `7z.exe` ([#21540]). + full path if you need access to executables or libraries in the `Sys.BINDIR` directory, e.g. + `joinpath(Sys.BINDIR, "7z.exe")` for `7z.exe` ([#21540]). * `sqrtm` has been deprecated in favor of `sqrt` ([#23504]). diff --git a/base/client.jl b/base/client.jl index 26014d026a668..9b85cdc08b1aa 100644 --- a/base/client.jl +++ b/base/client.jl @@ -327,11 +327,11 @@ end function load_juliarc() # If the user built us with a specific Base.SYSCONFDIR, check that location first for a juliarc.jl file - # If it is not found, then continue on to the relative path based on JULIA_HOME - if !isempty(Base.SYSCONFDIR) && isfile(joinpath(JULIA_HOME, Base.SYSCONFDIR, "julia", "juliarc.jl")) - include(Main, abspath(JULIA_HOME, Base.SYSCONFDIR, "julia", "juliarc.jl")) + # If it is not found, then continue on to the relative path based on Sys.BINDIR + if !isempty(Base.SYSCONFDIR) && isfile(joinpath(Sys.BINDIR, Base.SYSCONFDIR, "julia", "juliarc.jl")) + include(Main, abspath(Sys.BINDIR, Base.SYSCONFDIR, "julia", "juliarc.jl")) else - try_include(Main, abspath(JULIA_HOME, "..", "etc", "julia", "juliarc.jl")) + try_include(Main, abspath(Sys.BINDIR, "..", "etc", "julia", "juliarc.jl")) end try_include(Main, abspath(homedir(), ".juliarc.jl")) nothing diff --git a/base/deprecated.jl b/base/deprecated.jl index a92e96b77d287..a4305ff219780 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2166,6 +2166,8 @@ end # issue #20899 # TODO: delete cpu_name deprecation in base/sysinfo.jl +# TODO: delete JULIA_HOME deprecation in src/init.c +# TODO: delete JULIA_HOME deprecation in base/initdef.jl @eval LinAlg begin @deprecate chol!(x::Number, uplo) chol(x) false diff --git a/base/exports.jl b/base/exports.jl index 3d2c355994b1d..6981ab1818aa3 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -160,7 +160,6 @@ export C_NULL, ENDIAN_BOM, ENV, - JULIA_HOME, LOAD_PATH, PROGRAM_FILE, STDERR, diff --git a/base/initdefs.jl b/base/initdefs.jl index 3b2c9bac4a8ca..e0bf094c8a8df 100644 --- a/base/initdefs.jl +++ b/base/initdefs.jl @@ -59,18 +59,19 @@ code. const LOAD_PATH = String[] const LOAD_CACHE_PATH = String[] -function init_load_path(JULIA_HOME = JULIA_HOME) +function init_load_path(BINDIR = Sys.BINDIR) vers = "v$(VERSION.major).$(VERSION.minor)" if haskey(ENV, "JULIA_LOAD_PATH") prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static Sys.iswindows() ? ';' : ':')) end - push!(LOAD_PATH, abspath(JULIA_HOME, "..", "local", "share", "julia", "site", vers)) - push!(LOAD_PATH, abspath(JULIA_HOME, "..", "share", "julia", "site", vers)) - #push!(LOAD_CACHE_PATH, abspath(JULIA_HOME, "..", "lib", "julia")) #TODO: add a builtin location? + push!(LOAD_PATH, abspath(BINDIR, "..", "local", "share", "julia", "site", vers)) + push!(LOAD_PATH, abspath(BINDIR, "..", "share", "julia", "site", vers)) + #push!(LOAD_CACHE_PATH, abspath(BINDIR, "..", "lib", "julia")) #TODO: add a builtin location? end function early_init() - global const JULIA_HOME = ccall(:jl_get_julia_home, Any, ()) + Sys._early_init() + @eval @deprecate_binding JULIA_HOME Sys.BINDIR # make sure OpenBLAS does not set CPU affinity (#1070, #9639) ENV["OPENBLAS_MAIN_FREE"] = get(ENV, "OPENBLAS_MAIN_FREE", get(ENV, "GOTOBLAS_MAIN_FREE", "1")) @@ -80,13 +81,6 @@ function early_init() end end -""" - JULIA_HOME - -A string containing the full path to the directory containing the `julia` executable. -""" -:JULIA_HOME - const atexit_hooks = [] """ diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 4d2742386d339..94ab2abf35a1e 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -690,7 +690,7 @@ function runtests(tests = ["all"], numcores = ceil(Int, Sys.CPU_CORES / 2); ENV2 = copy(ENV) ENV2["JULIA_CPU_CORES"] = "$numcores" try - run(setenv(`$(julia_cmd()) $(joinpath(JULIA_HOME, + run(setenv(`$(julia_cmd()) $(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "test", "runtests.jl")) $tests`, ENV2)) catch buf = PipeBuffer() diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index 91ecc806b7e96..98b68650c2f7a 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -939,7 +939,7 @@ function __init__() ENV["SSL_CERT_FILE"] else # If we have a bundled ca cert file, point libgit2 at that so SSL connections work. - abspath(ccall(:jl_get_julia_home, Any, ()), Base.DATAROOTDIR, "julia", "cert.pem") + abspath(ccall(:jl_get_julia_bindir, Any, ()), Base.DATAROOTDIR, "julia", "cert.pem") end set_ssl_cert_locations(cert_loc) end diff --git a/base/loading.jl b/base/loading.jl index b1a4fa6732692..8f894f32a5d59 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -100,7 +100,7 @@ end function find_source_file(path::String) (isabspath(path) || isfile(path)) && return path - base_path = joinpath(JULIA_HOME, DATAROOTDIR, "julia", "base", path) + base_path = joinpath(Sys.BINDIR, DATAROOTDIR, "julia", "base", path) return isfile(base_path) ? base_path : nothing end diff --git a/base/options.jl b/base/options.jl index 432ca9e205d32..6095f6ac6dfaf 100644 --- a/base/options.jl +++ b/base/options.jl @@ -4,7 +4,7 @@ struct JLOptions quiet::Int8 banner::Int8 - julia_home::Ptr{UInt8} + julia_bindir::Ptr{UInt8} julia_bin::Ptr{UInt8} commands::Ptr{Ptr{UInt8}} # (e)eval, (E)print, (L)load image_file::Ptr{UInt8} diff --git a/base/sysimg.jl b/base/sysimg.jl index fe9676f4f41f9..f2ef498ad9cc3 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -426,7 +426,7 @@ include("threadcall.jl") include("loading.jl") # set up load path to be able to find stdlib packages -init_load_path(ccall(:jl_get_julia_home, Any, ())) +init_load_path(ccall(:jl_get_julia_bindir, Any, ())) INCLUDE_STATE = 3 # include = include_relative diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 18706337b99ba..b52e35137c4d0 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -5,7 +5,8 @@ module Sys Provide methods for retrieving information about hardware and the operating system. """ -> Sys -export CPU_CORES, +export BINDIR, + CPU_CORES, CPU_NAME, WORD_SIZE, ARCH, @@ -26,6 +27,17 @@ export CPU_CORES, import ..Base: show +""" + Sys.BINDIR + +A string containing the full path to the directory containing the `julia` executable. +""" +:BINDIR + +_early_init() = @eval const BINDIR = ccall(:jl_get_julia_bindir, Any, ()) + +# helper to avoid triggering precompile warnings + global CPU_CORES """ Sys.CPU_CORES @@ -66,7 +78,6 @@ Standard word size on the current machine, in bits. const WORD_SIZE = Core.sizeof(Int) * 8 function __init__() - # set CPU core count global CPU_CORES = haskey(ENV,"JULIA_CPU_CORES") ? parse(Int,ENV["JULIA_CPU_CORES"]) : Int(ccall(:jl_cpu_cores, Int32, ())) diff --git a/base/util.jl b/base/util.jl index 9a600fb6506c7..3bf04e790211e 100644 --- a/base/util.jl +++ b/base/util.jl @@ -347,7 +347,7 @@ println_with_color(color::Union{Int, Symbol}, io::IO, msg...; bold::Bool = false println_with_color(color::Union{Int, Symbol}, msg...; bold::Bool = false) = println_with_color(color, STDOUT, msg...; bold = bold) -function julia_cmd(julia=joinpath(JULIA_HOME, julia_exename())) +function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename())) opts = JLOptions() cpu_target = unsafe_string(opts.cpu_target) image_file = unsafe_string(opts.image_file) diff --git a/contrib/build_sysimg.jl b/contrib/build_sysimg.jl index 7b77af8908a07..ed1a1524e0cac 100644 --- a/contrib/build_sysimg.jl +++ b/contrib/build_sysimg.jl @@ -8,7 +8,7 @@ function default_sysimg_path(debug=false) if Sys.isunix() splitext(Libdl.dlpath(debug ? "sys-debug" : "sys"))[1] else - joinpath(dirname(JULIA_HOME), "lib", "julia", debug ? "sys-debug" : "sys") + joinpath(dirname(Sys.BINDIR), "lib", "julia", debug ? "sys-debug" : "sys") end end @@ -17,7 +17,7 @@ end Rebuild the system image. Store it in `sysimg_path`, which defaults to a file named `sys.ji` that sits in the same folder as `libjulia.{so,dylib}`, except on Windows where it defaults -to `JULIA_HOME/../lib/julia/sys.ji`. Use the cpu instruction set given by `cpu_target`. +to `Sys.BINDIR/../lib/julia/sys.ji`. Use the cpu instruction set given by `cpu_target`. Valid CPU targets are the same as for the `-C` option to `julia`, or the `-march` option to `gcc`. Defaults to `native`, which means to use all CPU instructions available on the current processor. Include the user image file given by `userimg_path`, which should contain @@ -46,7 +46,7 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not # Enter base and setup some useful paths base_dir = dirname(Base.find_source_file("sysimg.jl")) cd(base_dir) do - julia = joinpath(JULIA_HOME, debug ? "julia-debug" : "julia") + julia = joinpath(Sys.BINDIR, debug ? "julia-debug" : "julia") cc, warn_msg = find_system_compiler() # Ensure we have write-permissions to wherever we're trying to write to diff --git a/contrib/julia-config.jl b/contrib/julia-config.jl index 03d3420a6cf3e..b00f1e7dd193d 100755 --- a/contrib/julia-config.jl +++ b/contrib/julia-config.jl @@ -23,10 +23,10 @@ function libDir() end end -private_libDir() = abspath(JULIA_HOME, Base.PRIVATE_LIBDIR) +private_libDir() = abspath(Sys.BINDIR, Base.PRIVATE_LIBDIR) function includeDir() - return abspath(JULIA_HOME, Base.INCLUDEDIR, "julia") + return abspath(Sys.BINDIR, Base.INCLUDEDIR, "julia") end function ldflags() diff --git a/contrib/mac/juliarc.jl b/contrib/mac/juliarc.jl index 066a50cda9e7a..6822c1b1519e4 100644 --- a/contrib/mac/juliarc.jl +++ b/contrib/mac/juliarc.jl @@ -2,8 +2,8 @@ # Set up environment for Julia OSX binary distribution let - ROOT = abspath(JULIA_HOME,"..") - ENV["PATH"]="$JULIA_HOME:$(ENV["PATH"])" + ROOT = abspath(Sys.BINDIR,"..") + ENV["PATH"]="$(Sys.BINDIR):$(ENV["PATH"])" ENV["FONTCONFIG_PATH"] = joinpath(ROOT, "etc", "fonts") ENV["TK_LIBRARY"] = "/System/Library/Frameworks/Tk.framework/Versions/8.5/Resources/Scripts" end diff --git a/doc/src/devdocs/sysimg.md b/doc/src/devdocs/sysimg.md index 9fdc02203f80f..4ca11cf23eb9b 100644 --- a/doc/src/devdocs/sysimg.md +++ b/doc/src/devdocs/sysimg.md @@ -21,7 +21,7 @@ named `build_sysimg.jl` that lives in `DATAROOTDIR/julia/`. That is, to include Julia session, type: ```julia -include(joinpath(JULIA_HOME, Base.DATAROOTDIR, "julia", "build_sysimg.jl")) +include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "build_sysimg.jl")) ``` This will include a `build_sysimg` function: diff --git a/doc/src/manual/embedding.md b/doc/src/manual/embedding.md index eadfdf96a8099..fcf0d112bebf2 100644 --- a/doc/src/manual/embedding.md +++ b/doc/src/manual/embedding.md @@ -41,7 +41,7 @@ the above test program `test.c` with `gcc` using: gcc -o test -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib test.c -ljulia $JULIA_DIR/lib/julia/libstdc++.so.6 ``` -Then if the environment variable `JULIA_HOME` is set to `$JULIA_DIR/bin`, the output `test` program +Then if the environment variable `JULIA_BINDIR` is set to `$JULIA_DIR/bin`, the output `test` program can be executed. Alternatively, look at the `embedding.c` program in the Julia source tree in the `examples/` folder. @@ -125,7 +125,7 @@ too, and the makefile can be used to take advantage of that. The above example use a Makefile: ``` -JL_SHARE = $(shell julia -e 'print(joinpath(JULIA_HOME,Base.DATAROOTDIR,"julia"))') +JL_SHARE = $(shell julia -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia"))') CFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags) CXXFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags) LDFLAGS += $(shell $(JL_SHARE)/julia-config.jl --ldflags) diff --git a/doc/src/manual/environment-variables.md b/doc/src/manual/environment-variables.md index d2fe606136b76..201147c1473ad 100644 --- a/doc/src/manual/environment-variables.md +++ b/doc/src/manual/environment-variables.md @@ -16,26 +16,26 @@ those for which `JULIA` appears in the name. ## File locations -### `JULIA_HOME` +### `JULIA_BINDIR` The absolute path of the directory containing the Julia executable, which sets -the global variable [`Base.JULIA_HOME`](@ref). If `$JULIA_HOME` is not set, then -Julia determines the value `Base.JULIA_HOME` at run-time. +the global variable [`Sys.BINDIR`](@ref). If `$JULIA_BINDIR` is not set, then +Julia determines the value `Sys.BINDIR` at run-time. The executable itself is one of ``` -$JULIA_HOME/julia -$JULIA_HOME/julia-debug +$JULIA_BINDIR/julia +$JULIA_BINDIR/julia-debug ``` by default. The global variable `Base.DATAROOTDIR` determines a relative path from -`Base.JULIA_HOME` to the data directory associated with Julia. Then the path +`Sys.BINDIR` to the data directory associated with Julia. Then the path ``` -$JULIA_HOME/$DATAROOTDIR/julia/base +$JULIA_BINDIR/$DATAROOTDIR/julia/base ``` determines the directory in which Julia initially searches for source files (via @@ -45,15 +45,15 @@ Likewise, the global variable `Base.SYSCONFDIR` determines a relative path to th configuration file directory. Then Julia searches for a `juliarc.jl` file at ``` -$JULIA_HOME/$SYSCONFDIR/julia/juliarc.jl -$JULIA_HOME/../etc/julia/juliarc.jl +$JULIA_BINDIR/$SYSCONFDIR/julia/juliarc.jl +$JULIA_BINDIR/../etc/julia/juliarc.jl ``` by default (via `Base.load_juliarc()`). For example, a Linux installation with a Julia executable located at `/bin/julia`, a `DATAROOTDIR` of `../share`, and a `SYSCONFDIR` of `../etc` will -have `JULIA_HOME` set to `/bin`, a source-file search path of +have `JULIA_BINDIR` set to `/bin`, a source-file search path of ``` /share/julia/base diff --git a/doc/src/manual/unicode-input.md b/doc/src/manual/unicode-input.md index 6632c169c784e..57f9894e7423e 100644 --- a/doc/src/manual/unicode-input.md +++ b/doc/src/manual/unicode-input.md @@ -31,7 +31,7 @@ function tab_completions(symbols...) end function unicode_data() - file = normpath(JULIA_HOME, "..", "..", "doc", "UnicodeData.txt") + file = normpath(Sys.BINDIR, "..", "..", "doc", "UnicodeData.txt") names = Dict{UInt32, String}() open(file) do unidata for line in readlines(unidata) diff --git a/doc/src/stdlib/constants.md b/doc/src/stdlib/constants.md index e88211b354038..bb8af72ab3373 100644 --- a/doc/src/stdlib/constants.md +++ b/doc/src/stdlib/constants.md @@ -7,7 +7,7 @@ Base.ARGS Base.C_NULL Base.VERSION Base.LOAD_PATH -Base.JULIA_HOME +Base.Sys.BINDIR Base.Sys.CPU_CORES Base.Sys.WORD_SIZE Base.Sys.KERNEL diff --git a/examples/embedding/Makefile b/examples/embedding/Makefile index acfd9baf545ed..4fd4146b81a54 100644 --- a/examples/embedding/Makefile +++ b/examples/embedding/Makefile @@ -20,7 +20,7 @@ SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) EXE := $(suffix $(abspath $(JULIA))) # get compiler and linker flags. (see: `contrib/julia-config.jl`) -JULIA_CONFIG := $(JULIA) -e 'include(joinpath(JULIA_HOME, Base.DATAROOTDIR, "julia", "julia-config.jl"))' -- +JULIA_CONFIG := $(JULIA) -e 'include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "julia-config.jl"))' -- CPPFLAGS_ADD := CFLAGS_ADD = $(shell $(JULIA_CONFIG) --cflags) LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) diff --git a/examples/embedding/embedding-test.jl b/examples/embedding/embedding-test.jl index 99846f68ecce3..7b991c51f9349 100644 --- a/examples/embedding/embedding-test.jl +++ b/examples/embedding/embedding-test.jl @@ -5,7 +5,7 @@ using Test if Sys.iswindows() # libjulia needs to be in the same directory as the embedding executable or in path - ENV["PATH"] = string(JULIA_HOME, ";", ENV["PATH"]) + ENV["PATH"] = string(Sys.BINDIR, ";", ENV["PATH"]) end @test length(ARGS) == 1 diff --git a/src/codegen.cpp b/src/codegen.cpp index 9a71d00ae99d1..73e9f1f9907dd 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1680,7 +1680,7 @@ extern "C" int isabspath(const char *in); static void write_log_data(logdata_t &logData, const char *extension) { - std::string base = std::string(jl_options.julia_home); + std::string base = std::string(jl_options.julia_bindir); base = base + "/../share/julia/base/"; logdata_t::iterator it = logData.begin(); for (; it != logData.end(); it++) { diff --git a/src/dlload.c b/src/dlload.c index 371aa38804fa9..017b620d5e3dd 100644 --- a/src/dlload.c +++ b/src/dlload.c @@ -56,7 +56,7 @@ static int endswith_extension(const char *path) #define PATHBUF 512 -extern char *julia_home; +extern char *julia_bindir; #define JL_RTLD(flags, FLAG) (flags & JL_RTLD_ ## FLAG ? RTLD_ ## FLAG : 0) diff --git a/src/init.c b/src/init.c index 2e50a228f2a16..fb0993ef99180 100644 --- a/src/init.c +++ b/src/init.c @@ -491,7 +491,7 @@ static char *abspath(const char *in, int nprefix) static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel) { // this function resolves the paths in jl_options to absolute file locations as needed - // and it replaces the pointers to `julia_home`, `julia_bin`, `image_file`, and output file paths + // and it replaces the pointers to `julia_bindir`, `julia_bin`, `image_file`, and output file paths // it may fail, print an error, and exit(1) if any of these paths are longer than PATH_MAX // // note: if you care about lost memory, you should call the appropriate `free()` function @@ -508,22 +508,31 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel) jl_options.julia_bin = (char*)malloc(path_size+1); memcpy((char*)jl_options.julia_bin, free_path, path_size); ((char*)jl_options.julia_bin)[path_size] = '\0'; - if (!jl_options.julia_home) { - jl_options.julia_home = getenv("JULIA_HOME"); - if (!jl_options.julia_home) { - jl_options.julia_home = dirname(free_path); + if (!jl_options.julia_bindir) { + jl_options.julia_bindir = getenv("JULIA_BINDIR"); + if (!jl_options.julia_bindir) { + char *julia_bindir = getenv("JULIA_HOME"); + if (julia_bindir) { + jl_depwarn( + "`JULIA_HOME` environment variable is renamed to `JULIA_BINDIR`", + (jl_value_t*)jl_symbol("JULIA_HOME")); + jl_options.julia_bindir = julia_bindir; + } + } + if (!jl_options.julia_bindir) { + jl_options.julia_bindir = dirname(free_path); } } - if (jl_options.julia_home) - jl_options.julia_home = abspath(jl_options.julia_home, 0); + if (jl_options.julia_bindir) + jl_options.julia_bindir = abspath(jl_options.julia_bindir, 0); free(free_path); free_path = NULL; if (jl_options.image_file) { if (rel == JL_IMAGE_JULIA_HOME && !isabspath(jl_options.image_file)) { - // build time path, relative to JULIA_HOME + // build time path, relative to JULIA_BINDIR free_path = (char*)malloc(PATH_MAX); int n = snprintf(free_path, PATH_MAX, "%s" PATHSEPSTRING "%s", - jl_options.julia_home, jl_options.image_file); + jl_options.julia_bindir, jl_options.image_file); if (n >= PATH_MAX || n < 0) { jl_error("fatal error: jl_options.image_file path too long"); } diff --git a/src/jlapi.c b/src/jlapi.c index eadf3eafc7f27..a5bf650839c54 100644 --- a/src/jlapi.c +++ b/src/jlapi.c @@ -39,13 +39,13 @@ JL_DLLEXPORT int jl_is_initialized(void) // Second argument is the path of a system image file (*.ji) relative to the // first argument path, or relative to the default julia home dir. // The default is something like ../lib/julia/sys.ji -JL_DLLEXPORT void jl_init_with_image(const char *julia_home_dir, +JL_DLLEXPORT void jl_init_with_image(const char *julia_bindir, const char *image_relative_path) { if (jl_is_initialized()) return; libsupport_init(); - jl_options.julia_home = julia_home_dir; + jl_options.julia_bindir = julia_bindir; if (image_relative_path != NULL) jl_options.image_file = image_relative_path; else @@ -305,9 +305,9 @@ JL_DLLEXPORT int8_t jl_is_memdebug(void) { #endif } -JL_DLLEXPORT jl_value_t *jl_get_julia_home(void) +JL_DLLEXPORT jl_value_t *jl_get_julia_bindir(void) { - return jl_cstr_to_string(jl_options.julia_home); + return jl_cstr_to_string(jl_options.julia_bindir); } JL_DLLEXPORT jl_value_t *jl_get_julia_bin(void) diff --git a/src/jloptions.c b/src/jloptions.c index 0457d9c525565..d7db0e15330f5 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -29,7 +29,7 @@ JL_DLLEXPORT const char *jl_get_default_sysimg_path(void) jl_options_t jl_options = { 0, // quiet -1, // banner - NULL, // julia_home + NULL, // julia_bindir NULL, // julia_bin NULL, // cmds NULL, // image_file (will be filled in below) @@ -302,8 +302,8 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) } break; case 'H': // home - jl_options.julia_home = strdup(optarg); - if (!jl_options.julia_home) + jl_options.julia_bindir = strdup(optarg); + if (!jl_options.julia_bindir) jl_errorf("fatal error: failed to allocate memory: %s", strerror(errno)); break; case 'e': // eval diff --git a/src/julia.h b/src/julia.h index 9f6d1e0a46826..a52f7aebfcab8 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1365,7 +1365,7 @@ typedef enum { #endif JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel); JL_DLLEXPORT void jl_init(void); -JL_DLLEXPORT void jl_init_with_image(const char *julia_home_dir, +JL_DLLEXPORT void jl_init_with_image(const char *julia_bindir, const char *image_relative_path); JL_DLLEXPORT const char *jl_get_default_sysimg_path(void); JL_DLLEXPORT int jl_is_initialized(void); @@ -1701,7 +1701,7 @@ JL_DLLEXPORT void jl_(void *jl_value); typedef struct { int8_t quiet; int8_t banner; - const char *julia_home; + const char *julia_bindir; const char *julia_bin; const char **cmds; const char *image_file; diff --git a/stdlib/Distributed/src/cluster.jl b/stdlib/Distributed/src/cluster.jl index e658d639664c1..0b55ae30de45b 100644 --- a/stdlib/Distributed/src/cluster.jl +++ b/stdlib/Distributed/src/cluster.jl @@ -449,7 +449,7 @@ end default_addprocs_params() = AnyDict( :topology => :all_to_all, :dir => pwd(), - :exename => joinpath(JULIA_HOME, julia_exename()), + :exename => joinpath(Sys.BINDIR, julia_exename()), :exeflags => ``, :enable_threaded_blas => false, :lazy => true) diff --git a/stdlib/Distributed/src/managers.jl b/stdlib/Distributed/src/managers.jl index 9889a3c13fa08..86ed0a828c6b8 100644 --- a/stdlib/Distributed/src/managers.jl +++ b/stdlib/Distributed/src/managers.jl @@ -82,8 +82,8 @@ Keyword arguments: * `enable_threaded_blas`: if `true` then BLAS will run on multiple threads in added processes. Default is `false`. -* `exename`: name of the `julia` executable. Defaults to `"\$JULIA_HOME/julia"` or - `"\$JULIA_HOME/julia-debug"` as the case may be. +* `exename`: name of the `julia` executable. Defaults to `"\$(Sys.BINDIR)/julia"` or + `"\$(Sys.BINDIR)/julia-debug"` as the case may be. * `exeflags`: additional flags passed to the worker processes. diff --git a/stdlib/Distributed/test/distributed_exec.jl b/stdlib/Distributed/test/distributed_exec.jl index 80112777bb264..6c4d6258e2d33 100644 --- a/stdlib/Distributed/test/distributed_exec.jl +++ b/stdlib/Distributed/test/distributed_exec.jl @@ -3,7 +3,7 @@ using Test, Distributed import Distributed: launch, manage -include(joinpath(JULIA_HOME, "..", "share", "julia", "test", "testenv.jl")) +include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl")) # Test a few "remote" invocations when no workers are present @test remote(myid)() == 1 @@ -524,7 +524,7 @@ end # Start test for various kw arg combinations walk_args(1) -include(joinpath(JULIA_HOME, "..", "share", "julia", "test", "generic_map_tests.jl")) +include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "generic_map_tests.jl")) empty_pool = WorkerPool([myid()]) pmap_fallback = (f, c...) -> pmap(empty_pool, f, c...) generic_map_tests(pmap_fallback) @@ -678,7 +678,7 @@ if Sys.isunix() # aka have ssh test_n_remove_pids(new_pids) print("\nkeyword arg exename\n") - for exename in [`$(joinpath(JULIA_HOME, Base.julia_exename()))`, "$(joinpath(JULIA_HOME, Base.julia_exename()))"] + for exename in [`$(joinpath(Sys.BINDIR, Base.julia_exename()))`, "$(joinpath(Sys.BINDIR, Base.julia_exename()))"] for addp_func in [()->addprocs_with_testenv(["localhost"]; exename=exename, exeflags=test_exeflags, sshflags=sshflags), ()->addprocs_with_testenv(1; exename=exename, exeflags=test_exeflags)] diff --git a/stdlib/Distributed/test/runtests.jl b/stdlib/Distributed/test/runtests.jl index 76ecf1ab8dbdd..1683944a42a25 100644 --- a/stdlib/Distributed/test/runtests.jl +++ b/stdlib/Distributed/test/runtests.jl @@ -2,7 +2,7 @@ # Run the distributed test outside of the main driver since it needs its own # set of dedicated workers. -include(joinpath(JULIA_HOME, "..", "share", "julia", "test", "testenv.jl")) +include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl")) disttestfile = joinpath(@__DIR__, "distributed_exec.jl") cmd = `$test_exename $test_exeflags $disttestfile` diff --git a/stdlib/SharedArrays/test/runtests.jl b/stdlib/SharedArrays/test/runtests.jl index 6b62a645d404c..b82eafc391233 100644 --- a/stdlib/SharedArrays/test/runtests.jl +++ b/stdlib/SharedArrays/test/runtests.jl @@ -1,7 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license using Test, Distributed, SharedArrays -include(joinpath(JULIA_HOME, "..", "share", "julia", "test", "testenv.jl")) +include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl")) addprocs_with_testenv(4) @test nprocs() == 5 diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index d948d2c09bf75..04905a3f385fb 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -9,7 +9,7 @@ srand(123) @testset "based on deps/SuiteSparse-4.0.2/CHOLMOD/Demo/" begin -# chm_rdsp(joinpath(JULIA_HOME, "../../deps/SuiteSparse-4.0.2/CHOLMOD/Demo/Matrix/bcsstk01.tri")) +# chm_rdsp(joinpath(Sys.BINDIR, "../../deps/SuiteSparse-4.0.2/CHOLMOD/Demo/Matrix/bcsstk01.tri")) # because the file may not exist in binary distributions and when a system suitesparse library # is used diff --git a/test/choosetests.jl b/test/choosetests.jl index aa8e1ceb31800..42f00390b6398 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -const STDLIB_DIR = joinpath(JULIA_HOME, "..", "share", "julia", "site", "v$(VERSION.major).$(VERSION.minor)") +const STDLIB_DIR = joinpath(Sys.BINDIR, "..", "share", "julia", "site", "v$(VERSION.major).$(VERSION.minor)") const STDLIBS = readdir(STDLIB_DIR) @doc """ @@ -55,7 +55,7 @@ function choosetests(choices = []) "reinterpretarray", "syntax", "logging", "missing", "asyncmap" ] - if isdir(joinpath(JULIA_HOME, Base.DOCDIR, "examples")) + if isdir(joinpath(Sys.BINDIR, Base.DOCDIR, "examples")) push!(testnames, "examples") end diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index 091035f118a43..95d19d593850d 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -2,7 +2,7 @@ catcmd = `cat` if Sys.iswindows() - busybox = joinpath(JULIA_HOME, "busybox.exe") + busybox = joinpath(Sys.BINDIR, "busybox.exe") havebb = try # use busybox-w32 on windows success(`$busybox`) true @@ -41,8 +41,8 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes --startup-file=no` end # --home - @test success(`$exename -H $JULIA_HOME`) - @test success(`$exename --home=$JULIA_HOME`) + @test success(`$exename -H $(Sys.BINDIR)`) + @test success(`$exename --home=$(Sys.BINDIR)`) # --eval @test success(`$exename -e "exit(0)"`) @@ -386,7 +386,7 @@ end libjulia = abspath(Libdl.dlpath((ccall(:jl_is_debugbuild, Cint, ()) != 0) ? "libjulia-debug" : "libjulia")) # test error handling code paths of running --sysimage -let exename = joinpath(JULIA_HOME, Base.julia_exename()), +let exename = joinpath(Sys.BINDIR, Base.julia_exename()), sysname = unsafe_string(Base.JLOptions().image_file) for nonexist_image in ( joinpath(@__DIR__, "nonexistent"), @@ -434,10 +434,10 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes` end # Make sure `julia --lisp` doesn't break -run(pipeline(DevNull, `$(joinpath(JULIA_HOME, Base.julia_exename())) --lisp`, DevNull)) +run(pipeline(DevNull, `$(joinpath(Sys.BINDIR, Base.julia_exename())) --lisp`, DevNull)) # Test that `julia [some other option] --lisp` is disallowed -@test_throws ErrorException run(pipeline(DevNull, pipeline(`$(joinpath(JULIA_HOME, +@test_throws ErrorException run(pipeline(DevNull, pipeline(`$(joinpath(Sys.BINDIR, Base.julia_exename())) -Cnative --lisp`, stderr=DevNull), DevNull)) # --sysimage-native-code={yes|no} diff --git a/test/examples.jl b/test/examples.jl index decb7f7bdf9b4..378e9038deda2 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -dir = joinpath(JULIA_HOME, Base.DOCDIR, "examples") +dir = joinpath(Sys.BINDIR, Base.DOCDIR, "examples") include(joinpath(dir, "bubblesort.jl")) a = rand(1:100,100) diff --git a/test/spawn.jl b/test/spawn.jl index 93703cef90c44..c4a290fb986f7 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -18,7 +18,7 @@ sleepcmd = `sleep` lscmd = `ls` havebb = false if Sys.iswindows() - busybox = joinpath(JULIA_HOME, "busybox.exe") + busybox = joinpath(Sys.BINDIR, "busybox.exe") havebb = try # use busybox-w32 on windows, if available success(`$busybox`) true diff --git a/test/testenv.jl b/test/testenv.jl index 6447d6e342d09..fa37efbfc32f2 100644 --- a/test/testenv.jl +++ b/test/testenv.jl @@ -23,7 +23,7 @@ if !@isdefined(testenv_defined) if haskey(ENV, "JULIA_TEST_EXENAME") const test_exename = `$(Base.shell_split(ENV["JULIA_TEST_EXENAME"]))` else - const test_exename = `$(joinpath(JULIA_HOME, Base.julia_exename()))` + const test_exename = `$(joinpath(Sys.BINDIR, Base.julia_exename()))` end addprocs_with_testenv(X; kwargs...) = addprocs(X; exename=test_exename, exeflags=test_exeflags, kwargs...)