cmake_file_api/objects/
cmake_files_v1.rs1use crate::objects::{MajorMinor, Object, ObjectKind};
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9#[non_exhaustive]
10pub struct CMakeFiles {
11 pub kind: ObjectKind,
13
14 pub version: MajorMinor,
16
17 pub paths: Paths,
19
20 pub inputs: Vec<Input>,
22}
23
24#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26#[non_exhaustive]
27pub struct Paths {
28 pub build: PathBuf,
30
31 pub source: PathBuf,
33}
34
35#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase")]
37#[non_exhaustive]
38pub struct Input {
39 pub path: PathBuf,
43
44 #[serde(default)]
46 pub is_generated: bool,
47
48 #[serde(default)]
50 pub is_external: bool,
51
52 #[serde(default, rename = "isCMake")]
54 pub is_cmake: bool,
55}
56
57impl Object for CMakeFiles {
58 fn kind() -> ObjectKind {
59 ObjectKind::CMakeFiles
60 }
61
62 fn major() -> u32 {
63 1
64 }
65}
66
67#[cfg(test)]
68mod tests {
69 use crate::objects::cmake_files_v1::*;
70 use serde_json::json;
71
72 #[test]
73 fn test_configure_log() {
74 let json = json!({
75 "kind": "cmakeFiles",
76 "version": { "major": 1, "minor": 0 },
77 "paths": {
78 "build": "/path/to/top-level-build-dir",
79 "source": "/path/to/top-level-source-dir"
80 },
81 "inputs": [
82 {
83 "path": "CMakeLists.txt"
84 },
85 {
86 "isGenerated": true,
87 "path": "/path/to/top-level-build-dir/../CMakeSystem.cmake"
88 },
89 {
90 "isExternal": true,
91 "path": "/path/to/external/third-party/module.cmake"
92 },
93 {
94 "isCMake": true,
95 "isExternal": true,
96 "path": "/path/to/cmake/Modules/CMakeGenericSystem.cmake"
97 }
98 ]
99 });
100
101 let cmake_files = serde_json::from_value::<CMakeFiles>(json).unwrap();
102 assert_eq!(
103 cmake_files,
104 CMakeFiles {
105 kind: ObjectKind::CMakeFiles,
106 version: MajorMinor { major: 1, minor: 0 },
107 paths: Paths {
108 build: "/path/to/top-level-build-dir".into(),
109 source: "/path/to/top-level-source-dir".into()
110 },
111 inputs: vec![
112 Input {
113 path: "CMakeLists.txt".into(),
114 ..Default::default()
115 },
116 Input {
117 is_generated: true,
118 path: "/path/to/top-level-build-dir/../CMakeSystem.cmake".into(),
119 ..Default::default()
120 },
121 Input {
122 is_external: true,
123 path: "/path/to/external/third-party/module.cmake".into(),
124 ..Default::default()
125 },
126 Input {
127 is_cmake: true,
128 is_external: true,
129 path: "/path/to/cmake/Modules/CMakeGenericSystem.cmake".into(),
130 ..Default::default()
131 }
132 ]
133 }
134 );
135 }
136}