mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Share cache cleaning logic between OSes
This commit is contained in:
parent
5e7995eeb7
commit
6a7db8c701
3 changed files with 49 additions and 22 deletions
|
@ -9,7 +9,7 @@ mod ast_src;
|
|||
|
||||
use anyhow::Context;
|
||||
use std::{
|
||||
env,
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
@ -101,3 +101,41 @@ pub fn run_fuzzer() -> Result<()> {
|
|||
|
||||
run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
|
||||
}
|
||||
|
||||
/// Cleans the `./target` dir after the build such that only
|
||||
/// dependencies are cached on CI.
|
||||
pub fn run_pre_cache() -> Result<()> {
|
||||
let slow_tests_cookie = Path::new("./target/.slow_tests_cookie");
|
||||
if !slow_tests_cookie.exists() {
|
||||
panic!("slow tests were skipped on CI!")
|
||||
}
|
||||
rm_rf(slow_tests_cookie)?;
|
||||
|
||||
for entry in Path::new("./target/debug").read_dir()? {
|
||||
let entry = entry?;
|
||||
if entry.file_type().map(|it| it.is_file()).ok() == Some(true) {
|
||||
// Can't delete yourself on windows :-(
|
||||
if !entry.path().ends_with("xtask.exe") {
|
||||
rm_rf(&entry.path())?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs::remove_file("./target/.rustc_info.json")?;
|
||||
let to_delete = ["ra_", "heavy_test"];
|
||||
for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
|
||||
for entry in Path::new(dir).read_dir()? {
|
||||
let entry = entry?;
|
||||
if to_delete.iter().any(|&it| entry.path().display().to_string().contains(it)) {
|
||||
rm_rf(&entry.path())?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rm_rf(path: &Path) -> Result<()> {
|
||||
if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
|
||||
.with_context(|| format!("failed to remove {:?}", path))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue