Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a configuration flag for setting the environment #142

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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