Skip to content

Commit 80e9379

Browse files
committed
Include julia_libdir kwarg for withenv
1 parent 799dc4d commit 80e9379

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/Prefix.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,20 @@ show(io::IO, prefix::Prefix) = show(io, "Prefix($(prefix.path))")
9494

9595

9696
"""
97-
withenv(f::Function, prefixes::Vector{Prefix})
97+
withenv(f::Function, prefixes::Vector{Prefix}; julia_libdir::Bool = true)
9898
9999
Wrapper function designed to help executables find dynamic libraries and child
100-
binaries by wrapping PATH and (DY)LD_LIBRARY_PATH.
100+
binaries by wrapping PATH and `(DY)LD_(FALLBACK_)LIBRARY_PATH`. If
101+
`julia_libdir` is true, then the private library directory of this Julia
102+
distribution will be added on to the end of the LD_LIBRARY_PATH settings.
101103
"""
102-
function withenv(f::Function, prefixes::Vector{Prefix})
104+
function withenv(f::Function, prefixes::Vector{Prefix};
105+
julia_libdir::Bool = true)
103106
# Join `dirs` to ENV[key], removing duplicates and nonexistent directories
104107
# as we go, normalizing directory names, splitting and joining by `sep`.
105-
function joinenv(key, dirs, sep)
106-
value = [dirs..., split(get(ENV, key, ""), sep)...]
107-
return join([abspath(d) for d in value if isdir(d)], sep)
108+
function joinenv(key, dirs, sep, tail_dirs = [])
109+
value = [dirs..., split(get(ENV, key, ""), sep)..., tail_dirs...]
110+
return join(unique([abspath(d) for d in value if isdir(d)]), sep)
108111
end
109112
# We're going to build up PATH and {DY,}LD_LIBRARY_PATH such that binaries
110113
# that use things from the given prefixes can function properly.
@@ -113,8 +116,14 @@ function withenv(f::Function, prefixes::Vector{Prefix})
113116

114117
# {DY,}LD_LIBRARY_PATH only makes sense on non-windows
115118
if !Sys.iswindows()
116-
envname = Sys.isapple() ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"
117-
push!(mapping, envname => joinenv(envname, libdir.(prefixes), ":"))
119+
libdirs = libdir.(prefixes)
120+
tail_dirs = []
121+
if julia_libdir
122+
tail_dirs = [joinpath(Sys.BINDIR, Base.PRIVATE_LIBDIR)]
123+
end
124+
125+
envname = Sys.isapple() ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH"
126+
push!(mapping, envname => joinenv(envname, libdirs, ":", tail_dirs))
118127
end
119128

120129
# Use withenv to apply the calculated environment mappings to f.

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ end
348348
@test startswith(ENV["PATH"], bindir(prefix))
349349

350350
if !Sys.iswindows()
351-
envname = Sys.isapple() ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"
351+
envname = Sys.isapple() ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH"
352352
@test startswith(ENV[envname], libdir(prefix))
353+
private_libdir = abspath(joinpath(Sys.BINDIR, Base.PRIVATE_LIBDIR))
354+
@test endswith(ENV[envname], private_libdir)
353355

354356
# Test we can run the script we dropped within this prefix.
355357
# Once again, something about Windows | busybox | Julia won't

0 commit comments

Comments
 (0)