Skip to content

Commit e89113f

Browse files
authored
[Runner] Define a function to set up runner constructors (#191)
We have lots of duplication between `UserNSRunner.jl` and `DockerRunner.jl`, this should reduce it quite a lot and make further additions to the setup less error-prone.
1 parent 39e41d1 commit e89113f

File tree

4 files changed

+65
-91
lines changed

4 files changed

+65
-91
lines changed

src/DockerRunner.jl

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,51 +80,10 @@ function DockerRunner(workspace_root::String;
8080
kwargs...)
8181
global use_ccache
8282

83-
# Check to make sure we're not going to try and bindmount within an
84-
# encrypted directory, as that can trigger kernel bugs
85-
check_encryption(workspace_root; verbose=verbose)
86-
87-
# Extract compilers argument
88-
compilers = collect(extract_kwargs(kwargs, (:compilers,)))
89-
90-
# Construct environment variables we'll use from here on out
91-
platform = get_concrete_platform(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version))...)
92-
envs = merge(platform_envs(platform, src_name; verbose, compilers...), extra_env)
93-
94-
# JIT out some compiler wrappers, add it to our mounts
95-
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
96-
push!(workspaces, compiler_wrapper_path => "/opt/bin")
97-
98-
if isempty(bootstrap_list)
99-
# Generate CMake and Meson files, only if we are not bootstrapping
100-
generate_toolchain_files!(platform, envs, toolchains_path)
101-
push!(workspaces, toolchains_path => "/opt/toolchains")
102-
103-
# Generate directory where to write Cargo config files
104-
if isone(length(collect(compilers))) && :rust in collect(compilers)[1].second
105-
cargo_dir = mktempdir()
106-
cargo_config_file!(cargo_dir, platform)
107-
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
108-
# will be put in ${CARGO_HOME}.
109-
push!(workspaces, cargo_dir => envs["CARGO_HOME"] * "/" * randstring())
110-
end
111-
end
112-
113-
# the workspace_root is always a workspace, and we always mount it first
114-
insert!(workspaces, 1, workspace_root => "/workspace")
115-
116-
# If we're enabling ccache, then map in a named docker volume for it
117-
if use_ccache
118-
if !isdir(ccache_dir())
119-
mkpath(ccache_dir())
120-
end
121-
push!(workspaces, "binarybuilder_ccache" => "/root/.ccache")
122-
end
123-
124-
if isnothing(shards)
125-
# Choose the shards we're going to mount
126-
shards = choose_shards(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list))...)
127-
end
83+
platform, envs, shards =
84+
runner_setup!(workspaces, workspaces, workspace_root, verbose, kwargs,
85+
platform, src_name, extra_env, compiler_wrapper_path,
86+
toolchains_path, shards)
12887

12988
# Import docker image
13089
import_docker_image(shards[1], workspace_root; verbose=verbose)

src/Runner.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,3 +1109,56 @@ end
11091109
function runshell(::Type{R}, platform::AbstractPlatform = HostPlatform(); verbose::Bool=false,kwargs...) where {R <: Runner}
11101110
return runshell(R(pwd(); cwd="/workspace/", platform=platform, verbose=verbose, kwargs...); verbose=verbose)
11111111
end
1112+
1113+
# The runners constructors share a large part of their setup. This function reduces
1114+
# duplication by having bringing the common parts in one place.
1115+
function runner_setup!(workspaces, mappings, workspace_root, verbose, kwargs, platform,
1116+
src_name, extra_env, compiler_wrapper_path, toolchains_path, shards)
1117+
# Check to make sure we're not going to try and bindmount within an
1118+
# encrypted directory, as that triggers kernel bugs
1119+
check_encryption(workspace_root; verbose=verbose)
1120+
1121+
# Extract compilers argument
1122+
compilers = extract_kwargs(kwargs, (:compilers,))
1123+
1124+
# Construct environment variables we'll use from here on out
1125+
platform = get_concrete_platform(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version))...)
1126+
envs = merge(platform_envs(platform, src_name; verbose, compilers...), extra_env)
1127+
1128+
# JIT out some compiler wrappers, add it to our mounts
1129+
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
1130+
push!(workspaces, compiler_wrapper_path => "/opt/bin")
1131+
1132+
if isempty(bootstrap_list)
1133+
# Generate CMake and Meson files, only if we are not bootstrapping
1134+
generate_toolchain_files!(platform, envs, toolchains_path)
1135+
push!(workspaces, toolchains_path => "/opt/toolchains")
1136+
1137+
# Generate directory where to write Cargo config files
1138+
if isone(length(collect(compilers))) && :rust in collect(compilers)[1].second
1139+
cargo_dir = mktempdir()
1140+
cargo_config_file!(cargo_dir, platform)
1141+
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
1142+
# will be put in ${CARGO_HOME}.
1143+
push!(mappings, cargo_dir => "$(envs["CARGO_HOME"])/nonce")
1144+
end
1145+
end
1146+
1147+
# the workspace_root is always a workspace, and we always mount it first
1148+
insert!(workspaces, 1, workspace_root => "/workspace")
1149+
1150+
# If we're enabling ccache, then mount in a read-writeable volume at /root/.ccache
1151+
if use_ccache
1152+
if !isdir(ccache_dir())
1153+
mkpath(ccache_dir())
1154+
end
1155+
push!(workspaces, ccache_dir() => "/root/.ccache")
1156+
end
1157+
1158+
if isnothing(shards)
1159+
# Choose the shards we're going to mount
1160+
shards = choose_shards(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list))...)
1161+
end
1162+
1163+
return platform, envs, shards
1164+
end

src/UserNSRunner.jl

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,10 @@ function UserNSRunner(workspace_root::String;
3535
# Check that our kernel is new enough to use this runner
3636
kernel_version_check()
3737

38-
# Check to make sure we're not going to try and bindmount within an
39-
# encrypted directory, as that triggers kernel bugs
40-
check_encryption(workspace_root; verbose=verbose)
41-
42-
# Extract compilers argument
43-
compilers = extract_kwargs(kwargs, (:compilers,))
44-
45-
# Construct environment variables we'll use from here on out
46-
platform = get_concrete_platform(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version))...)
47-
envs = merge(platform_envs(platform, src_name; verbose, compilers...), extra_env)
48-
49-
# JIT out some compiler wrappers, add it to our mounts
50-
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
51-
push!(workspaces, compiler_wrapper_path => "/opt/bin")
52-
53-
if isempty(bootstrap_list)
54-
# Generate CMake and Meson files, only if we are not bootstrapping
55-
generate_toolchain_files!(platform, envs, toolchains_path)
56-
push!(workspaces, toolchains_path => "/opt/toolchains")
57-
58-
# Generate directory where to write Cargo config files
59-
if isone(length(collect(compilers))) && :rust in collect(compilers)[1].second
60-
cargo_dir = mktempdir()
61-
cargo_config_file!(cargo_dir, platform)
62-
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
63-
# will be put in ${CARGO_HOME}.
64-
push!(mappings, cargo_dir => envs["CARGO_HOME"] * "/" * randstring())
65-
end
66-
end
67-
68-
# the workspace_root is always a workspace, and we always mount it first
69-
insert!(workspaces, 1, workspace_root => "/workspace")
70-
71-
# If we're enabling ccache, then mount in a read-writeable volume at /root/.ccache
72-
if use_ccache
73-
if !isdir(ccache_dir())
74-
mkpath(ccache_dir())
75-
end
76-
push!(workspaces, ccache_dir() => "/root/.ccache")
77-
end
38+
platform, envs, shards =
39+
runner_setup!(workspaces, mappings, workspace_root, verbose, kwargs,
40+
platform, src_name, extra_env, compiler_wrapper_path,
41+
toolchains_path, shards)
7842

7943
# If we are on a system that uses `/etc/resolv.conf` as a resolver
8044
# configuration file (mainly *BSD and Linux), check if a nameserver is
@@ -91,11 +55,6 @@ function UserNSRunner(workspace_root::String;
9155
end
9256
end
9357

94-
if isnothing(shards)
95-
# Choose the shards we're going to mount
96-
shards = choose_shards(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list))...)
97-
end
98-
9958
# Construct sandbox command to look at the location it'll be mounted under
10059
mpath = mount_path(shards[1], workspace_root)
10160
sandbox_cmd = `$(mpath)/sandbox`
@@ -163,7 +122,7 @@ function show(io::IO, x::UserNSRunner)
163122
p = x.platform
164123
# Displays as, e.g., Linux x86_64 (glibc) UserNSRunner
165124
write(io, "$(typeof(p).name.name)", " ", arch(p), " ",
166-
Sys.islinux(p) ? "($(p.libc)) " : "",
125+
Sys.islinux(p) ? "($(libc(p))) " : "",
167126
"UserNSRunner")
168127
end
169128

test/runners.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ end
310310
@testset "testsuite" begin
311311
mktempdir() do dir
312312
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers=[:c, :rust, :go])
313+
# Make sure the runner platform is concrete even if the requested platform isn't
314+
@test !isnothing(libgfortran_version(ur.platform))
315+
@test !isnothing(cxxstring_abi(ur.platform))
313316
iobuff = IOBuffer()
314317
test_script = raw"""
315318
set -e

0 commit comments

Comments
 (0)