cmake_file_api/objects/codemodel_v2/
directory.rs

1#![allow(clippy::struct_excessive_bools)]
2#![allow(clippy::module_name_repetitions)]
3
4use super::backtrace_graph::BacktraceGraph;
5use serde::{Deserialize, Serialize};
6use std::path::PathBuf;
7
8/// A codemodel "directory" object is referenced by a "codemodel" version 2 object's directories array.
9#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11#[non_exhaustive]
12pub struct Directory {
13    /// Paths of the directory object.
14    pub paths: DirectoryPaths,
15
16    /// A "codemodel" version 2 "backtrace graph" whose nodes are referenced from backtrace members elsewhere in this "directory" object.
17    pub backtrace_graph: BacktraceGraph,
18
19    /// Entries corresponding to install() rules
20    pub installers: Vec<Installer>,
21}
22
23#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25#[non_exhaustive]
26pub struct DirectoryPaths {
27    /// A string specifying the path to the source directory, represented with forward slashes.
28    /// If the directory is inside the top-level source directory then the path is specified
29    /// relative to that directory (with . for the top-level source directory itself).
30    /// Otherwise, the path is absolute.
31    pub build: PathBuf,
32
33    /// A string specifying the path to the build directory, represented with forward slashes.
34    /// If the directory is inside the top-level build directory then the path is specified
35    /// relative to that directory (with . for the top-level build directory itself).
36    /// Otherwise, the path is absolute.
37    pub source: PathBuf,
38}
39
40#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
41#[serde(rename_all = "camelCase")]
42#[non_exhaustive]
43pub struct Installer {
44    /// A string specifying the component selected by the corresponding to install() command invocation.
45    pub component: String,
46
47    /// Optional member that is present for specific type values below. The value is a string specifying the installation destination path.
48    /// The path may be absolute or relative to the installation prefix.
49    pub destination: Option<String>,
50
51    /// Optional member that is present for specific installer_type values below.
52    #[serde(default)]
53    pub paths: Vec<InstallPath>,
54
55    /// A string specifying the type of installation rule. The value is one of the following, with some variants providing additional members:
56    /// * file: An install(FILES) or install(PROGRAMS) call. The destination and paths members are populated, with paths under the top-level source directory expressed relative to it. The isOptional member may exist. This type has no additional members.
57    /// * directory: An install(DIRECTORY) call. The destination and paths members are populated, with paths under the top-level source directory expressed relative to it. The isOptional member may exist. This type has no additional members.
58    /// * target: An install(TARGETS) call. The destination and paths members are populated, with paths under the top-level build directory expressed relative to it. The isOptional member may exist. This type has additional members targetId, targetIndex, targetIsImportLibrary, and targetInstallNamelink.
59    /// * export: An install(EXPORT) call. The destination and paths members are populated, with paths under the top-level build directory expressed relative to it. The paths entries refer to files generated automatically by CMake for installation, and their actual values are considered private implementation details. This type has additional members exportName and exportTargets.
60    /// * script: An install(SCRIPT) call. This type has additional member scriptFile.
61    /// * code: An install(CODE) call. This type has no additional members.
62    /// * importedRuntimeArtifacts: An install(IMPORTED_RUNTIME_ARTIFACTS) call. The destination member is populated. The isOptional member may exist. This type has no additional members.
63    /// * runtimeDependencySet: An install(RUNTIME_DEPENDENCY_SET) call or an install(TARGETS) call with RUNTIME_DEPENDENCIES. The destination member is populated. This type has additional members runtimeDependencySetName and runtimeDependencySetType.
64    /// * fileSet: An install(TARGETS) call with FILE_SET. The destination and paths members are populated. The isOptional member may exist. This type has additional members fileSetName, fileSetType, fileSetDirectories, and fileSetTarget.
65    /// This type was added in codemodel version 2.4.
66    #[serde(rename = "type")]
67    pub installer_type: String,
68
69    /// True when install() is called with the EXCLUDE_FROM_ALL option.
70    #[serde(default)]
71    pub is_exclude_from_all: bool,
72
73    /// True when install(SCRIPT|CODE) is called with the ALL_COMPONENTS option.
74    #[serde(default)]
75    pub is_for_all_components: bool,
76
77    /// True when install() is called with the OPTIONAL option.
78    /// This is allowed when type is file, directory, or target.
79    #[serde(default)]
80    pub is_optional: bool,
81
82    /// Optional member that is present when type is target. The value is a string uniquely identifying the target to be installed.
83    /// This matches the id member of the target in the main "codemodel" object's targets array.
84    pub target_id: Option<String>,
85
86    /// Optional member that is present when type is target.
87    /// The value is an unsigned integer 0-based index into the main "codemodel" object's targets array for the target to be installed.
88    pub target_index: Option<usize>,
89
90    /// True when type is target and the installer is for a Windows DLL import library file or for an AIX linker import file.
91    #[serde(default)]
92    pub target_is_import_library: bool,
93
94    /// Optional member that is present when type is target and the installer corresponds to a target that may use symbolic links
95    /// to implement the VERSION and SOVERSION target properties.
96    /// The value is a string indicating how the installer is supposed to handle the symlinks:
97    /// <b>skip</b> means the installer should skip the symlinks and install only the real file
98    /// <b>only</b> means the installer should install only the symlinks and not the real file.
99    /// In all cases the paths member lists what it actually installs.
100    pub target_install_namelink: Option<String>,
101
102    /// Optional member that is present when type is export.
103    /// The value is a string specifying the name of the export.
104    pub export_name: Option<String>,
105
106    /// Optional member that is present when <b>type</b> equals export.
107    #[serde(default)]
108    pub export_targets: Vec<TargetIdAndIndex>,
109
110    /// Optional member that is present when type is runtimeDependencySet and the installer was created by an install(RUNTIME_DEPENDENCY_SET) call.
111    /// The value is a string specifying the name of the runtime dependency set that was installed.
112    pub runtime_dependency_set_name: Option<String>,
113
114    /// Optional member that is present when type is runtimeDependencySet.
115    /// The value is a string with one of the following values:
116    /// * library: Indicates that this installer installs dependencies that are not macOS frameworks.
117    /// * framework: Indicates that this installer installs dependencies that are macOS frameworks.
118    pub runtime_dependency_set_type: Option<String>,
119
120    /// Optional member that is present when type is fileSet. The value is a string with the name of the file set.
121    /// This field was added in codemodel version 2.4.
122    pub file_set_name: Option<String>,
123
124    /// Optional member that is present when type is fileSet. The value is a string with the type of the file set.
125    /// This field was added in codemodel version 2.4.
126    pub file_set_type: Option<String>,
127
128    /// Optional member that is present when type is fileSet.
129    /// The value is a list of strings with the file set's base directories (determined by genex-evaluation of HEADER_DIRS or `HEADER_DIRS_<NAME>`).
130    /// This field was added in codemodel version 2.4.
131    #[serde(default)]
132    pub file_set_directories: Vec<String>,
133
134    /// Optional member that is present when type is fileSet.
135    /// This field was added in codemodel version 2.4.
136    pub file_set_target: Option<TargetIdAndIndex>,
137
138    /// Optional member that is present when type is script.
139    /// The value is a string specifying the path to the script file on disk, represented with forward slashes.
140    /// If the file is inside the top-level source directory then the path is specified relative to that directory.
141    /// Otherwise, the path is absolute.
142    pub script_file: Option<PathBuf>,
143
144    /// Optional member that is present when a CMake language backtrace to the install() or other command invocation
145    /// that added this installer is available.
146    /// The value is an unsigned integer 0-based index into the backtraceGraph member's nodes array.
147    pub backtrace: Option<usize>,
148}
149#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
150#[serde(rename_all = "camelCase")]
151#[non_exhaustive]
152pub struct TargetIdAndIndex {
153    /// A string uniquely identifying the target.
154    /// This matches the id member of the target in the main "codemodel" object's targets array.
155    pub id: String,
156
157    /// An unsigned integer 0-based index into the main "codemodel" object's targets array for the target.
158    pub index: usize,
159}
160
161#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
162#[serde(rename_all = "camelCase")]
163#[non_exhaustive]
164pub struct FromToPaths {
165    /// Path from which a file or directory is to be installed.
166    pub from: PathBuf,
167
168    /// Path to which the file or directory is to be installed under the destination.
169    pub to: PathBuf,
170}
171
172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
173#[serde(untagged)]
174#[non_exhaustive]
175pub enum InstallPath {
176    /// A string specifying the path from which a file or directory is to be installed.
177    /// The portion of the path not preceded by a / also specifies the path (name) to which the file or directory is to be installed
178    /// under the destination.
179    PathCombination(String),
180
181    /// A pair of paths specifying the path from which a file or directory is to be installed and
182    /// the path to which the file or directory is to be installed under the destination.
183    FromTo(FromToPaths),
184}
185
186#[cfg(test)]
187mod tests {
188    use crate::objects::codemodel_v2::directory::*;
189    use serde_json::json;
190    use std::path::PathBuf;
191
192    #[test]
193    fn test_directory() {
194        let json = json!({
195            "backtraceGraph" :
196            {
197                "commands" : [],
198                "files" : [],
199                "nodes" : []
200            },
201            "installers" : [],
202            "paths" :
203            {
204                "build" : ".",
205                "source" : "."
206            }
207        });
208
209        let dir = serde_json::from_value::<Directory>(json).unwrap();
210        assert_eq!(
211            dir,
212            Directory {
213                backtrace_graph: BacktraceGraph {
214                    ..Default::default()
215                },
216                installers: vec![],
217                paths: DirectoryPaths {
218                    build: PathBuf::from("."),
219                    source: PathBuf::from(".")
220                }
221            }
222        );
223    }
224}