From 12c0f9e0f6a234a62e2795b9bea9a4ceeebb1247 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Tue, 24 Nov 2020 13:57:08 -0600 Subject: [PATCH] add SandboxBuilder image override --- src/build.rs | 7 +++++++ src/cmd/sandbox.rs | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/build.rs b/src/build.rs index 4cc217e..8fae3d2 100644 --- a/src/build.rs +++ b/src/build.rs @@ -171,6 +171,13 @@ impl BuildDirectory { Ok(()) } + /// Get the path to the source code on the host machine (outside the sandbox). + pub fn get_source_dir(&self, krate: &Crate) -> Result { + let source_dir = self.source_dir(); + krate.copy_source_to(&self.workspace, source_dir.as_path())?; + Ok(source_dir) + } + fn build_dir(&self) -> PathBuf { self.workspace.builds_dir().join(&self.name) } diff --git a/src/cmd/sandbox.rs b/src/cmd/sandbox.rs index 1f5fd33..c5b569b 100644 --- a/src/cmd/sandbox.rs +++ b/src/cmd/sandbox.rs @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf}; use std::time::Duration; /// The Docker image used for sandboxing. +#[derive(Clone)] pub struct SandboxImage { name: String, } @@ -146,6 +147,7 @@ pub struct SandboxBuilder { user: Option, cmd: Vec, enable_networking: bool, + image: Option, } impl SandboxBuilder { @@ -160,6 +162,7 @@ impl SandboxBuilder { user: None, cmd: Vec::new(), enable_networking: true, + image: None, } } @@ -203,6 +206,14 @@ impl SandboxBuilder { self } + /// Override the image used for this sandbox. + /// + /// By default rustwide will use the image from the `Workspace`. + pub fn image(mut self, image: SandboxImage) -> Self { + self.image = Some(image); + self + } + pub(super) fn env, S2: Into>(mut self, key: S1, value: S2) -> Self { self.env.push((key.into(), value.into())); self @@ -274,7 +285,11 @@ impl SandboxBuilder { args.push("--isolation=process".into()); } - args.push(workspace.sandbox_image().name.clone()); + if let Some(image) = self.image { + args.push(image.name); + } else { + args.push(workspace.sandbox_image().name.clone()); + } for arg in self.cmd { args.push(arg);