Share cache cleaning logic between OSes

This commit is contained in:
Aleksey Kladov 2020-01-07 16:01:41 +01:00
parent 5e7995eeb7
commit 6a7db8c701
3 changed files with 49 additions and 22 deletions

View file

@ -56,28 +56,13 @@ jobs:
with:
command: test
- name: Prepare build directory for cache (UNIX)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
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 cache
run: cargo xtask pre-cache
- name: Prepare build directory for cache (Windows)
- name: Prepare cache 2
if: matrix.os == 'windows-latest'
run: >-
(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)
run: Remove-Item ./target/debug/xtask.exe
type-script:
name: TypeScript

View file

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

View file

@ -14,7 +14,7 @@ use pico_args::Arguments;
use xtask::{
codegen::{self, Mode},
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<()> {
@ -88,6 +88,10 @@ FLAGS:
args.finish()?;
run_fuzzer()
}
"pre-cache" => {
args.finish()?;
run_pre_cache()
}
_ => {
eprintln!(
"\