Skip to content

Commit a848d94

Browse files
Use dirs to hold container paths
1 parent e2f6d29 commit a848d94

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

src/dirs.rs

+24
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,27 @@ pub(crate) fn crate_source_dir(ex: &Experiment, tc: &Toolchain, krate: &Crate) -
4646
.join(tc.to_path_component())
4747
.join(krate.id())
4848
}
49+
50+
pub mod container {
51+
use std::path::{Path, PathBuf};
52+
53+
use lazy_static::lazy_static;
54+
55+
#[cfg(windows)]
56+
lazy_static! {
57+
pub static ref ROOT_DIR: PathBuf = Path::new(r"C:\crater").into();
58+
}
59+
60+
#[cfg(not(windows))]
61+
lazy_static! {
62+
pub static ref ROOT_DIR: PathBuf = Path::new("/opt/crater").into();
63+
}
64+
65+
lazy_static! {
66+
pub static ref WORK_DIR: PathBuf = ROOT_DIR.join("workdir");
67+
pub static ref TARGET_DIR: PathBuf = ROOT_DIR.join("target");
68+
pub static ref CARGO_HOME: PathBuf = ROOT_DIR.join("cargo-home");
69+
pub static ref RUSTUP_HOME: PathBuf = ROOT_DIR.join("rustup-home");
70+
pub static ref CARGO_BIN_DIR: PathBuf = CARGO_HOME.join("bin");
71+
}
72+
}

src/run.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::dirs::{CARGO_HOME, RUSTUP_HOME};
1+
use crate::dirs::{self, CARGO_HOME, RUSTUP_HOME};
22
use crate::docker::DockerEnv;
33
use crate::docker::{ContainerBuilder, MountPerms};
44
use crate::native;
@@ -238,9 +238,7 @@ impl<'a, 'pl> SandboxedCommand<'a, 'pl> {
238238
cmd.push(
239239
match self.command.binary {
240240
Binary::Global(path) => path,
241-
Binary::InstalledByCrater(path) => {
242-
PathBuf::from("/opt/crater/cargo-home/bin").join(path)
243-
}
241+
Binary::InstalledByCrater(path) => dirs::container::CARGO_BIN_DIR.join(path),
244242
}
245243
.to_string_lossy()
246244
.as_ref()
@@ -258,9 +256,13 @@ impl<'a, 'pl> SandboxedCommand<'a, 'pl> {
258256

259257
self.container = self
260258
.container
261-
.mount(source_dir, "/opt/crater/workdir", MountPerms::ReadOnly)
262-
.env("SOURCE_DIR", "/opt/crater/workdir")
263-
.workdir("/opt/crater/workdir")
259+
.mount(
260+
source_dir,
261+
dirs::container::WORK_DIR.to_str().unwrap(),
262+
MountPerms::ReadOnly,
263+
)
264+
.env("SOURCE_DIR", dirs::container::WORK_DIR.to_str().unwrap())
265+
.workdir(dirs::container::WORK_DIR.to_str().unwrap())
264266
.cmd(cmd);
265267

266268
if let Some(user_id) = native::current_user() {
@@ -277,14 +279,21 @@ impl<'a, 'pl> SandboxedCommand<'a, 'pl> {
277279
if self.command.local_rustup {
278280
self.container = self
279281
.container
280-
.mount(&*CARGO_HOME, "/opt/crater/cargo-home", MountPerms::ReadOnly)
282+
.mount(
283+
&*CARGO_HOME,
284+
dirs::container::CARGO_HOME.to_str().unwrap(),
285+
MountPerms::ReadOnly,
286+
)
281287
.mount(
282288
&*RUSTUP_HOME,
283-
"/opt/crater/rustup-home",
289+
dirs::container::RUSTUP_HOME.to_str().unwrap(),
284290
MountPerms::ReadOnly,
285291
)
286-
.env("CARGO_HOME", "/opt/crater/cargo-home")
287-
.env("RUSTUP_HOME", "/opt/crater/rustup-home");
292+
.env("CARGO_HOME", dirs::container::CARGO_HOME.to_str().unwrap())
293+
.env(
294+
"RUSTUP_HOME",
295+
dirs::container::RUSTUP_HOME.to_str().unwrap(),
296+
);
288297
}
289298

290299
self.container.run(self.command.quiet)

src/runner/test.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::dirs;
12
use crate::docker::{DockerError, MountPerms};
23
use crate::prelude::*;
34
use crate::results::{EncodingType, FailureReason, TestResult, WriteResults};
@@ -45,12 +46,19 @@ fn run_cargo<DB: WriteResults>(
4546
.args(args)
4647
.quiet(ctx.quiet)
4748
.cd(source_path)
48-
.env("CARGO_TARGET_DIR", "/opt/crater/target")
49+
.env(
50+
"CARGO_TARGET_DIR",
51+
dirs::container::TARGET_DIR.to_str().unwrap(),
52+
)
4953
.env("CARGO_INCREMENTAL", "0")
5054
.env("RUST_BACKTRACE", "full")
5155
.env(rustflags_env, rustflags)
5256
.sandboxed(&ctx.docker_env)
53-
.mount(target_dir, "/opt/crater/target", MountPerms::ReadWrite)
57+
.mount(
58+
target_dir,
59+
dirs::container::TARGET_DIR.to_str().unwrap(),
60+
MountPerms::ReadWrite,
61+
)
5462
.memory_limit(Some(ctx.config.sandbox.memory_limit))
5563
.run()?;
5664

0 commit comments

Comments
 (0)