Skip to content

Commit

Permalink
add SandboxBuilder image override
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Nov 26, 2020
1 parent 7a4ef73 commit 12c0f9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf, Error> {
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)
}
Expand Down
17 changes: 16 additions & 1 deletion src/cmd/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -146,6 +147,7 @@ pub struct SandboxBuilder {
user: Option<String>,
cmd: Vec<String>,
enable_networking: bool,
image: Option<SandboxImage>,
}

impl SandboxBuilder {
Expand All @@ -160,6 +162,7 @@ impl SandboxBuilder {
user: None,
cmd: Vec::new(),
enable_networking: true,
image: None,
}
}

Expand Down Expand Up @@ -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<S1: Into<String>, S2: Into<String>>(mut self, key: S1, value: S2) -> Self {
self.env.push((key.into(), value.into()));
self
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 12c0f9e

Please sign in to comment.