From f2c877b7f7866bee5d9480c0e7ee6d2351d946e1 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 May 2024 16:28:33 +0800 Subject: [PATCH] add a sanity check around the aes patch because we're doing shenanigans that we shouldn't be doing, I think a sanity check on the environment is in order. --- xtask/src/builder.rs | 16 +++++++++++++--- xtask/src/main.rs | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/xtask/src/builder.rs b/xtask/src/builder.rs index 271630b13..7f0ee0561 100644 --- a/xtask/src/builder.rs +++ b/xtask/src/builder.rs @@ -1128,11 +1128,9 @@ pub fn project_root() -> PathBuf { use std::fs::File; use std::io::{self, BufRead, BufReader}; pub fn search_and_replace_in_file(filename: &str, search: &str, replace: &str) -> io::Result<()> { - // Open the file for reading let file = File::open(filename)?; let reader = BufReader::new(file); - // Read lines from the file and perform replacement let mut modified_content = String::new(); for line in reader.lines() { let line = line?; @@ -1141,9 +1139,21 @@ pub fn search_and_replace_in_file(filename: &str, search: &str, replace: &str) - modified_content.push('\n'); } - // Write the modified content back to the file let mut file = File::create(filename)?; file.write_all(modified_content.as_bytes())?; Ok(()) } + +pub fn search_in_file(filename: &str, search: &str) -> io::Result { + let file = File::open(filename)?; + let reader = BufReader::new(file); + + for line in reader.lines() { + let line = line?; + if line.contains(search) { + return Ok(true); + } + } + Ok(false) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 45f1b15d3..bafca1a78 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -194,10 +194,21 @@ fn main() -> Result<(), Box> { builder.add_global_flag("--offline"); } + // manage an ugly patch we have to do to selectively configure AES for only cramium-soc targets + match builder::search_in_file("services/aes/Cargo.toml", "default = []") { + Ok(false) => { + println!( + "Build configuration is out of sync: cramium-soc patch on AES crate was not cleared out" + ); + return Err("services/aes/Cargo.toml is in a bad state! Revert any patches to the file.".into()); + } + _ => {} + } + let mut broken_aes_cleanup = false; + // ---- now process the verb plus position dependent arguments ---- let mut args = env::args(); let task = args.nth(1); - let mut broken_aes_cleanup = false; match task.as_deref() { Some("install-toolkit") | Some("install-toolchain") => { let arg = env::args().nth(2); @@ -516,6 +527,15 @@ fn main() -> Result<(), Box> { ) .expect("couldn't patch AES"); } + match builder::search_in_file("services/aes/Cargo.toml", "default = []") { + Ok(false) => { + println!( + "Build configuration is out of sync: cramium-soc patch on AES crate was not cleared out" + ); + return Err("services/aes/Cargo.toml is in a bad state! Revert any patches to the file.".into()); + } + _ => {} + } // the intent of this call is to check that crates we are sourcing from crates.io // match the crates in our local source. The usual cause of an inconsistency is // a maintainer forgot to publish a change to crates.io.