Skip to content

Commit

Permalink
Pkg3-style code loading, DEPOT_PATH, tests
Browse files Browse the repository at this point in the history
Developed together with vtjnash
  • Loading branch information
StefanKarpinski committed Jan 20, 2018
1 parent 8da905b commit 865c08e
Show file tree
Hide file tree
Showing 38 changed files with 1,365 additions and 346 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export
# Global constants and variables
ARGS,
C_NULL,
DEPOT_PATH,
ENDIAN_BOM,
ENV,
LOAD_PATH,
Expand Down
77 changes: 71 additions & 6 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,96 @@ Determine whether Julia is running an interactive session.
"""
isinteractive() = (is_interactive::Bool)

## package depots (registries, packages, environments) ##

const DEPOT_PATH = String[]

function init_depot_path(BINDIR = Sys.BINDIR)
if haskey(ENV, "JULIA_DEPOT_PATH")
depots = split(ENV["JULIA_DEPOT_PATH"], Sys.iswindows() ? ';' : ':')
push!(empty!(DEPOT_PATH), map(expanduser, depots))
else
push!(DEPOT_PATH, joinpath(homedir(), ".julia"))
end
end

## load-path types ##

abstract type AbstractEnv end

struct CurrentEnv <: AbstractEnv
create::Bool
CurrentEnv(; create::Bool=false) = new(create)
end

struct NamedEnv <: AbstractEnv
name::String
create::Bool
NamedEnv(name::String; create::Bool=false) = new(name, create)
end

function show(io::IO, env::CurrentEnv)
print(io, CurrentEnv, "(")
env.create && print(io, "create=true")
print(io, ")")
end

function show(io::IO, env::NamedEnv)
print(io, NamedEnv, "(", repr(env.name))
env.create && print(io, ", create=true")
print(io, ")")
end

function parse_env(env::Union{String,SubString{String}})
env == "@" && return CurrentEnv()
env == "@!" && return CurrentEnv(create=true)
if env[1] == '@'
create = env[2] == '!'
name = env[2+create:end]
name = replace(name, '#' => VERSION.major, count=1)
name = replace(name, '#' => VERSION.minor, count=1)
name = replace(name, '#' => VERSION.patch, count=1)
return NamedEnv(name, create=create)
end
return env # literal path
end

"""
LOAD_PATH
An array of paths as strings or custom loader objects for the `require`
function and `using` and `import` statements to consider when loading
code.
"""
const LOAD_PATH = String[]
const LOAD_PATH = Any[]
const LOAD_CACHE_PATH = String[]

function parse_load_path(str::String)
envs = Any[split(str, Sys.iswindows() ? ';' : ':');]
for (i, env) in enumerate(envs)
if '|' in env
envs[i] = [parse_env(e) for e in split(env, '|')]
else
envs[i] = parse_env(env)
end
end
return envs
end

function init_load_path(BINDIR = Sys.BINDIR)
load_path = get(ENV, "JULIA_LOAD_PATH", "@|@v#.#.#|@v#.#|@v#|@default|@!v#.#")
append!(empty!(LOAD_PATH), parse_load_path(load_path))
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, Pkg.dir)
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()
Sys._early_init()
# 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"))
get(ENV, "GOTOBLAS_MAIN_FREE", "1"))
if Sys.CPU_CORES > 8 && !("OPENBLAS_NUM_THREADS" in keys(ENV)) && !("OMP_NUM_THREADS" in keys(ENV))
# Prevent openblas from starting too many threads, unless/until specifically requested
ENV["OPENBLAS_NUM_THREADS"] = 8
Expand Down

0 comments on commit 865c08e

Please sign in to comment.