From 65d2ec64db76d156f4c1cdad15cc621e99a3fc2b Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Fri, 18 Mar 2022 23:35:42 +0800 Subject: [PATCH] xtask: add --force parameter to `install-toolkit` This parameter will remove the existing toolchain and target directories, forcing a reinstall. Signed-off-by: Sean Cross --- xtask/src/main.rs | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 631716074..9196c5b3e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -166,7 +166,12 @@ fn main() -> Result<(), Box> { let kkey = args.nth(4); match task.as_deref() { Some("install-toolkit") => { - ensure_compiler(&Some(PROGRAM_TARGET), true)? + let arg = env::args().nth(2); + ensure_compiler( + &Some(PROGRAM_TARGET), + true, + arg.map(|x| x == "--force").unwrap_or(false), + )? } Some("renode-image") => { let mut args = env::args(); @@ -605,7 +610,7 @@ Various debug configurations: pddb-ci PDDB config for CI testing (eg: TRNG->deterministic for reproducible errors) ffi-test builds an image for testing C-FFI bindings and integration tts builds an image with text to speech support via externally linked C executable - install-toolkit installs Xous toolkit with no prompt, useful in CI + install-toolkit installs Xous toolkit with no prompt, useful in CI. Specify `--force` to remove existing toolchains " ) } @@ -1019,7 +1024,11 @@ static DONE_COMPILER_CHECK: std::sync::atomic::AtomicBool = /// Ensure we have a compatible compiler toolchain. We use a new Target, /// and we want to give the user a friendly way of installing the latest /// Rust toolchain. -fn ensure_compiler(target: &Option<&str>, force_install: bool) -> Result<(), String> { +fn ensure_compiler( + target: &Option<&str>, + force_install: bool, + remove_existing: bool, +) -> Result<(), String> { use std::process::Stdio; if DONE_COMPILER_CHECK.load(std::sync::atomic::Ordering::SeqCst) { return Ok(()); @@ -1083,9 +1092,31 @@ fn ensure_compiler(target: &Option<&str>, force_install: bool) -> Result<(), Str // If the sysroot exists, then we're good. let target = target.unwrap_or(PROGRAM_TARGET); - if get_sysroot(Some(target))?.is_some() { - DONE_COMPILER_CHECK.store(true, std::sync::atomic::Ordering::SeqCst); - return Ok(()); + if let Some(path) = get_sysroot(Some(target))? { + let mut version_path = PathBuf::from(&path); + version_path.push("lib"); + version_path.push("rustlib"); + version_path.push(PROGRAM_TARGET); + if remove_existing { + println!("Target path exists, removing it"); + std::fs::remove_dir_all(version_path) + .or_else(|e| Err(format!("unable to remove existing toolchain: {}", e)))?; + println!("Also removing target directories for existing toolchain"); + let mut target_main = project_root(); + target_main.push("target"); + target_main.push(PROGRAM_TARGET); + std::fs::remove_dir_all(target_main).ok(); + + let mut target_loader = project_root(); + target_loader.push("loader"); + target_loader.push("target"); + target_loader.push(PROGRAM_TARGET); + std::fs::remove_dir_all(target_loader).ok(); + + } else { + DONE_COMPILER_CHECK.store(true, std::sync::atomic::Ordering::SeqCst); + return Ok(()); + } } // Since no sysroot exists, we must download a new one. @@ -1259,7 +1290,7 @@ fn build( extra_args: Option<&[&str]>, features: Option<&[&str]>, ) -> Result { - ensure_compiler(&target, false)?; + ensure_compiler(&target, false, false)?; let stream = if debug { "debug" } else { "release" }; let mut args = vec!["build"]; print!("Building");