sandbox: add the Sandbox trait and the host backend

Build code needs an interface it can receive explicitly instead of a
global context. Add the 11-method Sandbox trait, the command description
and builder, the transfer options, and the shared stage_tree helper that
owns VCS pruning.

Host implements the trait with std::process and std::fs. A conformance
test runs against it and pins the command contract through an
Arc<dyn Sandbox>.
This commit is contained in:
vhaudiquet committed 2026-11-24 18:35:17 +01:00
1 parent 48306f3719
commit f1a21e0923
7 files changed
+648 -38

No files matched your search

+13 -3
View File
@@ -142,15 +142,25 @@ pub struct BuildCommand<'a> {
}
pub trait SandboxExt: Sandbox {
fn command(&self, program: &str) -> BuildCommand<'_> { /* ... */ }
fn command(&self, program: &str) -> BuildCommand<'_>;
fn stage_tree(
&self,
host: &Path,
dest: &Path,
opts: &StageOptions,
) -> io::Result<PutOutcome>;
}
impl<T: Sandbox + ?Sized> SandboxExt for T {}
impl<T: Sandbox> SandboxExt for T { /* forward to free functions */ }
impl SandboxExt for dyn Sandbox + '_ { /* same */ }
```
The extension trait keeps `sandbox.command("apt-get")` working on
`Arc<dyn Sandbox>` without putting a generic or `Self: Sized` method on the
trait. `status`, `output` and `capture` keep their current behavior.
trait. Two impls are needed: a default method cannot coerce `&Self` to
`&dyn Sandbox` when `Self` is unsized, so the blanket impl covers sized
backends and a second impl covers `dyn Sandbox`. Both forward to the same
free functions. `status`, `output` and `capture` keep their current behavior.
`src/exec.rs` holds the parts that are about processes, not environments:
`Stream`, `LineSink`, `pump`, the `sanitize_fds` pre-exec hook, the