Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Include julia_libdir kwarg for withenv
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Sep 20, 2018
1 parent 799dc4d commit 80e9379
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/Prefix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,20 @@ show(io::IO, prefix::Prefix) = show(io, "Prefix($(prefix.path))")


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

# {DY,}LD_LIBRARY_PATH only makes sense on non-windows
if !Sys.iswindows()
envname = Sys.isapple() ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"
push!(mapping, envname => joinenv(envname, libdir.(prefixes), ":"))
libdirs = libdir.(prefixes)
tail_dirs = []
if julia_libdir
tail_dirs = [joinpath(Sys.BINDIR, Base.PRIVATE_LIBDIR)]
end

envname = Sys.isapple() ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH"
push!(mapping, envname => joinenv(envname, libdirs, ":", tail_dirs))
end

# Use withenv to apply the calculated environment mappings to f.
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ end
@test startswith(ENV["PATH"], bindir(prefix))

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

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

0 comments on commit 80e9379

Please sign in to comment.