aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/build.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2021-09-21 13:00:12 +0000
committerGravatar GitHub <noreply@github.com> 2021-09-21 13:00:12 +0000
commitc8621d78b9b1c0c67dff31404ade873a9d7b426e (patch)
treea958fa60fbeafedb7d8578c47fcaf506722e316f /xtask/src/build.rs
parentbf9df9fe73e9c1442a7a31ae93a91e7a8288f6f3 (diff)
parent7f45254e3939af5aa940c65e52c63fa83b93c16d (diff)
downloadrtic-c8621d78b9b1c0c67dff31404ade873a9d7b426e.tar.gz
rtic-c8621d78b9b1c0c67dff31404ade873a9d7b426e.tar.zst
rtic-c8621d78b9b1c0c67dff31404ade873a9d7b426e.zip
Merge #526
526: implement run-pass tests as xtasks r=korken89 a=Lotterleben resolves https://github.com/rtic-rs/cortex-m-rtic/issues/499 . With this PR, you should be able to run `cargo xtask --target <desired target>` or `cargo xtask --target all` locally. Of course, it also reconfigures the CI workflow to do the same. Note that I've translated the old `Run-pass tests` verbatim for now, which means the code includes checks for a `"types"`example which doesn't exist anymore. The examples could be collected much more nicely to prevent leftovers like this in the future, but imo that could also be achieved in a separate PR. Co-authored-by: Lotte Steenbrink <lotte.steenbrink@ferrous-systems.com>
Diffstat (limited to 'xtask/src/build.rs')
-rw-r--r--xtask/src/build.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/xtask/src/build.rs b/xtask/src/build.rs
new file mode 100644
index 00000000..a8c19aac
--- /dev/null
+++ b/xtask/src/build.rs
@@ -0,0 +1,53 @@
+use std::{
+ fs,
+ path::{Path, PathBuf},
+};
+
+use crate::{command::BuildMode, TestRunError};
+
+const HEX_BUILD_ROOT: &str = "ci/builds";
+
+/// make sure we're starting with a clean,but existing slate
+pub fn init_build_dir() -> anyhow::Result<()> {
+ if Path::new(HEX_BUILD_ROOT).exists() {
+ fs::remove_dir_all(HEX_BUILD_ROOT)
+ .map_err(|_| anyhow::anyhow!("Could not clear out directory: {}", HEX_BUILD_ROOT))?;
+ }
+ fs::create_dir_all(HEX_BUILD_ROOT)
+ .map_err(|_| anyhow::anyhow!("Could not create directory: {}", HEX_BUILD_ROOT))
+}
+
+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);
+
+ let mut path = PathBuf::from(HEX_BUILD_ROOT);
+ path.push(filename);
+
+ path.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(())
+}