diff --git a/xtask/src/build.rs b/xtask/src/build.rs index 11666ad4fa..a8c19aac73 100644 --- a/xtask/src/build.rs +++ b/xtask/src/build.rs @@ -1,7 +1,22 @@ -use std::path::PathBuf; +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>, @@ -14,10 +29,11 @@ pub fn build_hexpath( }; let filename = format!("{}_{}_{}_{}.hex", example, features, build_mode, build_num); - ["ci", "builds", &filename] - .iter() - .collect::() - .into_os_string() + + 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))) } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4d582ddd26..3243b98e20 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -14,7 +14,7 @@ use std::{ use structopt::StructOpt; use crate::{ - build::{build_hexpath, compare_builds}, + build::{build_hexpath, compare_builds, init_build_dir}, command::{run_command, run_successful, BuildMode, CargoCommand}, }; @@ -98,6 +98,8 @@ fn main() -> anyhow::Result<()> { let opts = Options::from_args(); let target = &opts.target; + init_build_dir()?; + if target == "all" { for t in targets { run_test(t, examples)?;