mirror of
https://github.com/DeterminateSystems/flake-checker.git
synced 2024-08-17 01:50:23 +03:00
Add Path variant to enum
This commit is contained in:
parent
85cb4ebf05
commit
a6aa366930
@ -3,7 +3,7 @@
|
|||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use serde::de::{self, MapAccess, Visitor};
|
use serde::de::{self, MapAccess, Visitor};
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
@ -137,7 +137,9 @@ fn chase_input_node(
|
|||||||
let maybe_node_inputs = match node {
|
let maybe_node_inputs = match node {
|
||||||
Node::Root(_) => None,
|
Node::Root(_) => None,
|
||||||
Node::Repo(node) => node.inputs.to_owned(),
|
Node::Repo(node) => node.inputs.to_owned(),
|
||||||
|
// TODO: investigate
|
||||||
Node::Indirect(_) => None,
|
Node::Indirect(_) => None,
|
||||||
|
Node::Path(_) => None,
|
||||||
Node::Fallthrough(node) => match node.get("inputs") {
|
Node::Fallthrough(node) => match node.get("inputs") {
|
||||||
Some(node_inputs) => serde_json::from_value(node_inputs.clone())
|
Some(node_inputs) => serde_json::from_value(node_inputs.clone())
|
||||||
.map_err(FlakeLockParseError::Json)?,
|
.map_err(FlakeLockParseError::Json)?,
|
||||||
@ -187,7 +189,10 @@ pub enum Node {
|
|||||||
/// A [RepoNode] flake input for a [Git](https://git-scm.com) repository (or another version
|
/// A [RepoNode] flake input for a [Git](https://git-scm.com) repository (or another version
|
||||||
/// control system).
|
/// control system).
|
||||||
Repo(Box<RepoNode>),
|
Repo(Box<RepoNode>),
|
||||||
|
/// TODO
|
||||||
Indirect(IndirectNode),
|
Indirect(IndirectNode),
|
||||||
|
/// TODO
|
||||||
|
Path(PathNode),
|
||||||
/// A "catch-all" variant for node types that don't (yet) have explicit struct definitions in
|
/// A "catch-all" variant for node types that don't (yet) have explicit struct definitions in
|
||||||
/// this crate.
|
/// this crate.
|
||||||
Fallthrough(serde_json::value::Value), // Covers all other node types
|
Fallthrough(serde_json::value::Value), // Covers all other node types
|
||||||
@ -199,6 +204,7 @@ impl Node {
|
|||||||
Node::Root(_) => "Root",
|
Node::Root(_) => "Root",
|
||||||
Node::Repo(_) => "Repo",
|
Node::Repo(_) => "Repo",
|
||||||
Node::Indirect(_) => "Indirect",
|
Node::Indirect(_) => "Indirect",
|
||||||
|
Node::Path(_) => "Path",
|
||||||
Node::Fallthrough(_) => "Fallthrough", // Covers all other node types
|
Node::Fallthrough(_) => "Fallthrough", // Covers all other node types
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,6 +241,7 @@ pub struct RepoNode {
|
|||||||
pub original: RepoOriginal,
|
pub original: RepoOriginal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Information about the flake input that's "locked" because it's supplied by Nix.
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct Locked {
|
pub struct Locked {
|
||||||
#[serde(alias = "lastModified")]
|
#[serde(alias = "lastModified")]
|
||||||
@ -248,6 +255,7 @@ pub struct Locked {
|
|||||||
pub node_type: String,
|
pub node_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `original` field of a [Repo][Node::Repo] node.
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct RepoOriginal {
|
pub struct RepoOriginal {
|
||||||
pub owner: String,
|
pub owner: String,
|
||||||
@ -258,6 +266,9 @@ pub struct RepoOriginal {
|
|||||||
pub git_ref: Option<String>,
|
pub git_ref: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An indirect flake input (using the
|
||||||
|
/// [flake
|
||||||
|
/// registry](https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-flake-registry)).
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct IndirectNode {
|
pub struct IndirectNode {
|
||||||
@ -265,9 +276,40 @@ pub struct IndirectNode {
|
|||||||
pub original: IndirectOriginal,
|
pub original: IndirectOriginal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `original` field of an [Indirect][Node::Indirect] node.
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct IndirectOriginal {
|
pub struct IndirectOriginal {
|
||||||
id: String,
|
pub id: String,
|
||||||
|
#[serde(alias = "type")]
|
||||||
|
pub node_type: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct PathNode {
|
||||||
|
pub locked: PathLocked,
|
||||||
|
pub original: PathOriginal,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
pub struct PathLocked {
|
||||||
|
#[serde(alias = "lastModified")]
|
||||||
|
pub last_modified: i64,
|
||||||
|
#[serde(alias = "narHash")]
|
||||||
|
pub nar_hash: String,
|
||||||
|
pub path: PathBuf,
|
||||||
|
#[serde(alias = "type")]
|
||||||
|
pub node_type: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
pub struct PathOriginal {
|
||||||
|
pub path: PathBuf,
|
||||||
|
#[serde(alias = "ref")]
|
||||||
|
pub git_ref: Option<String>,
|
||||||
#[serde(alias = "type")]
|
#[serde(alias = "type")]
|
||||||
pub node_type: String,
|
pub node_type: String,
|
||||||
}
|
}
|
||||||
|
18
src/flake.rs
18
src/flake.rs
@ -49,12 +49,20 @@ fn nixpkgs_deps(
|
|||||||
) -> Result<HashMap<String, Node>, FlakeCheckerError> {
|
) -> Result<HashMap<String, Node>, FlakeCheckerError> {
|
||||||
let mut deps: HashMap<String, Node> = HashMap::new();
|
let mut deps: HashMap<String, Node> = HashMap::new();
|
||||||
|
|
||||||
for (key, node) in flake_lock.root.clone() {
|
for (ref key, node) in flake_lock.root.clone() {
|
||||||
if let Node::Repo(_) = node {
|
if let Node::Repo(_) = &node {
|
||||||
if keys.contains(&key) {
|
if keys.contains(&key) {
|
||||||
deps.insert(key, node);
|
deps.insert(key.to_string(), node.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Node::Indirect(indirect_node) = &node {
|
||||||
|
if &indirect_node.original.id == key {
|
||||||
|
deps.insert(key.to_string(), node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: it's unclear that a path node for Nixpkgs should be accepted
|
||||||
}
|
}
|
||||||
let missing: Vec<String> = keys
|
let missing: Vec<String> = keys
|
||||||
.iter()
|
.iter()
|
||||||
@ -139,7 +147,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clean_flake_locks() {
|
fn test_clean_flake_locks() {
|
||||||
for n in 0..=4 {
|
for n in 0..=6 {
|
||||||
let path = PathBuf::from(format!("tests/flake.clean.{n}.lock"));
|
let path = PathBuf::from(format!("tests/flake.clean.{n}.lock"));
|
||||||
let flake_lock = FlakeLock::new(&path).expect("couldn't create flake.lock");
|
let flake_lock = FlakeLock::new(&path).expect("couldn't create flake.lock");
|
||||||
let config = FlakeCheckConfig {
|
let config = FlakeCheckConfig {
|
||||||
@ -147,7 +155,7 @@ mod test {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let issues = check_flake_lock(&flake_lock, &config)
|
let issues = check_flake_lock(&flake_lock, &config)
|
||||||
.expect("couldn't run check_flake_lock function");
|
.expect(&format!("couldn't run check_flake_lock function in {path:?}"));
|
||||||
assert!(issues.is_empty());
|
assert!(issues.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,36 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs-test": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1685573264,
|
"lastModified": 1689078114,
|
||||||
"narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=",
|
"narHash": "sha256-osG8BrX5RpKJ7wH+vI6auOU+ctvNOblT4XXCgknK47c=",
|
||||||
"owner": "nixos",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "380be19fbd2d9079f677978361792cb25e8a3635",
|
"rev": "b6cc7ff8fee93789bc871a267ab876c3fca042cb",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"id": "nixpkgs",
|
||||||
"ref": "release-22.05",
|
"ref": "nixpkgs-unstable",
|
||||||
"repo": "nixpkgs",
|
"type": "indirect"
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": "nixpkgs",
|
||||||
"nixpkgs-test"
|
"sub": "sub"
|
||||||
],
|
}
|
||||||
"nixpkgs-test": "nixpkgs-test"
|
},
|
||||||
|
"sub": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1,
|
||||||
|
"narHash": "sha256-+qUhj8mkS6BsSFAOMQek346MHTEDkmoaojSBbLefq7w=",
|
||||||
|
"path": "./sub",
|
||||||
|
"type": "path"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"path": "./sub",
|
||||||
|
"type": "path"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user