Skip to content

Commit

Permalink
Add a configuration flag for setting the environment (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Oct 5, 2022
1 parent 67b77d1 commit 4509117
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/sandbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ function setup_generic_sandbox(config::Configuration, cmd::Cmd;
env["TERM"] = ENV["TERM"]
end

for flag in config.environment
key, value = split(flag, '='; limit=2)
if (value[begin] == value[end] == '"') || (value[begin] == value[end] == '\'')
value = value[2:end-1]
end
env[key] = value
end

if config.xvfb
lock(xvfb_lock) do
if xvfb_proc[] === nothing || !process_running(xvfb_proc[])
Expand Down
3 changes: 2 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Base.@kwdef struct Configuration
julia::Setting{String} = Default("nightly")
buildflags::Setting{Vector{String}} = Default(String[])
buildcommands::Setting{String} = Default("make install")
environment::Setting{Vector{String}} = Default(String[])
julia_install_dir::Setting{String} = Default("/opt/julia")
julia_binary::Setting{String} = Default("julia")
## additional Julia arguments to pass to the process
Expand Down Expand Up @@ -73,7 +74,7 @@ function Base.show(io::IO, cfg::Configuration)
println(io, "PkgEval configuration(")

println(io, " # Julia properties")
show_setting.(["julia", "buildflags", "buildcommands", "julia_install_dir", "julia_binary", "julia_args"])
show_setting.(["julia", "buildflags", "buildcommands", "environment", "julia_install_dir", "julia_binary", "julia_args"])
println(io)

println(io, " # Registry properties")
Expand Down
18 changes: 17 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,28 @@ config = Configuration(; config_kwargs...)
if julia_release !== nothing
p = Pipe()
close(p.in)
PkgEval.sandboxed_julia(config, `-e 'println(VERSION)'`; stdout=p.out)
PkgEval.sandboxed_julia(config, `-e 'print(VERSION)'`; stdout=p.out)
version_str = read(p.out, String)
@test parse(VersionNumber, version_str) == julia_release
end
end

@testset "environment flags" begin
let
p = Pipe()
close(p.in)
PkgEval.sandboxed_julia(config, `-e 'print(get(ENV, "FOO", nothing))'`; stdout=p.out)
@test read(p.out, String) == "nothing"
end

let config = Configuration(; environment=["FOO=bar"], config_kwargs...)
p = Pipe()
close(p.in)
PkgEval.sandboxed_julia(config, `-e 'print(get(ENV, "FOO", nothing))'`; stdout=p.out)
@test read(p.out, String) == "bar"
end
end

@testset "package installation" begin
# by name
let results = evaluate([config],
Expand Down

0 comments on commit 4509117

Please sign in to comment.