|
| 1 | +use std::env; |
| 2 | +use std::{fs, process::Command}; |
| 3 | +use xtask::{EXAMPLES, HALS}; |
| 4 | + |
| 5 | +fn build_example(example: &str, target: &str, feature: Option<&str>) { |
| 6 | + println!("building `{}` for `{}`", example, target); |
| 7 | + let mut cargo = Command::new("cargo"); |
| 8 | + let toml_path = format!("examples/{}/Cargo.toml", example); |
| 9 | + cargo.args(&["build", "--target", target, "--manifest-path", &toml_path]); |
| 10 | + if let Some(feature) = feature { |
| 11 | + cargo.args(&["--features", feature]); |
| 12 | + } |
| 13 | + |
| 14 | + let status = cargo |
| 15 | + .status() |
| 16 | + .map_err(|e| format!("could not execute {:?}: {}", cargo, e)) |
| 17 | + .unwrap(); |
| 18 | + assert!( |
| 19 | + status.success(), |
| 20 | + "command exited with error status: {:?}", |
| 21 | + cargo |
| 22 | + ); |
| 23 | +} |
| 24 | + |
| 25 | +fn main() { |
| 26 | + xtask::install_targets(); |
| 27 | + |
| 28 | + // We execute from the `xtask` dir, so `cd ..` so that we can find `examples` etc. |
| 29 | + env::set_current_dir("..").unwrap(); |
| 30 | + |
| 31 | + // Build-test every HAL. |
| 32 | + for (hal, target) in HALS { |
| 33 | + let mut cargo = Command::new("cargo"); |
| 34 | + let toml_path = format!("{}/Cargo.toml", hal); |
| 35 | + let status = cargo |
| 36 | + .args(&["build", "--manifest-path", &toml_path, "--target", target]) |
| 37 | + .status() |
| 38 | + .map_err(|e| format!("could not execute {:?}: {}", cargo, e)) |
| 39 | + .unwrap(); |
| 40 | + assert!( |
| 41 | + status.success(), |
| 42 | + "command exited with error status: {:?}", |
| 43 | + cargo |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + // Build-test every example with each supported feature. |
| 48 | + for (example, features) in EXAMPLES { |
| 49 | + // Features are exclusive (they select the target chip), so we test each one |
| 50 | + // individually. |
| 51 | + if features.is_empty() { |
| 52 | + // Use a default target. |
| 53 | + build_example(example, "thumbv7em-none-eabihf", None); |
| 54 | + } else { |
| 55 | + for feature in *features { |
| 56 | + let target = xtask::feature_to_target(feature); |
| 57 | + build_example(example, target, Some(*feature)); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + // Ensure that no examples get added without an entry in EXAMPLES. |
| 63 | + for entry in fs::read_dir("examples").unwrap() { |
| 64 | + let entry = entry.unwrap(); |
| 65 | + let name = entry.file_name(); |
| 66 | + let name = name.to_str().unwrap(); |
| 67 | + |
| 68 | + if EXAMPLES |
| 69 | + .iter() |
| 70 | + .find(|(example, ..)| *example == name) |
| 71 | + .is_none() |
| 72 | + { |
| 73 | + panic!("example `{}` is missing an entry in xtask `EXAMPLES`", name); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments