Skip to content

Commit 76a3156

Browse files
Add private functions for getting the locations of the global and local startup files (#43807)
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent 4abf26e commit 76a3156

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

base/client.jl

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ function incomplete_tag(ex::Expr)
206206
return :other
207207
end
208208

209-
# call include() on a file, ignoring if not found
210-
include_ifexists(mod::Module, path::AbstractString) = isfile(path) && include(mod, path)
211-
212209
function exec_options(opts)
213210
if !isempty(ARGS)
214211
idxs = findall(x -> x == "--", ARGS)
@@ -323,17 +320,33 @@ function exec_options(opts)
323320
nothing
324321
end
325322

326-
function load_julia_startup()
323+
function _global_julia_startup_file()
327324
# If the user built us with a specific Base.SYSCONFDIR, check that location first for a startup.jl file
328-
# If it is not found, then continue on to the relative path based on Sys.BINDIR
325+
# If it is not found, then continue on to the relative path based on Sys.BINDIR
329326
BINDIR = Sys.BINDIR::String
330327
SYSCONFDIR = Base.SYSCONFDIR::String
331-
if !isempty(SYSCONFDIR) && isfile(joinpath(BINDIR, SYSCONFDIR, "julia", "startup.jl"))
332-
include(Main, abspath(BINDIR, SYSCONFDIR, "julia", "startup.jl"))
333-
else
334-
include_ifexists(Main, abspath(BINDIR, "..", "etc", "julia", "startup.jl"))
328+
if !isempty(SYSCONFDIR)
329+
p1 = abspath(BINDIR, SYSCONFDIR, "julia", "startup.jl")
330+
isfile(p1) && return p1
335331
end
336-
!isempty(DEPOT_PATH) && include_ifexists(Main, abspath(DEPOT_PATH[1], "config", "startup.jl"))
332+
p2 = abspath(BINDIR, "..", "etc", "julia", "startup.jl")
333+
isfile(p2) && return p2
334+
return nothing
335+
end
336+
337+
function _local_julia_startup_file()
338+
if !isempty(DEPOT_PATH)
339+
path = abspath(DEPOT_PATH[1], "config", "startup.jl")
340+
isfile(path) && return path
341+
end
342+
return nothing
343+
end
344+
345+
function load_julia_startup()
346+
global_file = _global_julia_startup_file()
347+
(global_file !== nothing) && include(Main, global_file)
348+
local_file = _local_julia_startup_file()
349+
(local_file !== nothing) && include(Main, local_file)
337350
return nothing
338351
end
339352

0 commit comments

Comments
 (0)