Skip to content

Commit 9d1363b

Browse files
committed
fix
1 parent 240fdd0 commit 9d1363b

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
- Option `-o`(`--output-path`) let you specify output directory path
13-
- Option `ignore_groups` for optional disabling #506
1413

1514
### Changed
1615

1716
- options can be set now with `svd2rust.toml` config
17+
- option `ignore_groups` for optional disabling #506
1818
- [breaking-change] move `const_generic` from features to options
1919
- use `Config` to pass options over all render levels
2020
- Use register iterator from `svd-parser`

src/generate/device.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use proc_macro2::{Ident, Span, TokenStream};
33
use quote::{quote, ToTokens};
44
use std::fs::File;
55
use std::io::Write;
6-
use std::path::Path;
76

87
use crate::util::{self, Config, ToSanitizedUpperCase};
98
use crate::Target;
@@ -12,12 +11,7 @@ use anyhow::Result;
1211
use crate::generate::{interrupt, peripheral};
1312

1413
/// Whole device generation
15-
pub fn render(
16-
d: &Device,
17-
config: &Config,
18-
device_x: &mut String,
19-
path: impl AsRef<Path>,
20-
) -> Result<TokenStream> {
14+
pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<TokenStream> {
2115
let mut out = TokenStream::new();
2216

2317
let commit_info = {
@@ -146,7 +140,7 @@ pub fn render(
146140
let generic_file = std::str::from_utf8(include_bytes!("generic.rs"))?;
147141
if config.generic_mod {
148142
writeln!(
149-
File::create(&path.as_ref().join("generic.rs"))?,
143+
File::create(config.output_dir.join("generic.rs"))?,
150144
"{}",
151145
generic_file
152146
)?;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ pub fn generate(xml: &str, config: &Config) -> Result<Generation> {
516516
let device = svd::parse(xml)?;
517517
let mut device_x = String::new();
518518
let items =
519-
generate::device::render(&device, &config, &mut device_x, ".").or(Err(SvdError::Render))?;
519+
generate::device::render(&device, &config, &mut device_x).or(Err(SvdError::Render))?;
520520

521521
let mut lib_rs = String::new();
522522
writeln!(

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,21 @@ fn run() -> Result<()> {
148148
make_mod,
149149
const_generic,
150150
ignore_groups,
151+
output_dir: path.clone(),
151152
};
152153

153154
let mut device_x = String::new();
154-
let items = generate::device::render(&device, &config, &mut device_x, &path)?;
155+
let items = generate::device::render(&device, &config, &mut device_x)?;
155156
let filename = if make_mod { "mod.rs" } else { "lib.rs" };
156-
let mut file = File::create(&path.join(filename)).expect("Couldn't create output file");
157+
let mut file = File::create(path.join(filename)).expect("Couldn't create output file");
157158

158159
let data = items.to_string().replace("] ", "]\n");
159160
file.write_all(data.as_ref())
160161
.expect("Could not write code to lib.rs");
161162

162163
if target == Target::CortexM || target == Target::Msp430 || target == Target::XtensaLX {
163-
writeln!(File::create(&path.join("device.x"))?, "{}", device_x)?;
164-
writeln!(File::create(&path.join("build.rs"))?, "{}", build_rs())?;
164+
writeln!(File::create(path.join("device.x"))?, "{}", device_x)?;
165+
writeln!(File::create(path.join("build.rs"))?, "{}", build_rs())?;
165166
}
166167

167168
Ok(())

src/util.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::svd::{Access, Cluster, Register, RegisterCluster, RegisterInfo};
44
use inflections::Inflect;
55
use proc_macro2::{Ident, Literal, Span, TokenStream};
66
use quote::{quote, ToTokens};
7+
use std::path::PathBuf;
78

89
use anyhow::{anyhow, bail, Result};
910

@@ -13,14 +14,29 @@ pub const BITS_PER_BYTE: u32 = 8;
1314
/// that are not valid in Rust ident
1415
const BLACKLIST_CHARS: &[char] = &['(', ')', '[', ']', '/', ' ', '-'];
1516

16-
#[derive(Clone, Copy, PartialEq, Default, Debug)]
17+
#[derive(Clone, PartialEq, Debug)]
1718
pub struct Config {
1819
pub target: Target,
1920
pub nightly: bool,
2021
pub generic_mod: bool,
2122
pub make_mod: bool,
2223
pub const_generic: bool,
2324
pub ignore_groups: bool,
25+
pub output_dir: PathBuf,
26+
}
27+
28+
impl Default for Config {
29+
fn default() -> Self {
30+
Self {
31+
target: Target::default(),
32+
nightly: false,
33+
generic_mod: false,
34+
make_mod: false,
35+
const_generic: false,
36+
ignore_groups: false,
37+
output_dir: PathBuf::from("."),
38+
}
39+
}
2440
}
2541

2642
#[allow(clippy::upper_case_acronyms)]

0 commit comments

Comments
 (0)