mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
cargo xtask is now ~40x faster
This commit is contained in:
parent
bc883e393d
commit
ef4e4aaaa3
13 changed files with 36 additions and 206 deletions
|
@ -1,4 +0,0 @@
|
||||||
init(baseline = Instant(0))
|
|
||||||
foo(baseline = Instant(0))
|
|
||||||
UART0(baseline = Instant(904))
|
|
||||||
foo(baseline = Instant(904))
|
|
|
@ -1,2 +0,0 @@
|
||||||
foo has been called 1 time
|
|
||||||
foo has been called 2 times
|
|
|
@ -1 +0,0 @@
|
||||||
received message: 42
|
|
|
@ -1 +0,0 @@
|
||||||
20000000 t ramfunc::bar::h9d6714fe5a3b0c89
|
|
|
@ -1 +0,0 @@
|
||||||
00000162 t ramfunc::foo::h30e7789b08c08e19
|
|
|
@ -1,2 +0,0 @@
|
||||||
UART1: local_to_uart1 = 1
|
|
||||||
UART0: local_to_uart0 = 1
|
|
|
@ -1,2 +0,0 @@
|
||||||
bar(2)
|
|
||||||
foo(1)
|
|
|
@ -1,9 +1,4 @@
|
||||||
use std::{
|
use std::{fs, path::Path};
|
||||||
fs,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{command::BuildMode, TestRunError};
|
|
||||||
|
|
||||||
const HEX_BUILD_ROOT: &str = "ci/builds";
|
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)
|
fs::create_dir_all(HEX_BUILD_ROOT)
|
||||||
.map_err(|_| anyhow::anyhow!("Could not create directory: {}", 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(())
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{RunResult, TestRunError};
|
use crate::{RunResult, TestRunError};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use os_pipe::pipe;
|
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)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
@ -18,32 +18,23 @@ pub enum CargoCommand<'a> {
|
||||||
features: Option<&'a str>,
|
features: Option<&'a str>,
|
||||||
mode: BuildMode,
|
mode: BuildMode,
|
||||||
},
|
},
|
||||||
Build {
|
BuildAll {
|
||||||
example: &'a str,
|
|
||||||
target: &'a str,
|
target: &'a str,
|
||||||
features: Option<&'a str>,
|
features: Option<&'a str>,
|
||||||
mode: BuildMode,
|
mode: BuildMode,
|
||||||
},
|
},
|
||||||
Objcopy {
|
// Size {
|
||||||
example: &'a str,
|
// example_paths: Vec<&'a Path>,
|
||||||
target: &'a str,
|
// },
|
||||||
features: Option<&'a str>,
|
// Clean,
|
||||||
ihex: &'a str,
|
|
||||||
},
|
|
||||||
Size {
|
|
||||||
example_paths: Vec<&'a Path>,
|
|
||||||
},
|
|
||||||
Clean,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CargoCommand<'a> {
|
impl<'a> CargoCommand<'a> {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
CargoCommand::Run { .. } => "run",
|
CargoCommand::Run { .. } => "run",
|
||||||
CargoCommand::Size { example_paths: _ } => "rust-size",
|
// CargoCommand::Size { example_paths: _ } => "rust-size",
|
||||||
CargoCommand::Clean => "clean",
|
CargoCommand::BuildAll { .. } => "build",
|
||||||
CargoCommand::Build { .. } => "build",
|
|
||||||
CargoCommand::Objcopy { .. } => "objcopy",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +45,6 @@ impl<'a> CargoCommand<'a> {
|
||||||
target,
|
target,
|
||||||
features,
|
features,
|
||||||
mode,
|
mode,
|
||||||
}
|
|
||||||
| CargoCommand::Build {
|
|
||||||
example,
|
|
||||||
target,
|
|
||||||
features,
|
|
||||||
mode,
|
|
||||||
} => {
|
} => {
|
||||||
let mut args = vec![self.name(), "--example", example, "--target", target];
|
let mut args = vec![self.name(), "--example", example, "--target", target];
|
||||||
|
|
||||||
|
@ -71,26 +56,23 @@ impl<'a> CargoCommand<'a> {
|
||||||
}
|
}
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
CargoCommand::Size { example_paths } => {
|
CargoCommand::BuildAll {
|
||||||
example_paths.iter().map(|p| p.to_str().unwrap()).collect()
|
|
||||||
}
|
|
||||||
CargoCommand::Clean => vec!["clean"],
|
|
||||||
CargoCommand::Objcopy {
|
|
||||||
example,
|
|
||||||
target,
|
target,
|
||||||
features,
|
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 {
|
if let Some(feature_name) = features {
|
||||||
args.extend_from_slice(&["--features", feature_name]);
|
args.extend_from_slice(&["--features", feature_name]);
|
||||||
}
|
}
|
||||||
|
if let Some(flag) = mode.to_flag() {
|
||||||
// this always needs to go at the end
|
args.push(flag);
|
||||||
args.extend_from_slice(&["--", "-O", "ihex", ihex]);
|
|
||||||
args
|
|
||||||
}
|
}
|
||||||
|
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:
|
// we need to cheat a little here:
|
||||||
// `cargo size` can't be ran on multiple files, so we're using `rust-size` instead –
|
// `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 :)
|
// 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",
|
_ => "cargo",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::{
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
build::{build_hexpath, compare_builds, init_build_dir},
|
build::init_build_dir,
|
||||||
command::{run_command, run_successful, BuildMode, CargoCommand},
|
command::{run_command, run_successful, BuildMode, CargoCommand},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,25 +93,6 @@ fn main() -> anyhow::Result<()> {
|
||||||
})
|
})
|
||||||
.collect();
|
.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 opts = Options::from_args();
|
||||||
let target = &opts.target;
|
let target = &opts.target;
|
||||||
|
|
||||||
|
@ -120,11 +101,9 @@ fn main() -> anyhow::Result<()> {
|
||||||
if target == "all" {
|
if target == "all" {
|
||||||
for t in targets {
|
for t in targets {
|
||||||
run_test(t, &examples)?;
|
run_test(t, &examples)?;
|
||||||
build_test(t, &examples)?;
|
|
||||||
}
|
}
|
||||||
} else if targets.contains(&target.as_str()) {
|
} else if targets.contains(&target.as_str()) {
|
||||||
run_test(&target, &examples)?;
|
run_test(&target, &examples)?;
|
||||||
build_test(&target, &examples)?;
|
|
||||||
} else {
|
} else {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"The target you specified is not available. Available targets are:\
|
"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<()> {
|
fn run_test(target: &str, examples: &[String]) -> anyhow::Result<()> {
|
||||||
|
arm_example(&CargoCommand::BuildAll {
|
||||||
|
target,
|
||||||
|
features: None,
|
||||||
|
mode: BuildMode::Release,
|
||||||
|
})?;
|
||||||
|
|
||||||
for example in examples {
|
for example in examples {
|
||||||
let cmd = CargoCommand::Run {
|
let cmd = CargoCommand::Run {
|
||||||
example,
|
example,
|
||||||
|
@ -147,37 +132,16 @@ fn run_test(target: &str, examples: &[String]) -> anyhow::Result<()> {
|
||||||
mode: BuildMode::Release,
|
mode: BuildMode::Release,
|
||||||
};
|
};
|
||||||
|
|
||||||
arm_example(&cmd, 1)?;
|
arm_example(&cmd)?;
|
||||||
|
|
||||||
arm_example(
|
|
||||||
&CargoCommand::Build {
|
|
||||||
example,
|
|
||||||
target,
|
|
||||||
features: None,
|
|
||||||
mode: BuildMode::Release,
|
|
||||||
},
|
|
||||||
1,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// run example binary `example`
|
// run example binary `example`
|
||||||
fn arm_example(command: &CargoCommand, build_num: u32) -> anyhow::Result<()> {
|
fn arm_example(command: &CargoCommand) -> anyhow::Result<()> {
|
||||||
match *command {
|
match *command {
|
||||||
CargoCommand::Run {
|
CargoCommand::Run { example, .. } => {
|
||||||
example,
|
|
||||||
target,
|
|
||||||
features,
|
|
||||||
mode,
|
|
||||||
}
|
|
||||||
| CargoCommand::Build {
|
|
||||||
example,
|
|
||||||
target,
|
|
||||||
features,
|
|
||||||
mode,
|
|
||||||
} => {
|
|
||||||
let run_file = format!("{}.run", example);
|
let run_file = format!("{}.run", example);
|
||||||
let expected_output_file = ["ci", "expected", &run_file]
|
let expected_output_file = ["ci", "expected", &run_file]
|
||||||
.iter()
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(anyhow::Error::new(TestRunError::IncompatibleCommand)),
|
CargoCommand::BuildAll { .. } => {
|
||||||
}
|
// command is either build or run
|
||||||
}
|
let cargo_run_result = run_command(&command)?;
|
||||||
|
println!("{}", cargo_run_result.output);
|
||||||
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 })?;
|
|
||||||
|
|
||||||
if size_run_result.exit_status.success() {
|
|
||||||
println!("{}", size_run_result.output);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} // _ => Err(anyhow::Error::new(TestRunError::IncompatibleCommand)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in a new issue