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 27, 2020
1 parent 7a4ef73 commit dde39c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/cmd/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub struct SandboxBuilder {
user: Option<String>,
cmd: Vec<String>,
enable_networking: bool,
image: Option<String>,
}

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

Expand Down Expand Up @@ -203,6 +205,14 @@ impl SandboxBuilder {
self
}

/// Override the image used for this sandbox.
///
/// By default rustwide will use the image configured with [`WorkspaceBuilder::sandbox_image`].
pub fn image(mut self, image: SandboxImage) -> Self {
self.image = Some(image.name);
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 +284,11 @@ impl SandboxBuilder {
args.push("--isolation=process".into());
}

args.push(workspace.sandbox_image().name.clone());
if let Some(image) = self.image {
args.push(image);
} else {
args.push(workspace.sandbox_image().name.clone());
}

for arg in self.cmd {
args.push(arg);
Expand Down
3 changes: 2 additions & 1 deletion src/crates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl Crate {
}
}

pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> {
/// Copy this crate's source to `dest`. If `dest` already exists, it will be replaced.
pub fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> {
if dest.exists() {
info!(
"crate source directory {} already exists, cleaning it up",
Expand Down

0 comments on commit dde39c4

Please sign in to comment.