aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/build.rs42
-rw-r--r--xtask/src/command.rs54
-rw-r--r--xtask/src/main.rs131
3 files changed, 35 insertions, 192 deletions
diff --git a/xtask/src/build.rs b/xtask/src/build.rs
index 904e9177..148a9fde 100644
--- a/xtask/src/build.rs
+++ b/xtask/src/build.rs
@@ -1,9 +1,4 @@
-use std::{
- fs,
- path::{Path, PathBuf},
-};
-
-use crate::{command::BuildMode, TestRunError};
+use std::{fs, path::Path};
const HEX_BUILD_ROOT: &str = "ci/builds";
@@ -16,38 +11,3 @@ pub fn init_build_dir() -> anyhow::Result<()> {
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(expected: String, got: String) -> anyhow::Result<()> {
- let buf_1 = std::fs::read_to_string(expected.clone())?;
- let buf_2 = std::fs::read_to_string(got.clone())?;
-
- if buf_1 != buf_2 {
- return Err(anyhow::Error::new(TestRunError::FileCmpError {
- expected,
- got,
- }));
- }
-
- Ok(())
-}
diff --git a/xtask/src/command.rs b/xtask/src/command.rs
index d94a7ab3..2f719bf5 100644
--- a/xtask/src/command.rs
+++ b/xtask/src/command.rs
@@ -1,7 +1,7 @@
use crate::{RunResult, TestRunError};
use core::fmt;
use os_pipe::pipe;
-use std::{fs::File, io::Read, path::Path, process::Command};
+use std::{fs::File, io::Read, process::Command};
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -18,32 +18,23 @@ pub enum CargoCommand<'a> {
features: Option<&'a str>,
mode: BuildMode,
},
- Build {
- example: &'a str,
+ BuildAll {
target: &'a str,
features: Option<&'a str>,
mode: BuildMode,
},
- Objcopy {
- example: &'a str,
- target: &'a str,
- features: Option<&'a str>,
- ihex: &'a str,
- },
- Size {
- example_paths: Vec<&'a Path>,
- },
- Clean,
+ // Size {
+ // example_paths: Vec<&'a Path>,
+ // },
+ // Clean,
}
impl<'a> CargoCommand<'a> {
fn name(&self) -> &str {
match self {
CargoCommand::Run { .. } => "run",
- CargoCommand::Size { example_paths: _ } => "rust-size",
- CargoCommand::Clean => "clean",
- CargoCommand::Build { .. } => "build",
- CargoCommand::Objcopy { .. } => "objcopy",
+ // CargoCommand::Size { example_paths: _ } => "rust-size",
+ CargoCommand::BuildAll { .. } => "build",
}
}
@@ -54,12 +45,6 @@ impl<'a> CargoCommand<'a> {
target,
features,
mode,
- }
- | CargoCommand::Build {
- example,
- target,
- features,
- mode,
} => {
let mut args = vec![self.name(), "--example", example, "--target", target];
@@ -71,26 +56,23 @@ impl<'a> CargoCommand<'a> {
}
args
}
- CargoCommand::Size { example_paths } => {
- example_paths.iter().map(|p| p.to_str().unwrap()).collect()
- }
- CargoCommand::Clean => vec!["clean"],
- CargoCommand::Objcopy {
- example,
+ CargoCommand::BuildAll {
target,
features,
- ihex,
+ mode,
} => {
- let mut args = vec![self.name(), "--example", example, "--target", target];
+ let mut args = vec![self.name(), "--examples", "--target", target];
if let Some(feature_name) = features {
args.extend_from_slice(&["--features", feature_name]);
}
-
- // this always needs to go at the end
- args.extend_from_slice(&["--", "-O", "ihex", ihex]);
+ if let Some(flag) = mode.to_flag() {
+ args.push(flag);
+ }
args
- }
+ } // CargoCommand::Size { example_paths } => {
+ // example_paths.iter().map(|p| p.to_str().unwrap()).collect()
+ // }
}
}
@@ -99,7 +81,7 @@ impl<'a> CargoCommand<'a> {
// we need to cheat a little here:
// `cargo size` can't be ran on multiple files, so we're using `rust-size` instead –
// which isn't a command that starts wizh `cargo`. So we're sneakily swapping them out :)
- CargoCommand::Size { .. } => "rust-size",
+ // CargoCommand::Size { .. } => "rust-size",
_ => "cargo",
}
}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index ad8719ad..76ce04bd 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, init_build_dir},
+ build::init_build_dir,
command::{run_command, run_successful, BuildMode, CargoCommand},
};
@@ -93,25 +93,6 @@ fn main() -> anyhow::Result<()> {
})
.collect();
- // let examples = &[
- // "idle",
- // "init",
- // "hardware",
- // "preempt",
- // "binds",
- // "lock",
- // "multilock",
- // "only-shared-access",
- // "task",
- // "message",
- // "capacity",
- // "not-sync",
- // "generics",
- // "pool",
- // "ramfunc",
- // "peripherals-taken",
- // ];
-
let opts = Options::from_args();
let target = &opts.target;
@@ -120,11 +101,9 @@ fn main() -> anyhow::Result<()> {
if target == "all" {
for t in targets {
run_test(t, &examples)?;
- build_test(t, &examples)?;
}
} else if targets.contains(&target.as_str()) {
run_test(&target, &examples)?;
- build_test(&target, &examples)?;
} else {
eprintln!(
"The target you specified is not available. Available targets are:\
@@ -139,6 +118,12 @@ fn main() -> anyhow::Result<()> {
}
fn run_test(target: &str, examples: &[String]) -> anyhow::Result<()> {
+ arm_example(&CargoCommand::BuildAll {
+ target,
+ features: None,
+ mode: BuildMode::Release,
+ })?;
+
for example in examples {
let cmd = CargoCommand::Run {
example,
@@ -147,37 +132,16 @@ fn run_test(target: &str, examples: &[String]) -> anyhow::Result<()> {
mode: BuildMode::Release,
};
- arm_example(&cmd, 1)?;
-
- arm_example(
- &CargoCommand::Build {
- example,
- target,
- features: None,
- mode: BuildMode::Release,
- },
- 1,
- )?;
+ arm_example(&cmd)?;
}
Ok(())
}
// run example binary `example`
-fn arm_example(command: &CargoCommand, build_num: u32) -> anyhow::Result<()> {
+fn arm_example(command: &CargoCommand) -> anyhow::Result<()> {
match *command {
- CargoCommand::Run {
- example,
- target,
- features,
- mode,
- }
- | CargoCommand::Build {
- example,
- target,
- features,
- mode,
- } => {
+ CargoCommand::Run { example, .. } => {
let run_file = format!("{}.run", example);
let expected_output_file = ["ci", "expected", &run_file]
.iter()
@@ -197,77 +161,14 @@ fn arm_example(command: &CargoCommand, build_num: u32) -> anyhow::Result<()> {
_ => (),
}
- // now, prepare to objcopy
- let hexpath = build_hexpath(example, features, mode, build_num)?;
-
- run_command(&CargoCommand::Objcopy {
- example,
- target,
- features,
- ihex: &hexpath,
- })?;
-
Ok(())
}
- _ => Err(anyhow::Error::new(TestRunError::IncompatibleCommand)),
- }
-}
-
-fn build_test(target: &str, examples: &[String]) -> anyhow::Result<()> {
- run_command(&CargoCommand::Clean)?;
-
- let mut built = vec![];
- let build_path: PathBuf = ["target", target, "release", "examples"].iter().collect();
-
- for example in examples {
- let no_features = None;
- arm_example(
- &CargoCommand::Build {
- target,
- example,
- mode: BuildMode::Release,
- features: no_features,
- },
- 2,
- )?;
- let expected = build_hexpath(example, no_features, BuildMode::Release, 1)?;
- let got = build_hexpath(example, no_features, BuildMode::Release, 2)?;
-
- compare_builds(expected, got)?;
-
- arm_example(
- &CargoCommand::Build {
- target,
- example,
- mode: BuildMode::Release,
- features: no_features,
- },
- 2,
- )?;
- let expected = build_hexpath(example, no_features, BuildMode::Release, 1)?;
- let got = build_hexpath(example, no_features, BuildMode::Release, 2)?;
-
- compare_builds(expected, got)?;
-
- built.push(build_path.join(example));
- }
-
- let example_paths: Vec<&Path> = built.iter().map(|p| p.as_path()).collect();
- let size_run_result = run_command(&CargoCommand::Size { example_paths })?;
+ CargoCommand::BuildAll { .. } => {
+ // command is either build or run
+ let cargo_run_result = run_command(&command)?;
+ println!("{}", cargo_run_result.output);
- if size_run_result.exit_status.success() {
- println!("{}", size_run_result.output);
+ Ok(())
+ } // _ => Err(anyhow::Error::new(TestRunError::IncompatibleCommand)),
}
-
- Ok(())
}
-
-// /// Check if lines in `output` contain `pattern` and print matching lines
-// fn print_from_output(pattern: &str, lines: &str) {
-// let lines = lines.split("\n");
-// for line in lines {
-// if line.contains(pattern) {
-// println!("{}", line);
-// }
-// }
-// }