diff options
Diffstat (limited to 'src/pipeline/steps.rs')
| -rw-r--r-- | src/pipeline/steps.rs | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 7187e13..98089ca 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -4,12 +4,12 @@ //! the long-running child process happens outside any transaction (§11a). use std::path::Path; -use std::process::Command; use crate::db::{self, builds, model::*}; use crate::error::{Error, Result}; use crate::git; use crate::pipeline::{Collect, CollectedPkg, Ctx, StepResult}; +use crate::sandbox::Cmd; use crate::watch::digests::cached_path; pub fn run_step(ctx: &Ctx, step: &str) -> Result<StepResult> { @@ -119,12 +119,12 @@ fn chroot(ctx: &Ctx) -> Result<StepResult> { let seed = ctx.cfg.chroot_seed(&ctx.profile); if !seed.exists() { std::fs::create_dir_all(seed.parent().unwrap_or(&ctx.cfg.chroot_dir()))?; - let mut cmd = Command::new(&ctx.cfg.mkarchroot_bin); // Real devtools usage: `mkarchroot [options] <working-dir> <packages...>`. - cmd.arg(&seed).args(&ctx.cfg.mkarchroot_args); - ctx.cfg.child_env(&mut cmd); - let out = cmd.output()?; - if !out.status.success() { + let mut argv = vec![ctx.cfg.mkarchroot_bin.clone(), seed.display().to_string()]; + argv.extend(ctx.cfg.mkarchroot_args.iter().cloned()); + let sbx = ctx.sandbox()?; + let out = sbx.run(&Cmd::new(argv), &mut |_| {})?; + if !out.success() { return Err(Error::Subprocess { cmd: ctx.cfg.mkarchroot_bin.clone(), detail: String::from_utf8_lossy(&out.stderr).into_owned(), @@ -187,11 +187,10 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> { } return Ok(StepResult::Skipped("no VCS sources; pkgver is static".into())); } - let mut cmd = Command::new(&ctx.cfg.makepkg_bin); - cmd.current_dir(&ctx.srcdir).arg("--vercheck"); - ctx.cfg.child_env(&mut cmd); - let out = cmd.output()?; - if !out.status.success() { + let cmd = vec![ctx.cfg.makepkg_bin.clone(), "--vercheck".to_string()]; + let sbx = ctx.sandbox()?; + let out = sbx.run(&Cmd::new(cmd).in_dir(&ctx.srcdir), &mut |_| {})?; + if !out.success() { return Err(Error::Subprocess { cmd: ctx.cfg.makepkg_bin.clone(), detail: String::from_utf8_lossy(&out.stderr).into_owned(), @@ -216,25 +215,34 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> { /// the file the SSE tail reads. fn build(ctx: &Ctx) -> Result<StepResult> { let seed = ctx.cfg.chroot_seed(&ctx.profile); - let mut cmd = Command::new(&ctx.cfg.makechrootpkg_bin); - cmd.current_dir(&ctx.srcdir); - cmd.args(["-c", "-r", &seed.display().to_string(), "--"]); + let mut argv = vec![ + ctx.cfg.makechrootpkg_bin.clone(), + "-c".into(), + "-r".into(), + seed.display().to_string(), + "--".into(), + ]; if !ctx.cfg.signing_key_id.is_empty() { - cmd.arg(format!("-si{}", ctx.cfg.signing_key_id)); + argv.push(format!("-si{}", ctx.cfg.signing_key_id)); } - cmd.arg("-f"); - ctx.cfg.child_env(&mut cmd); - let out = cmd.output()?; - // Capture the child's output into the build log regardless of outcome. + argv.push("-f".into()); + // Capture the child's output into the build log regardless of outcome — + // the sandbox streams it here as it arrives, and the SSE tail reads the + // same file. if let Some(parent) = ctx.log.parent() { let _ = std::fs::create_dir_all(parent); } use std::io::Write; - if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(&ctx.log) { - let _ = f.write_all(&out.stdout); - let _ = f.write_all(&out.stderr); - } - if !out.status.success() { + let mut log_file = std::fs::OpenOptions::new().create(true).append(true).open(&ctx.log).ok(); + let mut on_log = move |bytes: &[u8]| { + if let Some(f) = log_file.as_mut() { + let _ = f.write_all(bytes); + } + }; + let sbx = ctx.sandbox()?; + let out = sbx.run(&Cmd::new(argv).in_dir(&ctx.srcdir), &mut on_log)?; + drop(on_log); // closes the log file before the outcome is recorded + if !out.success() { return Err(Error::Subprocess { cmd: ctx.cfg.makechrootpkg_bin.clone(), detail: tail(&out.stderr), |
