diff options
Diffstat (limited to 'tvix/cli/src/known_paths.rs')
-rw-r--r-- | tvix/cli/src/known_paths.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tvix/cli/src/known_paths.rs b/tvix/cli/src/known_paths.rs index 569fb41ba318..a5e95f5b5972 100644 --- a/tvix/cli/src/known_paths.rs +++ b/tvix/cli/src/known_paths.rs @@ -33,6 +33,12 @@ pub enum PathType { pub struct KnownPaths { /// All known paths, and their associated [`PathType`]. paths: HashMap<String, PathType>, + + /// All known replacement strings for derivations. + /// + /// Keys are derivation paths, values are the opaque replacement + /// strings. + replacements: HashMap<String, String>, } impl Index<&str> for KnownPaths { @@ -112,4 +118,27 @@ impl KnownPaths { let candidates = self.paths.keys().map(Clone::clone).collect(); ReferenceScanner::new(candidates) } + + /// Fetch the opaque "replacement string" for a given derivation path. + pub fn get_replacement_string(&self, drv: &str) -> String { + // TODO: we rely on an invariant that things *should* have + // been calculated if we get this far. + self.replacements[drv].clone() + } + + pub fn add_replacement_string<D: ToString>(&mut self, drv: D, replacement_str: &str) { + let old = self + .replacements + .insert(drv.to_string(), replacement_str.to_owned()); + + #[cfg(debug_assertions)] + { + if let Some(old) = old { + debug_assert!( + old == replacement_str, + "replacement string for a given derivation should always match" + ); + } + } + } } |