|
1 | 1 | #![recursion_limit = "128"]
|
2 | 2 |
|
3 | 3 | use log::error;
|
| 4 | +use std::path::PathBuf; |
4 | 5 | use svd_parser as svd;
|
5 | 6 |
|
6 | 7 | mod generate;
|
@@ -29,8 +30,17 @@ fn run() -> Result<()> {
|
29 | 30 | .takes_value(true)
|
30 | 31 | .value_name("FILE"),
|
31 | 32 | )
|
| 33 | + .arg( |
| 34 | + Arg::with_name("output") |
| 35 | + .long("output-dir") |
| 36 | + .help("Directory to place generated files") |
| 37 | + .short("o") |
| 38 | + .takes_value(true) |
| 39 | + .value_name("PATH"), |
| 40 | + ) |
32 | 41 | .arg(
|
33 | 42 | Arg::with_name("config")
|
| 43 | + .long("config") |
34 | 44 | .help("Config TOML file")
|
35 | 45 | .short("c")
|
36 | 46 | .takes_value(true)
|
@@ -102,6 +112,8 @@ fn run() -> Result<()> {
|
102 | 112 | }
|
103 | 113 | }
|
104 | 114 |
|
| 115 | + let path = PathBuf::from(matches.value_of("output").unwrap_or(".")); |
| 116 | + |
105 | 117 | let config_filename = matches.value_of("config").unwrap_or("");
|
106 | 118 |
|
107 | 119 | let cfg = with_toml_env(&matches, &[config_filename, "svd2rust.toml"]);
|
@@ -136,20 +148,21 @@ fn run() -> Result<()> {
|
136 | 148 | make_mod,
|
137 | 149 | const_generic,
|
138 | 150 | ignore_groups,
|
| 151 | + output_dir: path.clone(), |
139 | 152 | };
|
140 | 153 |
|
141 | 154 | let mut device_x = String::new();
|
142 | 155 | let items = generate::device::render(&device, &config, &mut device_x)?;
|
143 | 156 | let filename = if make_mod { "mod.rs" } else { "lib.rs" };
|
144 |
| - let mut file = File::create(filename).expect("Couldn't create output file"); |
| 157 | + let mut file = File::create(path.join(filename)).expect("Couldn't create output file"); |
145 | 158 |
|
146 | 159 | let data = items.to_string().replace("] ", "]\n");
|
147 | 160 | file.write_all(data.as_ref())
|
148 | 161 | .expect("Could not write code to lib.rs");
|
149 | 162 |
|
150 | 163 | if target == Target::CortexM || target == Target::Msp430 || target == Target::XtensaLX {
|
151 |
| - writeln!(File::create("device.x")?, "{}", device_x)?; |
152 |
| - writeln!(File::create("build.rs")?, "{}", build_rs())?; |
| 164 | + writeln!(File::create(path.join("device.x"))?, "{}", device_x)?; |
| 165 | + writeln!(File::create(path.join("build.rs"))?, "{}", build_rs())?; |
153 | 166 | }
|
154 | 167 |
|
155 | 168 | Ok(())
|
|
0 commit comments