feat(tvix/cli): add replacement strings tracking to KnownPaths
Replacement strings are some weird internal feature of Nix that is required for calculating derivation hashes. We need to track these like other paths, as they need to be re-used on builds with dependencies on values from previous builds. Change-Id: Ie955b3fb5ae3685cfadfbe4d06ea6b5e219590c7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7828 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
499e72c1cb
commit
79e54f46ce
1 changed files with 29 additions and 0 deletions
|
@ -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"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue