Add conversions for StorePath to harmonia
Only enabled with new feature "harmonia" due to harmonia's state of flux.
This commit is contained in:
parent
fddf079d35
commit
aae065cb3e
4 changed files with 960 additions and 10 deletions
898
Cargo.lock
generated
898
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -18,6 +18,7 @@ nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
|
|||
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
|
||||
lazy_static = "1.4"
|
||||
zerocopy = "0.8"
|
||||
harmonia-store-core = { version = "0.0.0-alpha.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
ctor = "0.2"
|
||||
|
|
@ -30,6 +31,9 @@ pkg-config = "0.3"
|
|||
# Needed for version parsing in build.rs
|
||||
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
|
||||
|
||||
[features]
|
||||
harmonia = [ "dep:harmonia-store-core" ]
|
||||
|
||||
[lints.rust]
|
||||
warnings = "deny"
|
||||
dead-code = "allow"
|
||||
|
|
|
|||
65
nix-bindings-store/src/path/harmonia.rs
Normal file
65
nix-bindings-store/src/path/harmonia.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
use anyhow::{Context as _, Result};
|
||||
|
||||
use super::{StorePath, STORE_PATH_HASH_SIZE};
|
||||
|
||||
impl TryFrom<&harmonia_store_core::store_path::StorePath> for StorePath {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(harmonia_path: &harmonia_store_core::store_path::StorePath) -> Result<Self> {
|
||||
let hash: &[u8; STORE_PATH_HASH_SIZE] = harmonia_path.hash().as_ref();
|
||||
StorePath::from_parts(hash, harmonia_path.name().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&StorePath> for harmonia_store_core::store_path::StorePath {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(nix_path: &StorePath) -> Result<Self> {
|
||||
let hash = nix_path
|
||||
.hash()
|
||||
.context("Failed to get hash from nix StorePath")?;
|
||||
let harmonia_hash = harmonia_store_core::store_path::StorePathHash::new(hash);
|
||||
|
||||
let name = nix_path
|
||||
.name()
|
||||
.context("Failed to get name from nix StorePath")?;
|
||||
|
||||
let harmonia_name: harmonia_store_core::store_path::StorePathName = name
|
||||
.parse()
|
||||
.context("Failed to parse name as StorePathName")?;
|
||||
|
||||
Ok(harmonia_store_core::store_path::StorePath::from((
|
||||
harmonia_hash,
|
||||
harmonia_name,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
#[test]
|
||||
fn store_path_round_trip_harmonia() {
|
||||
let harmonia_path: harmonia_store_core::store_path::StorePath =
|
||||
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv".parse().unwrap();
|
||||
|
||||
let nix_path: crate::path::StorePath = (&harmonia_path).try_into().unwrap();
|
||||
|
||||
let harmonia_round_trip: harmonia_store_core::store_path::StorePath =
|
||||
(&nix_path).try_into().unwrap();
|
||||
|
||||
assert_eq!(harmonia_path, harmonia_round_trip);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn store_path_harmonia_clone() {
|
||||
let harmonia_path: harmonia_store_core::store_path::StorePath =
|
||||
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv".parse().unwrap();
|
||||
|
||||
let nix_path: crate::path::StorePath = (&harmonia_path).try_into().unwrap();
|
||||
let cloned_path = nix_path.clone();
|
||||
|
||||
assert_eq!(nix_path.name().unwrap(), cloned_path.name().unwrap());
|
||||
assert_eq!(nix_path.hash().unwrap(), cloned_path.hash().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
@ -125,6 +125,9 @@ impl Drop for StorePath {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "harmonia", nix_at_least = "2.33"))]
|
||||
mod harmonia;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
Loading…
Add table
Add a link
Reference in a new issue