From 23c97b545dd7d8dbee80e491269f95308707c750 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Nov 2023 17:35:49 +0100 Subject: [PATCH] Replace `xargs` command with pure Rust --- build_system/src/build.rs | 7 ++++- build_system/src/test.rs | 59 ++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/build_system/src/build.rs b/build_system/src/build.rs index 8f5c113fe319..3087a5d79e01 100644 --- a/build_system/src/build.rs +++ b/build_system/src/build.rs @@ -196,7 +196,12 @@ fn build_sysroot_inner( ) })?; run_command( - &[&"cp", &"-r", &start_dir.join("sysroot_src/library/"), &sysroot_src_path], + &[ + &"cp", + &"-r", + &start_dir.join("sysroot_src/library/"), + &sysroot_src_path, + ], None, )?; diff --git a/build_system/src/test.rs b/build_system/src/test.rs index bbe2322f93d3..12927c5d13ca 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -929,7 +929,7 @@ where fn file_handling(file: &Path) -> Result<(), String> { let path_str = file.display().to_string().replace("\\", "/"); if !path_str.ends_with(".rs") { - return Ok(()) + return Ok(()); } else if should_not_remove_test(&path_str) { return Ok(()); } else if should_remove_test(file, &path_str) { @@ -1052,18 +1052,24 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> { Some(Path::new("rust")), )?; // Putting back only the failing ones. - run_command( - &[ - &"xargs", - &"-a", - &"../failing-ui-tests.txt", - &"-d'\n'", - &"git", - &"checkout", - &"--", - ], - Some(Path::new("rust")), - )?; + let path = "failing-ui-tests.txt"; + if let Ok(files) = std::fs::read_to_string(path) { + for file in files + .split('\n') + .map(|line| line.trim()) + .filter(|line| !line.is_empty()) + { + run_command( + &[&"git", &"checkout", &"--", &file], + Some(Path::new("rust")), + )?; + } + } else { + println!( + "Failed to read `{}`, not putting back failing ui tests", + path + ); + } Ok(true) }) } @@ -1071,16 +1077,23 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> { fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> { test_rustc_inner(env, args, || { // Removing the failing tests. - run_command( - &[ - &"xargs", - &"-a", - &"../failing-ui-tests.txt", - &"-d'\n'", - &"rm", - ], - Some(Path::new("rust")), - )?; + let path = "failing-ui-tests.txt"; + if let Ok(files) = std::fs::read_to_string(path) { + for file in files + .split('\n') + .map(|line| line.trim()) + .filter(|line| !line.is_empty()) + { + let path = Path::new("rust").join(file); + std::fs::remove_file(&path) + .map_err(|error| format!("failed to remove `{}`: {:?}", path.display(), error))?; + } + } else { + println!( + "Failed to read `{}`, not putting back failing ui tests", + path + ); + } Ok(true) }) }