cmake_parser/doc/command/scripting/
find_path.rs1use cmake_parser_derive::CMake;
2
3use crate::{
4 command::common::{FindPath as CommonFindPath, FindRoot, Names, WindowsRegistryView},
5 doc::command_scope::{CommandScope, ToCommandScope},
6 Token,
7};
8
9#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
13#[cmake(pkg = "crate", untagged)]
14pub enum FindPath<'t> {
15 General(FindPathGeneral<'t>),
16 Short(FindPathShort<'t>),
17}
18
19impl<'t> ToCommandScope for FindPath<'t> {
20 fn to_command_scope(&self) -> CommandScope {
21 CommandScope::Scripting
22 }
23}
24
25#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
26#[cmake(pkg = "crate", default = "names")]
27pub struct FindPathGeneral<'t> {
28 #[cmake(positional)]
29 pub variable: Token<'t>,
30 #[cmake(rename = "")]
31 pub names: Names<'t>,
32 pub hints: Option<Vec<CommonFindPath<'t>>>,
33 pub paths: Option<Vec<CommonFindPath<'t>>>,
34 pub registry_view: Option<WindowsRegistryView>,
35 pub path_suffixes: Option<Vec<Token<'t>>>,
36 pub validator: Option<Token<'t>>,
37 pub doc: Option<Token<'t>>,
38 pub no_cache: bool,
39 pub required: bool,
40 pub no_default_path: bool,
41 pub no_package_root_path: bool,
42 pub no_cmake_path: bool,
43 pub no_cmake_environment_path: bool,
44 pub no_system_environment_path: bool,
45 pub no_cmake_system_path: bool,
46 pub no_cmake_install_prefix: bool,
47 pub find_root: Option<FindRoot>,
48}
49
50#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
51#[cmake(pkg = "crate", positional)]
52pub struct FindPathShort<'t> {
53 pub variable: Token<'t>,
54 pub name: Token<'t>,
55 pub paths: Vec<Token<'t>>,
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61 use crate::doc::cmake_parse::tests::{token, tokens_vec};
62 use crate::*;
63 use pretty_assertions::assert_eq;
64
65 #[test]
66 fn find_path() {
67 let src = include_bytes!("../../../../../fixture/commands/scripting/find_path");
68 let cmakelists = parse_cmakelists(src).unwrap();
69 let doc = Doc::from(cmakelists);
70 assert_eq!(
71 doc.commands(),
72 Ok(vec![
73 Command::FindPath(Box::new(FindPath::General(FindPathGeneral {
74 variable: token(b"variable1"),
75 names: Names::Multi(tokens_vec([b"name1", b"name2"])),
76 hints: None,
77 paths: None,
78 registry_view: None,
79 path_suffixes: None,
80 validator: None,
81 doc: None,
82 no_cache: false,
83 required: false,
84 no_default_path: false,
85 no_package_root_path: false,
86 no_cmake_path: false,
87 no_cmake_environment_path: false,
88 no_system_environment_path: false,
89 no_cmake_system_path: false,
90 no_cmake_install_prefix: false,
91 find_root: None,
92 }))),
93 Command::FindPath(Box::new(FindPath::Short(FindPathShort {
94 variable: token(b"variable1"),
95 name: token(b"name1"),
96 paths: tokens_vec([b"path1"]),
97 }))),
98 Command::FindPath(Box::new(FindPath::General(FindPathGeneral {
99 variable: token(b"variable1"),
100 names: Names::Multi(tokens_vec([b"name1", b"name2"])),
101 hints: Some(vec![
102 CommonFindPath::Path(token(b"path1")),
103 CommonFindPath::Path(token(b"path2")),
104 CommonFindPath::Env(token(b"env1")),
105 ]),
106 paths: Some(vec![
107 CommonFindPath::Env(token(b"env1")),
108 CommonFindPath::Env(token(b"env2")),
109 CommonFindPath::Path(token(b"path1")),
110 ]),
111 registry_view: Some(WindowsRegistryView::Target),
112 path_suffixes: Some(tokens_vec([b"suffix1", b"suffix2"])),
113 validator: Some(token(b"validator1")),
114 doc: Some(token(b"doc1")),
115 no_cache: true,
116 required: true,
117 no_default_path: true,
118 no_package_root_path: true,
119 no_cmake_path: true,
120 no_cmake_environment_path: true,
121 no_system_environment_path: true,
122 no_cmake_system_path: true,
123 no_cmake_install_prefix: true,
124 find_root: Some(FindRoot::CMakeFindRootPathBoth),
125 }))),
126 ])
127 )
128 }
129}