aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/build.rs
blob: 11666ad4fa9d58a1efd769b0c6f78ec5691ee5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::path::PathBuf;

use crate::{command::BuildMode, TestRunError};

pub fn build_hexpath(
    example: &str,
    features: Option<&str>,
    build_mode: BuildMode,
    build_num: u32,
) -> anyhow::Result<String> {
    let features = match features {
        Some(f) => f,
        None => "",
    };

    let filename = format!("{}_{}_{}_{}.hex", example, features, build_mode, build_num);
    ["ci", "builds", &filename]
        .iter()
        .collect::<PathBuf>()
        .into_os_string()
        .into_string()
        .map_err(|e| anyhow::Error::new(TestRunError::PathConversionError(e)))
}

pub fn compare_builds(file_1: String, file_2: String) -> anyhow::Result<()> {
    let buf_1 = std::fs::read_to_string(file_1.clone())?;
    let buf_2 = std::fs::read_to_string(file_2.clone())?;

    if buf_1 != buf_2 {
        return Err(anyhow::Error::new(TestRunError::FileCmpError {
            file_1,
            file_2,
        }));
    }

    Ok(())
}