mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +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
25
.github/workflows/ci.yaml
vendored
25
.github/workflows/ci.yaml
vendored
|
@ -56,28 +56,13 @@ jobs:
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
|
|
||||||
- name: Prepare build directory for cache (UNIX)
|
- name: Prepare cache
|
||||||
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
|
run: cargo xtask pre-cache
|
||||||
run: |
|
|
||||||
find ./target/debug -maxdepth 1 -type f -delete \
|
|
||||||
&& rm -fr ./target/debug/{deps,.fingerprint}/{*ra_*,*heavy_test*,*gen_lsp*,*thread_worker*} \
|
|
||||||
&& rm -f ./target/.rustc_info.json \
|
|
||||||
&& rm ./target/.slow_tests_cookie
|
|
||||||
|
|
||||||
- name: Prepare build directory for cache (Windows)
|
- name: Prepare cache 2
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
run: >-
|
run: Remove-Item ./target/debug/xtask.exe
|
||||||
(Get-ChildItem ./target/debug -Recurse -Depth 1 -File | Remove-Item) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/deps/*ra_*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/deps/*heavy_test*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/deps/*gen_lsp*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/deps/*thread_worker*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/.fingerprint/*ra_*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/.fingerprint/*heavy_test*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/.fingerprint/*gen_lsp*) -and
|
|
||||||
(Remove-Item -Force -Recurse ./target/debug/.fingerprint/*thread_worker*) -and
|
|
||||||
(Remove-Item -Force ./target/.rustc_info.json) -and
|
|
||||||
(Remove-Item ./target/.slow_tests_cookie)
|
|
||||||
|
|
||||||
type-script:
|
type-script:
|
||||||
name: TypeScript
|
name: TypeScript
|
||||||
|
|
|
@ -9,7 +9,7 @@ mod ast_src;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env, fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
@ -101,3 +101,41 @@ pub fn run_fuzzer() -> Result<()> {
|
||||||
|
|
||||||
run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
|
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))
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use pico_args::Arguments;
|
||||||
use xtask::{
|
use xtask::{
|
||||||
codegen::{self, Mode},
|
codegen::{self, Mode},
|
||||||
install::{ClientOpt, InstallCmd, ServerOpt},
|
install::{ClientOpt, InstallCmd, ServerOpt},
|
||||||
pre_commit, run_clippy, run_fuzzer, run_rustfmt, Result,
|
pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
@ -88,6 +88,10 @@ FLAGS:
|
||||||
args.finish()?;
|
args.finish()?;
|
||||||
run_fuzzer()
|
run_fuzzer()
|
||||||
}
|
}
|
||||||
|
"pre-cache" => {
|
||||||
|
args.finish()?;
|
||||||
|
run_pre_cache()
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"\
|
"\
|
||||||
|
|
Loading…
Reference in a new issue