diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-04-29 23:51:33 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-29 23:51:33 +0200 |
| commit | 7fb74ff756a3f4b8f770df6d070ba152439a0c45 (patch) | |
| tree | 3f4156728b9929c54719b228779cc6385507b3e3 | |
| parent | 6f44d7a9dfbb1dfe503c978e2277cfc5b1b6d486 (diff) | |
stm32: rustfmt generated files in build.rs
| -rw-r--r-- | embassy-stm32/build.rs | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 49ffef217..d2b352742 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; | 1 | use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; |
| 2 | use std::fmt::Write as _; | 2 | use std::fmt::Write as _; |
| 3 | use std::path::PathBuf; | 3 | use std::io::Write; |
| 4 | use std::path::{Path, PathBuf}; | ||
| 5 | use std::process::Command; | ||
| 4 | use std::{env, fs}; | 6 | use std::{env, fs}; |
| 5 | 7 | ||
| 6 | use proc_macro2::{Ident, TokenStream}; | 8 | use proc_macro2::{Ident, TokenStream}; |
| @@ -1536,13 +1538,15 @@ fn main() { | |||
| 1536 | 1538 | ||
| 1537 | let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | 1539 | let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); |
| 1538 | let out_file = out_dir.join("_macros.rs").to_string_lossy().to_string(); | 1540 | let out_file = out_dir.join("_macros.rs").to_string_lossy().to_string(); |
| 1539 | fs::write(out_file, m).unwrap(); | 1541 | fs::write(&out_file, m).unwrap(); |
| 1542 | rustfmt(&out_file); | ||
| 1540 | 1543 | ||
| 1541 | // ======== | 1544 | // ======== |
| 1542 | // Write generated.rs | 1545 | // Write generated.rs |
| 1543 | 1546 | ||
| 1544 | let out_file = out_dir.join("_generated.rs").to_string_lossy().to_string(); | 1547 | let out_file = out_dir.join("_generated.rs").to_string_lossy().to_string(); |
| 1545 | fs::write(out_file, g.to_string()).unwrap(); | 1548 | fs::write(&out_file, g.to_string()).unwrap(); |
| 1549 | rustfmt(&out_file); | ||
| 1546 | 1550 | ||
| 1547 | // ======== | 1551 | // ======== |
| 1548 | // Multicore | 1552 | // Multicore |
| @@ -1657,3 +1661,23 @@ fn get_flash_region_type_name(name: &str) -> String { | |||
| 1657 | .replace("REGION", "Region") | 1661 | .replace("REGION", "Region") |
| 1658 | .replace('_', "") | 1662 | .replace('_', "") |
| 1659 | } | 1663 | } |
| 1664 | |||
| 1665 | /// rustfmt a given path. | ||
| 1666 | /// Failures are logged to stderr and ignored. | ||
| 1667 | fn rustfmt(path: impl AsRef<Path>) { | ||
| 1668 | let path = path.as_ref(); | ||
| 1669 | match Command::new("rustfmt").args([path]).output() { | ||
| 1670 | Err(e) => { | ||
| 1671 | eprintln!("failed to exec rustfmt {:?}: {:?}", path, e); | ||
| 1672 | } | ||
| 1673 | Ok(out) => { | ||
| 1674 | if !out.status.success() { | ||
| 1675 | eprintln!("rustfmt {:?} failed:", path); | ||
| 1676 | eprintln!("=== STDOUT:"); | ||
| 1677 | std::io::stderr().write_all(&out.stdout).unwrap(); | ||
| 1678 | eprintln!("=== STDERR:"); | ||
| 1679 | std::io::stderr().write_all(&out.stderr).unwrap(); | ||
| 1680 | } | ||
| 1681 | } | ||
| 1682 | } | ||
| 1683 | } | ||
