Skip to content

Commit f6b13f0

Browse files
committed
Updated README and improved output with verbose
1 parent b2147f1 commit f6b13f0

File tree

7 files changed

+55
-26
lines changed

7 files changed

+55
-26
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ regress:nightly:
1414
- cargo build --release
1515
- cd ci/svd2rust-regress
1616
- rm -rf ./output
17-
- cargo run --release -- --long-test
17+
- cargo run --release -- --long-test --format --verbose

ci/svd2rust-regress/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "svd2rust-regress"
33
version = "0.1.0"
4-
authors = ["James Munns <[email protected]>"]
4+
authors = ["James Munns <[email protected]>", "The svd2rust developers"]
55

66
[dependencies]
77
reqwest = "0.8"
88
rayon = "1.0"
99
structopt = "0.2"
1010
error-chain = "0.11"
11-
inflections = "1.1.0"
11+
inflections = "1.1.0"

ci/svd2rust-regress/README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
### Preconditions
1717

18-
By default, `svd2rust-regress` assumes you have already built `svd2rust` in the root of this repository in `--release` mode. If this is not possible, it is possible to specify the path to an `svd2rust` binary (see **Options** below).
18+
By default, `svd2rust-regress` assumes you have already built `svd2rust` in the root of this repository in `--release` mode.
19+
If this is not possible, it is possible to specify the path to an `svd2rust` binary (see **Options** below).
20+
21+
You'll also need to have `rustfmt` version > v0.4.0 to use the `--format` flag, you can install `rustfmt` with `rustup component add rustfmt-preview`.
1922

2023
### Output
2124

@@ -30,7 +33,7 @@ Passed: spansion_mb9af12x_k - 23 seconds
3033
Fail results look like this:
3134

3235
```text
33-
Failed: si_five_e310x - 0 seconds - Error(Msg("Process Failed! - cargo check"), State { next_error: None, backtrace: None })
36+
Failed: si_five_e310x - 0 seconds. Error: Process Failed - cargo check
3437
```
3538

3639
If all test cases passed, the return code will be `0`. If any test cases failed, the return code will be `1`.
@@ -42,24 +45,32 @@ Here are the options for running `svd2rust-regress`:
4245

4346
```text
4447
svd2rust-regress 0.1.0
45-
James Munns <[email protected]>
48+
James Munns <[email protected]>:The svd2rust developers
4649
4750
USAGE:
4851
svd2rust-regress [FLAGS] [OPTIONS]
4952
5053
FLAGS:
5154
-b, --bad-tests Include tests expected to fail (will cause a non-zero return code)
55+
-f, --format Enable formatting with `rustfmt`
5256
-h, --help Prints help information
5357
-l, --long-test Run a long test (it's very long)
5458
-V, --version Prints version information
59+
-v, --verbose Use verbose output
5560
5661
OPTIONS:
57-
-a, --architecture <arch> Filter by architecture, case sensitive, may be combined with other filters Options
58-
are: "CortexM", "RiscV", and "Msp430"
59-
-p, --svd2rust-path <bin_path> Path to an `svd2rust` binary, relative or absolute. Defaults to
60-
`target/release/svd2rust[.exe]` of this repository (which must be already built)
61-
-c, --chip <chip> Filter by chip name, case sensitive, may be combined with other filters
62-
-m, --manufacturer <mfgr> Filter by manufacturer, case sensitive, may be combined with other filters
62+
-a, --architecture <arch>
63+
Filter by architecture, case sensitive, may be combined with other filters Options are: "CortexM", "RiscV",
64+
and "Msp430"
65+
-p, --svd2rust-path <bin_path>
66+
Path to an `svd2rust` binary, relative or absolute. Defaults to `target/release/svd2rust[.exe]` of this
67+
repository (which must be already built)
68+
-c, --chip <chip> Filter by chip name, case sensitive, may be combined with other filters
69+
-m, --manufacturer <mfgr>
70+
Filter by manufacturer, case sensitive, may be combined with other filters
71+
72+
--rustfmt_bin_path <rustfmt_bin_path>
73+
Path to an `rustfmt` binary, relative or absolute. Defaults to `$(rustup which rustfmt)`
6374
```
6475

6576
### Filters
@@ -92,4 +103,6 @@ cargo run --release -- --long-test -c MB9AF12xK -m Fujitsu
92103
Finished release [optimized] target(s) in 0.0 secs
93104
Running `target/release/svd2rust-regress --long-test -c MB9AF12xK -m Fujitsu`
94105
Passed: fujitsu_mb9af12x_k - 19 seconds
95-
```
106+
```
107+
108+
Note that you may have to pass `--long-test` to enable some chips as they are known to take a long time to compile.

ci/svd2rust-regress/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::path;
1+
use std::path::PathBuf;
22
error_chain!{
33
errors {
4-
ProcessFailed(command: String, stderr: Option<path::PathBuf>, stdout: Option<path::PathBuf>) {
4+
ProcessFailed(command: String, stderr: Option<PathBuf>, stdout: Option<PathBuf>) {
55
description("Process Failed")
66
display("Process Failed - {}", command)
77
}

ci/svd2rust-regress/src/main.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ mod errors;
1010
mod svd_test;
1111
mod tests;
1212

13+
use error_chain::ChainedError;
1314
use rayon::prelude::*;
15+
use std::fs::File;
16+
use std::io::Read;
1417
use std::path::PathBuf;
1518
use std::process::{exit, Command};
1619
use std::sync::atomic::{AtomicBool, Ordering};
1720
use std::time::Instant;
18-
use std::fs::File;
19-
use std::io::Read;
2021
use structopt::StructOpt;
2122

2223
#[derive(StructOpt, Debug)]
@@ -122,8 +123,14 @@ fn main() {
122123
(_, false) => None,
123124
(&Some(ref path), true) => Some(path),
124125
(&None, true) => {
125-
if default_rustfmt.is_none() {
126-
eprintln!("Warning: No rustfmt found, formatting will be skipped")
126+
// FIXME: Use Option::filter instead when stable, rust-lang/rust#45860
127+
if default_rustfmt
128+
.iter()
129+
.filter(|p| p.is_file())
130+
.next()
131+
.is_none()
132+
{
133+
panic!("No rustfmt found");
127134
}
128135
default_rustfmt.as_ref()
129136
}
@@ -181,22 +188,28 @@ fn main() {
181188
any_fails.store(true, Ordering::Release);
182189
let additional_info = if opt.verbose > 0 {
183190
match e.kind() {
184-
&errors::ErrorKind::ProcessFailed(ref command, _, ref stderr) if command == "cargo check" => {
191+
&errors::ErrorKind::ProcessFailed(ref command, _, Some(ref stderr))
192+
if command == "cargo check" =>
193+
{
185194
let mut buf = String::new();
186195
// Unwrap is safe
187-
File::open(stderr.as_ref().unwrap()).expect("Couldn't open file").read_to_string(&mut buf).expect("Couldn't read file to string");
196+
File::open(stderr)
197+
.expect("Couldn't open file")
198+
.read_to_string(&mut buf)
199+
.expect("Couldn't read file to string");
200+
buf.insert_str(0, &format!("\n---{:?}---\n", stderr.as_os_str()));
188201
buf
189202
}
190-
_ => "".into()
203+
_ => "".into(),
191204
}
192205
} else {
193206
"".into()
194207
};
195208
eprintln!(
196-
"Failed: {} - {} seconds - {}{}",
209+
"Failed: {} - {} seconds. {}{}",
197210
t.name(),
198211
start.elapsed().as_secs(),
199-
e,
212+
e.display_chain().to_string().trim_right(),
200213
additional_info,
201214
);
202215
}

ci/svd2rust-regress/src/svd_test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ impl CommandHelper for Output {
6161
};
6262

6363
if cant_fail && !self.status.success() {
64-
return Err(ErrorKind::ProcessFailed(name.into(), stdout.cloned(), stderr.cloned()).into())
64+
return Err(
65+
ErrorKind::ProcessFailed(name.into(), stdout.cloned(), stderr.cloned()).into(),
66+
);
6567
}
6668

6769
Ok(())
@@ -134,6 +136,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
134136
&Msp430 => "msp430",
135137
&RiscV => "riscv",
136138
};
139+
137140
Command::new(bin_path)
138141
.args(&["-i", &chip_svd])
139142
.args(&["--target", &target])

ci/svd2rust-regress/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use self::RunWhen::*;
7676
/// that are not valid in Rust ident
7777
const BLACKLIST_CHARS: &'static [char] = &['(', ')', '[', ']'];
7878

79-
/// Lovingly stolen from `svd2rust`. Probably could be `Cow`, but I'm lazy
79+
/// Lovingly stolen from `svd2rust`. Probably could be `Cow`
8080
pub trait ToSanitizedSnakeCase {
8181
fn to_sanitized_snake_case(&self) -> String;
8282
}

0 commit comments

Comments
 (0)