Skip to content

Commit 94bf4a1

Browse files
committed
Allow embedding environment variables into workspace mappings
This allows us to, for instance, map `${JULIA_DEPOT_PATH}` into the sandbox.
1 parent 5747131 commit 94bf4a1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/generate_sandboxed_bash.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ function add_env_dir!(dict, env_var; default=nothing)
3636
return dict
3737
end
3838

39+
# Super-simple environment expansion
40+
envexpand(s::String) = replace(s, r"\${[a-zA-Z0-9_]+}" => m -> get(ENV, m[3:end-1], m))
41+
3942
# read-write mount mappings
4043
workspace_mappings = Dict{String,String}()
4144

@@ -50,7 +53,9 @@ add_env_dir!(workspace_mappings, "TMPDIR"; default="/tmp")
5053

5154
# Add user-specified workspaces (note they must all be absolute paths)
5255
for (sandbox_path, host_path) in workspaces
53-
workspace_mappings[sandbox_path] = abspath(host_path)
56+
# Also perform ENV-expansion. Note that to make parsing easier, we
57+
# only support `${FOO}` style expansion, not `$FOO` style.
58+
workspace_mappings[envexpand(sandbox_path)] = envexpand(abspath(host_path))
5459
end
5560

5661

0 commit comments

Comments
 (0)