|
21 | 21 | const p7zip_exe = "7z"
|
22 | 22 | end
|
23 | 23 |
|
24 |
| -# These functions look a little strange, but they're mimicking the JLLWrappers signature |
25 |
| -p7zip(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) = f(p7zip_path) |
26 |
| -p7zip(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) = Cmd([p7zip_path]) |
| 24 | +if Sys.iswindows() |
| 25 | + const LIBPATH_env = "PATH" |
| 26 | + const LIBPATH_default = "" |
| 27 | + const pathsep = ';' |
| 28 | +elseif Sys.isapple() |
| 29 | + const LIBPATH_env = "DYLD_FALLBACK_LIBRARY_PATH" |
| 30 | + const LIBPATH_default = "~/lib:/usr/local/lib:/lib:/usr/lib" |
| 31 | + const pathsep = ':' |
| 32 | +else |
| 33 | + const LIBPATH_env = "LD_LIBRARY_PATH" |
| 34 | + const LIBPATH_default = "" |
| 35 | + const pathsep = ':' |
| 36 | +end |
| 37 | + |
| 38 | +function adjust_ENV!(env::Dict, PATH::String, LIBPATH::String, adjust_PATH::Bool, adjust_LIBPATH::Bool) |
| 39 | + if adjust_LIBPATH |
| 40 | + LIBPATH_base = get(env, LIBPATH_env, expanduser(LIBPATH_default)) |
| 41 | + if !isempty(LIBPATH_base) |
| 42 | + env[LIBPATH_env] = string(LIBPATH, pathsep, LIBPATH_base) |
| 43 | + else |
| 44 | + env[LIBPATH_env] = LIBPATH |
| 45 | + end |
| 46 | + end |
| 47 | + if adjust_PATH && (LIBPATH_env != "PATH" || !adjust_LIBPATH) |
| 48 | + if adjust_PATH |
| 49 | + if !isempty(get(env, "PATH", "")) |
| 50 | + env["PATH"] = string(PATH, pathsep, env["PATH"]) |
| 51 | + else |
| 52 | + env["PATH"] = PATH |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | + return env |
| 57 | +end |
| 58 | + |
| 59 | +function p7zip(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) |
| 60 | + env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH) |
| 61 | + withenv(env...) do |
| 62 | + return f(p7zip_path) |
| 63 | + end |
| 64 | +end |
| 65 | +function p7zip(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) |
| 66 | + env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH) |
| 67 | + return Cmd(Cmd([p7zip_path]); env) |
| 68 | +end |
27 | 69 |
|
28 | 70 | function init_p7zip_path()
|
29 | 71 | # Prefer our own bundled p7zip, but if we don't have one, pick it up off of the PATH
|
|
0 commit comments