Skip to content

Modernize svd2rust regress #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ci/svd2rust-regress/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
edition = "2018"
name = "svd2rust-regress"
version = "0.1.0"
authors = ["James Munns <[email protected]>", "The svd2rust developers"]

[dependencies]
reqwest = "0.8"
rayon = "1.0"
reqwest = "0.9"
rayon = "1.1"
structopt = "0.2"
error-chain = "0.11"
inflections = "1.1.0"
error-chain = "0.12"
inflections = "1.1"
14 changes: 4 additions & 10 deletions ci/svd2rust-regress/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#[macro_use]
extern crate error_chain;
extern crate inflections;
extern crate rayon;
extern crate reqwest;
#[macro_use]
extern crate structopt;

mod errors;
mod svd_test;
Expand Down Expand Up @@ -177,8 +172,7 @@ fn main() {
// FIXME: Use Option::filter instead when stable, rust-lang/rust#45860
if default_rustfmt
.iter()
.filter(|p| p.is_file())
.next()
.find(|p| p.is_file())
.is_none()
{
panic!("No rustfmt found");
Expand Down Expand Up @@ -265,8 +259,8 @@ fn main() {
Err(e) => {
any_fails.store(true, Ordering::Release);
let additional_info = if opt.verbose > 0 {
match e.kind() {
&errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
match *e.kind() {
errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
let mut buf = String::new();
if opt.verbose > 1 {
for stderr in previous_processes_stderr {
Expand All @@ -285,7 +279,7 @@ fn main() {
"Failed: {} - {} seconds. {}{}",
t.name(),
start.elapsed().as_secs(),
e.display_chain().to_string().trim_right(),
e.display_chain().to_string().trim_end(),
additional_info,
);
}
Expand Down
33 changes: 15 additions & 18 deletions ci/svd2rust-regress/src/svd_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use errors::*;
use crate::errors::*;
use reqwest;
use std::fs::{self, File, OpenOptions};
use std::io::prelude::*;
use std::path::PathBuf;
use std::process::{Command, Output};
use tests::TestCase;
use crate::tests::TestCase;

static CRATES_ALL: &[&str] = &["bare-metal = \"0.2.0\"", "vcell = \"0.1.0\""];
static CRATES_MSP430: &[&str] = &["msp430 = \"0.1.0\""];
Expand Down Expand Up @@ -42,7 +42,7 @@ trait CommandHelper {
name: &str,
stdout: Option<&PathBuf>,
stderr: Option<&PathBuf>,
previous_processes_stderr: &Vec<PathBuf>,
previous_processes_stderr: &[PathBuf],
) -> Result<()>;
}

Expand All @@ -53,7 +53,7 @@ impl CommandHelper for Output {
name: &str,
stdout: Option<&PathBuf>,
stderr: Option<&PathBuf>,
previous_processes_stderr: &Vec<PathBuf>,
previous_processes_stderr: &[PathBuf],
) -> Result<()> {
if let Some(out) = stdout {
let out_payload = String::from_utf8_lossy(&self.stdout);
Expand All @@ -70,7 +70,7 @@ impl CommandHelper for Output {
ErrorKind::ProcessFailed(name.into(),
stdout.cloned(),
stderr.cloned(),
previous_processes_stderr.clone(),
previous_processes_stderr.to_vec(),
).into()
);
}
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
.arg(&chip_dir)
.output()
.chain_err(|| "Failed to cargo init")?
.capture_outputs(true, "cargo init", None, None, &vec![])?;
.capture_outputs(true, "cargo init", None, None, &[])?;

// Add some crates to the Cargo.toml of our new project
let svd_toml = path_helper_base(&chip_dir, &["Cargo.toml"]);
Expand All @@ -119,7 +119,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
.open(svd_toml)
.chain_err(|| "Failed to open Cargo.toml for appending")?;

use tests::Architecture::*;
use crate::tests::Architecture::*;
let crates = CRATES_ALL
.iter()
.chain(match &t.arch {
Expand Down Expand Up @@ -154,10 +154,10 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
// If the architecture is cortex-m we move the generated lib.rs file to src/
let lib_rs_file = path_helper_base(&chip_dir, &["src", "lib.rs"]);
let svd2rust_err_file = path_helper_base(&chip_dir, &["svd2rust.err.log"]);
let target = match &t.arch {
&CortexM => "cortex-m",
&Msp430 => "msp430",
&RiscV => "riscv",
let target = match t.arch {
CortexM => "cortex-m",
Msp430 => "msp430",
RiscV => "riscv",
};
let mut svd2rust_bin = Command::new(bin_path);
if nightly {
Expand All @@ -175,16 +175,13 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
"svd2rust",
if t.arch != CortexM { Some(&lib_rs_file) } else { None }, // use Option.filter
Some(&svd2rust_err_file),
&vec![],
&[],
)?;
process_stderr_paths.push(svd2rust_err_file);

match &t.arch {
&CortexM => {
// TODO: Give error the path to stderr
fs::rename(path_helper_base(&chip_dir, &["lib.rs"]), &lib_rs_file).chain_err(|| "While moving lib.rs file")?
}
_ => (),
if let CortexM = t.arch {
// TODO: Give error the path to stderr
fs::rename(path_helper_base(&chip_dir, &["lib.rs"]), &lib_rs_file).chain_err(|| "While moving lib.rs file")?
}

let rustfmt_err_file = path_helper_base(&chip_dir, &["rustfmt.err.log"]);
Expand Down
Loading