cmake_parser/doc/command/deprecated/
exec_program.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Run an executable program during the processing of the CMakeList.txt file.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/exec_program.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate", default = "dir")]
13pub struct ExecProgram<'t> {
14    #[cmake(positional)]
15    pub executable: Token<'t>,
16    #[cmake(rename = "")]
17    pub dir: Option<Token<'t>>,
18    pub args: Option<Vec<Token<'t>>>,
19    pub output_variable: Option<Token<'t>>,
20    pub return_value: Option<Token<'t>>,
21}
22
23impl<'t> ToCommandScope for ExecProgram<'t> {
24    fn to_command_scope(&self) -> CommandScope {
25        CommandScope::Deprecated
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32    use crate::doc::cmake_parse::tests::{token, tokens_vec};
33    use crate::*;
34    use pretty_assertions::assert_eq;
35
36    #[test]
37    fn exec_program() {
38        let src = include_bytes!("../../../../../fixture/commands/deprecated/exec_program");
39        let cmakelists = parse_cmakelists(src).unwrap();
40        let doc = Doc::from(cmakelists);
41        assert_eq!(
42            doc.commands(),
43            Ok(vec![
44                Command::ExecProgram(Box::new(ExecProgram {
45                    executable: token(b"exe1"),
46                    dir: Some(token(b"dir1")),
47                    args: Some(tokens_vec([b"arg1", b"arg2"])),
48                    output_variable: Some(token(b"output_variable1")),
49                    return_value: Some(token(b"return_value1")),
50                })),
51                Command::ExecProgram(Box::new(ExecProgram {
52                    executable: token(b"exe1"),
53                    dir: None,
54                    args: Some(tokens_vec([b"arg1", b"arg2"])),
55                    output_variable: None,
56                    return_value: None,
57                })),
58            ])
59        )
60    }
61}