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.
This commit is contained in:
bunnie 2024-05-05 16:28:33 +08:00
parent 02640db931
commit f2c877b7f7
2 changed files with 34 additions and 4 deletions

View file

@ -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<bool> {
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)
}

View file

@ -194,10 +194,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
)
.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.