aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/main.rs
diff options
context:
space:
mode:
authorEmil Fresk <emil.fresk@gmail.com>2021-12-26 10:43:57 +0100
committerEmil Fresk <emil.fresk@gmail.com>2021-12-26 11:05:35 +0100
commitef4e4aaaa3d261bda0aa46f89f2e6f8edefd202e (patch)
treec4866ab5e4d57f7bbf8108937f8a120367acef21 /xtask/src/main.rs
parentbc883e393db2e07f3519993abae0248e3584cbef (diff)
cargo xtask is now ~40x faster
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r--xtask/src/main.rs131
1 files changed, 16 insertions, 115 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index ad8719a..76ce04b 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);
-// }
-// }
-// }