Skip to content

Commit c79b4cd

Browse files
Merge #344 #346
344: Join the bits muching into a single line to improve dev builds r=adamgreig a=therealprof Also this rectifies many of the tons of https://rust-lang.github.io/rust-clippy/master/index.html#identity_op lints we're getting. Signed-off-by: Daniel Egger <[email protected]> 346: Modernize svd2rust regress r=adamgreig a=therealprof A series of patches to bring it a bit more up-to-date. Includes: * making it Edition-2018 * bumping a few dependencies * fixing all clippy lints * changing to the master branch (instead of the ghost branch python-0.4 which can only be found by GitHub somehow) of the `cmsis-svd` repository * allowing `cargo init` on weirdly named SVD files * fixed NXP company name so SVD files can actually be downloaded * weeded out old STM SVD filenames and added some new ones Co-authored-by: Daniel Egger <[email protected]>
3 parents 59ef3dc + bb73dfe + 0637dc0 commit c79b4cd

File tree

6 files changed

+222
-90
lines changed

6 files changed

+222
-90
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Changed
1515

1616
- Break ultra-long single line output into multiple lines for better usability
17+
- Joined field write proxy into a single line to help dev builds
18+
- Elimated useless 0 shifts to reduce generated code size and fix a clippy lint
1719

1820
### Fixed
1921

ci/svd2rust-regress/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[package]
2+
edition = "2018"
23
name = "svd2rust-regress"
34
version = "0.1.0"
45
authors = ["James Munns <[email protected]>", "The svd2rust developers"]
56

67
[dependencies]
7-
reqwest = "0.8"
8-
rayon = "1.0"
8+
reqwest = "0.9"
9+
rayon = "1.1"
910
structopt = "0.2"
10-
error-chain = "0.11"
11-
inflections = "1.1.0"
11+
error-chain = "0.12"
12+
inflections = "1.1"

ci/svd2rust-regress/src/main.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#[macro_use]
22
extern crate error_chain;
3-
extern crate inflections;
4-
extern crate rayon;
5-
extern crate reqwest;
6-
#[macro_use]
7-
extern crate structopt;
83

94
mod errors;
105
mod svd_test;
@@ -177,8 +172,7 @@ fn main() {
177172
// FIXME: Use Option::filter instead when stable, rust-lang/rust#45860
178173
if default_rustfmt
179174
.iter()
180-
.filter(|p| p.is_file())
181-
.next()
175+
.find(|p| p.is_file())
182176
.is_none()
183177
{
184178
panic!("No rustfmt found");
@@ -265,8 +259,8 @@ fn main() {
265259
Err(e) => {
266260
any_fails.store(true, Ordering::Release);
267261
let additional_info = if opt.verbose > 0 {
268-
match e.kind() {
269-
&errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
262+
match *e.kind() {
263+
errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
270264
let mut buf = String::new();
271265
if opt.verbose > 1 {
272266
for stderr in previous_processes_stderr {
@@ -285,7 +279,7 @@ fn main() {
285279
"Failed: {} - {} seconds. {}{}",
286280
t.name(),
287281
start.elapsed().as_secs(),
288-
e.display_chain().to_string().trim_right(),
282+
e.display_chain().to_string().trim_end(),
289283
additional_info,
290284
);
291285
}

ci/svd2rust-regress/src/svd_test.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use errors::*;
1+
use crate::errors::*;
22
use reqwest;
33
use std::fs::{self, File, OpenOptions};
44
use std::io::prelude::*;
55
use std::path::PathBuf;
66
use std::process::{Command, Output};
7-
use tests::TestCase;
7+
use crate::tests::TestCase;
88

99
static CRATES_ALL: &[&str] = &["bare-metal = \"0.2.0\"", "vcell = \"0.1.0\""];
1010
static CRATES_MSP430: &[&str] = &["msp430 = \"0.1.0\""];
@@ -42,7 +42,7 @@ trait CommandHelper {
4242
name: &str,
4343
stdout: Option<&PathBuf>,
4444
stderr: Option<&PathBuf>,
45-
previous_processes_stderr: &Vec<PathBuf>,
45+
previous_processes_stderr: &[PathBuf],
4646
) -> Result<()>;
4747
}
4848

@@ -53,7 +53,7 @@ impl CommandHelper for Output {
5353
name: &str,
5454
stdout: Option<&PathBuf>,
5555
stderr: Option<&PathBuf>,
56-
previous_processes_stderr: &Vec<PathBuf>,
56+
previous_processes_stderr: &[PathBuf],
5757
) -> Result<()> {
5858
if let Some(out) = stdout {
5959
let out_payload = String::from_utf8_lossy(&self.stdout);
@@ -70,7 +70,7 @@ impl CommandHelper for Output {
7070
ErrorKind::ProcessFailed(name.into(),
7171
stdout.cloned(),
7272
stderr.cloned(),
73-
previous_processes_stderr.clone(),
73+
previous_processes_stderr.to_vec(),
7474
).into()
7575
);
7676
}
@@ -109,7 +109,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
109109
.arg(&chip_dir)
110110
.output()
111111
.chain_err(|| "Failed to cargo init")?
112-
.capture_outputs(true, "cargo init", None, None, &vec![])?;
112+
.capture_outputs(true, "cargo init", None, None, &[])?;
113113

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

122-
use tests::Architecture::*;
122+
use crate::tests::Architecture::*;
123123
let crates = CRATES_ALL
124124
.iter()
125125
.chain(match &t.arch {
@@ -154,10 +154,10 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
154154
// If the architecture is cortex-m we move the generated lib.rs file to src/
155155
let lib_rs_file = path_helper_base(&chip_dir, &["src", "lib.rs"]);
156156
let svd2rust_err_file = path_helper_base(&chip_dir, &["svd2rust.err.log"]);
157-
let target = match &t.arch {
158-
&CortexM => "cortex-m",
159-
&Msp430 => "msp430",
160-
&RiscV => "riscv",
157+
let target = match t.arch {
158+
CortexM => "cortex-m",
159+
Msp430 => "msp430",
160+
RiscV => "riscv",
161161
};
162162
let mut svd2rust_bin = Command::new(bin_path);
163163
if nightly {
@@ -175,16 +175,13 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
175175
"svd2rust",
176176
if t.arch != CortexM { Some(&lib_rs_file) } else { None }, // use Option.filter
177177
Some(&svd2rust_err_file),
178-
&vec![],
178+
&[],
179179
)?;
180180
process_stderr_paths.push(svd2rust_err_file);
181181

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

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

0 commit comments

Comments
 (0)