aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yaml25
-rw-r--r--xtask/src/lib.rs40
-rw-r--r--xtask/src/main.rs6
3 files changed, 49 insertions, 22 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index abdec602e..84c04ee72 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -56,28 +56,13 @@ jobs:
56 with: 56 with:
57 command: test 57 command: test
58 58
59 - name: Prepare build directory for cache (UNIX) 59 - name: Prepare cache
60 if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' 60 run: cargo xtask pre-cache
61 run: |
62 find ./target/debug -maxdepth 1 -type f -delete \
63 && rm -fr ./target/debug/{deps,.fingerprint}/{*ra_*,*heavy_test*,*gen_lsp*,*thread_worker*} \
64 && rm -f ./target/.rustc_info.json \
65 && rm ./target/.slow_tests_cookie
66 61
67 - name: Prepare build directory for cache (Windows) 62 - name: Prepare cache 2
68 if: matrix.os == 'windows-latest' 63 if: matrix.os == 'windows-latest'
69 run: >- 64 run: Remove-Item ./target/debug/xtask.exe
70 (Get-ChildItem ./target/debug -Recurse -Depth 1 -File | Remove-Item) -and 65
71 (Remove-Item -Force -Recurse ./target/debug/deps/*ra_*) -and
72 (Remove-Item -Force -Recurse ./target/debug/deps/*heavy_test*) -and
73 (Remove-Item -Force -Recurse ./target/debug/deps/*gen_lsp*) -and
74 (Remove-Item -Force -Recurse ./target/debug/deps/*thread_worker*) -and
75 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*ra_*) -and
76 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*heavy_test*) -and
77 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*gen_lsp*) -and
78 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*thread_worker*) -and
79 (Remove-Item -Force ./target/.rustc_info.json) -and
80 (Remove-Item ./target/.slow_tests_cookie)
81 66
82 type-script: 67 type-script:
83 name: TypeScript 68 name: TypeScript
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index b76278635..e46c21db7 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -9,7 +9,7 @@ mod ast_src;
9 9
10use anyhow::Context; 10use anyhow::Context;
11use std::{ 11use std::{
12 env, 12 env, fs,
13 path::{Path, PathBuf}, 13 path::{Path, PathBuf},
14 process::{Command, Stdio}, 14 process::{Command, Stdio},
15}; 15};
@@ -101,3 +101,41 @@ pub fn run_fuzzer() -> Result<()> {
101 101
102 run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") 102 run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
103} 103}
104
105/// Cleans the `./target` dir after the build such that only
106/// dependencies are cached on CI.
107pub fn run_pre_cache() -> Result<()> {
108 let slow_tests_cookie = Path::new("./target/.slow_tests_cookie");
109 if !slow_tests_cookie.exists() {
110 panic!("slow tests were skipped on CI!")
111 }
112 rm_rf(slow_tests_cookie)?;
113
114 for entry in Path::new("./target/debug").read_dir()? {
115 let entry = entry?;
116 if entry.file_type().map(|it| it.is_file()).ok() == Some(true) {
117 // Can't delete yourself on windows :-(
118 if !entry.path().ends_with("xtask.exe") {
119 rm_rf(&entry.path())?
120 }
121 }
122 }
123
124 fs::remove_file("./target/.rustc_info.json")?;
125 let to_delete = ["ra_", "heavy_test"];
126 for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
127 for entry in Path::new(dir).read_dir()? {
128 let entry = entry?;
129 if to_delete.iter().any(|&it| entry.path().display().to_string().contains(it)) {
130 rm_rf(&entry.path())?
131 }
132 }
133 }
134
135 Ok(())
136}
137
138fn rm_rf(path: &Path) -> Result<()> {
139 if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
140 .with_context(|| format!("failed to remove {:?}", path))
141}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 9309b2fbd..053453e6e 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -14,7 +14,7 @@ use pico_args::Arguments;
14use xtask::{ 14use xtask::{
15 codegen::{self, Mode}, 15 codegen::{self, Mode},
16 install::{ClientOpt, InstallCmd, ServerOpt}, 16 install::{ClientOpt, InstallCmd, ServerOpt},
17 pre_commit, run_clippy, run_fuzzer, run_rustfmt, Result, 17 pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result,
18}; 18};
19 19
20fn main() -> Result<()> { 20fn main() -> Result<()> {
@@ -88,6 +88,10 @@ FLAGS:
88 args.finish()?; 88 args.finish()?;
89 run_fuzzer() 89 run_fuzzer()
90 } 90 }
91 "pre-cache" => {
92 args.finish()?;
93 run_pre_cache()
94 }
91 _ => { 95 _ => {
92 eprintln!( 96 eprintln!(
93 "\ 97 "\