refactor(tvix/cli): split CLI-specific IO logic into TvixIO type

This adds a wrapper type TvixIO<T: EvalIO>, which can wrap around an
arbitrary EvalIO implementation and perform actions needed for the
Tvix CLI (marking imported paths as known, and handling __corepkgs__).

Change-Id: I5fc1ca199b9f94b21a89103b84575e0f8f58dff9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8579
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2023-05-17 18:33:22 +03:00 committed by tazjin
parent 7f99eb44a5
commit ba4807e1de
3 changed files with 84 additions and 11 deletions

View file

@ -9,10 +9,8 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::path::Path;
use std::process::Command;
use std::rc::Rc;
use std::{io, path::PathBuf};
use crate::known_paths::KnownPaths;
use smol_str::SmolStr;
use tvix_eval::{ErrorKind, EvalIO, FileType, StdIO};
@ -23,10 +21,6 @@ pub struct NixCompatIO {
/// instead.
underlying: StdIO,
/// Ingested paths must be reported to this known paths tracker
/// for accurate build reference scanning.
known_paths: Rc<RefCell<KnownPaths>>,
/// Cache paths for identical files being imported to the store.
// TODO(tazjin): This could be done better by having a thunk cache
// for these calls on the eval side, but that is a little more
@ -86,11 +80,10 @@ impl EvalIO for NixCompatIO {
}
impl NixCompatIO {
pub fn new(known_paths: Rc<RefCell<KnownPaths>>) -> Self {
pub fn new() -> Self {
NixCompatIO {
underlying: StdIO,
import_cache: RefCell::new(HashMap::new()),
known_paths,
}
}
@ -118,8 +111,6 @@ impl NixCompatIO {
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
let out_path_trimmed = out_path_str.trim();
self.known_paths.borrow_mut().plain(out_path_trimmed);
let mut out_path = PathBuf::new();
out_path.push(out_path_trimmed);
Ok(out_path)