cmake_parser/doc/command/scripting/
cmake_host_system_information.rs1use cmake_parser_derive::CMake;
2
3use crate::{
4 command::common::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")]
14pub struct CMakeHostSystemInformation<'t> {
15 pub result: Token<'t>,
16 pub query: Query<'t>,
17}
18
19impl<'t> ToCommandScope for CMakeHostSystemInformation<'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", untagged)]
27pub enum Query<'t> {
28 #[cmake(transparent)]
29 WindowsRegistry(WindowsRegistryQuery<'t>),
30 Regular(Vec<Token<'t>>),
31}
32
33#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
34#[cmake(pkg = "crate")]
35pub struct WindowsRegistryQuery<'t> {
36 #[cmake(positional)]
37 pub key: Token<'t>,
38 pub selector: Option<WindowsRegistrySelector<'t>>,
39 pub view: Option<WindowsRegistryView>,
40 pub separator: Option<Token<'t>>,
41 pub error_variable: Option<Token<'t>>,
42}
43
44#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
45#[cmake(pkg = "crate")]
46pub enum WindowsRegistrySelector<'t> {
47 ValueNames,
48 Subkeys,
49 #[cmake(transparent)]
50 Value(Token<'t>),
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56 use crate::doc::cmake_parse::tests::{quoted_token, token, tokens_vec};
57 use crate::*;
58 use pretty_assertions::assert_eq;
59
60 #[test]
61 fn cmake_host_system_information() {
62 let src = include_bytes!(
63 "../../../../../fixture/commands/scripting/cmake_host_system_information"
64 );
65 let cmakelists = parse_cmakelists(src).unwrap();
66 let doc = Doc::from(cmakelists);
67 assert_eq!(
68 doc.commands(),
69 Ok(vec![
70 Command::CMakeHostSystemInformation(Box::new(CMakeHostSystemInformation {
71 result: token(b"Ncpu"),
72 query: Query::Regular(tokens_vec([b"NUMBER_OF_PHYSICAL_CORES"])),
73 })),
74 Command::CMakeHostSystemInformation(Box::new(CMakeHostSystemInformation {
75 result: token(b"result"),
76 query: Query::WindowsRegistry(WindowsRegistryQuery {
77 key: quoted_token(b"HKLM/SOFTWARE/Kitware"),
78 selector: None,
79 view: None,
80 separator: None,
81 error_variable: None,
82 }),
83 })),
84 Command::CMakeHostSystemInformation(Box::new(CMakeHostSystemInformation {
85 result: token(b"result"),
86 query: Query::WindowsRegistry(WindowsRegistryQuery {
87 key: quoted_token(b"HKLM/SOFTWARE/Kitware"),
88 selector: Some(WindowsRegistrySelector::Value(quoted_token(b"(default)"))),
89 view: None,
90 separator: None,
91 error_variable: None,
92 }),
93 })),
94 Command::CMakeHostSystemInformation(Box::new(CMakeHostSystemInformation {
95 result: token(b"result"),
96 query: Query::WindowsRegistry(WindowsRegistryQuery {
97 key: quoted_token(b"HKLM/SOFTWARE/Kitware"),
98 selector: Some(WindowsRegistrySelector::Subkeys),
99 view: Some(WindowsRegistryView::Bits32Fallback64),
100 separator: Some(token(b"separator1")),
101 error_variable: Some(token(b"error_variable1")),
102 }),
103 })),
104 Command::CMakeHostSystemInformation(Box::new(CMakeHostSystemInformation {
105 result: token(b"_vs_dir"),
106 query: Query::Regular(tokens_vec([b"VS_${_vs_ver}_DIR"])),
107 })),
108 ])
109 )
110 }
111}