Grcov report - macros.rs

1

    #[macro_export]

2

    macro_rules! handle_output {

3

      ($output:expr, $context:expr) => {

4

        let output = $output

5

          .take()

6

          .with_context(|| format!("Failed to open {}", stringify!($output)))?;

7

        let multi_clone = $context.multi.clone();

8
186

        thread::spawn(move || {

9
186

          let reader = BufReader::new(output);

10
186

          for line in reader.lines().map_while(Result::ok) {

11
93

            let _ = multi_clone.println(line);

12
93

          }

13
186

        });

14

      };

15

    }

16

17

    #[macro_export]

18

    macro_rules! run_shell_command {

19

      ($value:expr, $shell:expr, $verbose:expr) => {{

20

        let arg = $value.trim_start_matches("$(").trim_end_matches(")");

21

        let stdout = if $verbose {

22

          std::process::Stdio::piped()

23

        } else {

24

          std::process::Stdio::null()

25

        };

26

27

        let mut cmd = std::process::Command::new($shell);

28

        let mut child = cmd.arg("-c").arg(arg).stdout(stdout).spawn()?;

29

        let stdout = child

30

          .stdout

31

          .take()

32

          .ok_or_else(|| anyhow::anyhow!("Failed to open stdout"))?;

33

        let buf = std::io::BufReader::new(stdout);

34

        let output = buf

35

          .lines()

36

          .next()

37

          .ok_or_else(|| anyhow::anyhow!("Failed to read stdout"))??;

38

        output

39

      }};

40

    }

41

42

    #[macro_export]

43

    macro_rules! get_template_command_value {

44

      ($value:expr, $context:expr) => {{

45

        let value = $value.trim_start_matches("${{").trim_end_matches("}}").trim();

46

        let value = if value.starts_with("env.") {

47

          let value = value.trim_start_matches("env.");

48

          let value = $context

49

            .env_vars

50

            .get(value)

51

            .ok_or_else(|| anyhow::anyhow!("Failed to find environment variable"))?;

52

          value

53

        } else {

54

          value

55

        };

56

        value.to_string()

57

      }};

58

    }