refactor(nix-compat/store_path): take [u8;32] for outer fingerprint
The outer fingerprint used for store path calculation is always a sha256 digest. This includes both input and output-addressed store paths. We used a NixHash here, which can also represent other hash types, and that had a bunch of annoyances: - Whenever we had the bytes, we had to wrap them in a NixHash::Sha256(). - Things like AtermWriteable had to be implemented on NixHash, even though we then had an assertion it was only called in the NixHash::Sha256 case. Change-Id: Ic895503d9b071800d2e52ae057666f44bd0ab9d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11142 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: John Ericson <git@johnericson.me> Reviewed-by: picnoir picnoir <picnoir@alternativebit.fr>
This commit is contained in:
parent
35f636b684
commit
43c851bc84
5 changed files with 46 additions and 51 deletions
|
@ -8,7 +8,7 @@
|
|||
//! This data is required to find the derivation needed to actually trigger the
|
||||
//! build, if necessary.
|
||||
|
||||
use nix_compat::{derivation::Derivation, nixhash::NixHash, store_path::StorePath};
|
||||
use nix_compat::{derivation::Derivation, store_path::StorePath};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Struct keeping track of all known Derivations in the current evaluation.
|
||||
|
@ -20,7 +20,7 @@ pub struct KnownPaths {
|
|||
///
|
||||
/// Keys are derivation paths, values are a tuple of the "hash derivation
|
||||
/// modulo" and the Derivation struct itself.
|
||||
derivations: HashMap<StorePath, (NixHash, Derivation)>,
|
||||
derivations: HashMap<StorePath, ([u8; 32], Derivation)>,
|
||||
|
||||
/// A map from output path to (one) drv path.
|
||||
/// Note that in the case of FODs, multiple drvs can produce the same output
|
||||
|
@ -30,7 +30,7 @@ pub struct KnownPaths {
|
|||
|
||||
impl KnownPaths {
|
||||
/// Fetch the opaque "hash derivation modulo" for a given derivation path.
|
||||
pub fn get_hash_derivation_modulo(&self, drv_path: &StorePath) -> Option<&NixHash> {
|
||||
pub fn get_hash_derivation_modulo(&self, drv_path: &StorePath) -> Option<&[u8; 32]> {
|
||||
self.derivations
|
||||
.get(drv_path)
|
||||
.map(|(hash_derivation_modulo, _derivation)| hash_derivation_modulo)
|
||||
|
@ -83,7 +83,7 @@ impl KnownPaths {
|
|||
#[allow(unused_variables)] // assertions on this only compiled in debug builds
|
||||
let old = self
|
||||
.derivations
|
||||
.insert(drv_path.to_owned(), (hash_derivation_modulo.clone(), drv));
|
||||
.insert(drv_path.to_owned(), (hash_derivation_modulo, drv));
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ impl KnownPaths {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use nix_compat::{derivation::Derivation, nixhash::NixHash, store_path::StorePath};
|
||||
use nix_compat::{derivation::Derivation, store_path::StorePath};
|
||||
|
||||
use super::KnownPaths;
|
||||
use hex_literal::hex;
|
||||
|
@ -165,9 +165,9 @@ mod tests {
|
|||
|
||||
// It should be possible to get the hash derivation modulo.
|
||||
assert_eq!(
|
||||
Some(&NixHash::Sha256(hex!(
|
||||
Some(&hex!(
|
||||
"c79aebd0ce3269393d4a1fde2cbd1d975d879b40f0bf40a48f550edc107fd5df"
|
||||
))),
|
||||
)),
|
||||
known_paths.get_hash_derivation_modulo(&BAR_DRV_PATH.clone())
|
||||
);
|
||||
|
||||
|
@ -180,9 +180,9 @@ mod tests {
|
|||
known_paths.get_drv_by_drvpath(&FOO_DRV_PATH)
|
||||
);
|
||||
assert_eq!(
|
||||
Some(&NixHash::Sha256(hex!(
|
||||
Some(&hex!(
|
||||
"af030d36d63d3d7f56a71adaba26b36f5fa1f9847da5eed953ed62e18192762f"
|
||||
))),
|
||||
)),
|
||||
known_paths.get_hash_derivation_modulo(&FOO_DRV_PATH.clone())
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue