use crate::objects::{MajorMinor, Object, ObjectKind};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct CMakeFiles {
pub kind: ObjectKind,
pub version: MajorMinor,
pub paths: Paths,
pub inputs: Vec<Input>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Paths {
pub build: PathBuf,
pub source: PathBuf,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Input {
pub path: PathBuf,
#[serde(default)]
pub is_generated: bool,
#[serde(default)]
pub is_external: bool,
#[serde(default, rename = "isCMake")]
pub is_cmake: bool,
}
impl Object for CMakeFiles {
fn kind() -> ObjectKind {
ObjectKind::CMakeFiles
}
fn major() -> u32 {
1
}
}
#[cfg(test)]
mod tests {
use crate::objects::cmake_files_v1::*;
use serde_json::json;
#[test]
fn test_configure_log() {
let json = json!({
"kind": "cmakeFiles",
"version": { "major": 1, "minor": 0 },
"paths": {
"build": "/path/to/top-level-build-dir",
"source": "/path/to/top-level-source-dir"
},
"inputs": [
{
"path": "CMakeLists.txt"
},
{
"isGenerated": true,
"path": "/path/to/top-level-build-dir/../CMakeSystem.cmake"
},
{
"isExternal": true,
"path": "/path/to/external/third-party/module.cmake"
},
{
"isCMake": true,
"isExternal": true,
"path": "/path/to/cmake/Modules/CMakeGenericSystem.cmake"
}
]
});
let cmake_files = serde_json::from_value::<CMakeFiles>(json).unwrap();
assert_eq!(
cmake_files,
CMakeFiles {
kind: ObjectKind::CMakeFiles,
version: MajorMinor { major: 1, minor: 0 },
paths: Paths {
build: "/path/to/top-level-build-dir".into(),
source: "/path/to/top-level-source-dir".into()
},
inputs: vec![
Input {
path: "CMakeLists.txt".into(),
..Default::default()
},
Input {
is_generated: true,
path: "/path/to/top-level-build-dir/../CMakeSystem.cmake".into(),
..Default::default()
},
Input {
is_external: true,
path: "/path/to/external/third-party/module.cmake".into(),
..Default::default()
},
Input {
is_cmake: true,
is_external: true,
path: "/path/to/cmake/Modules/CMakeGenericSystem.cmake".into(),
..Default::default()
}
]
}
);
}
}