diff options
-rw-r--r-- | crates/rust-analyzer/tests/rust-analyzer/main.rs (renamed from crates/rust-analyzer/tests/heavy_tests/main.rs) | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/rust-analyzer/support.rs (renamed from crates/rust-analyzer/tests/heavy_tests/support.rs) | 0 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/rust-analyzer/testdir.rs (renamed from crates/rust-analyzer/tests/heavy_tests/testdir.rs) | 0 | ||||
-rw-r--r-- | xtask/src/lib.rs | 45 | ||||
-rw-r--r-- | xtask/src/main.rs | 5 | ||||
-rw-r--r-- | xtask/src/pre_cache.rs | 80 |
6 files changed, 98 insertions, 42 deletions
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/rust-analyzer/main.rs index 7370505f8..fa315ff8e 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/main.rs | |||
@@ -1,3 +1,13 @@ | |||
1 | //! The most high-level integrated tests for rust-analyzer. | ||
2 | //! | ||
3 | //! This tests run a full LSP event loop, spawn cargo and process stdlib from | ||
4 | //! sysroot. For this reason, the tests here are very slow, and should be | ||
5 | //! avoided unless absolutely necessary. | ||
6 | //! | ||
7 | //! In particular, it's fine *not* to test that client & server agree on | ||
8 | //! specific JSON shapes here -- there's little value in such tests, as we can't | ||
9 | //! be sure without a real client anyway. | ||
10 | |||
1 | mod testdir; | 11 | mod testdir; |
2 | mod support; | 12 | mod support; |
3 | 13 | ||
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs index 5bafeba79..5bafeba79 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs | |||
diff --git a/crates/rust-analyzer/tests/heavy_tests/testdir.rs b/crates/rust-analyzer/tests/rust-analyzer/testdir.rs index 7487e7429..7487e7429 100644 --- a/crates/rust-analyzer/tests/heavy_tests/testdir.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/testdir.rs | |||
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index f3ad81ba7..e790d995f 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -3,14 +3,15 @@ | |||
3 | //! See https://github.com/matklad/cargo-xtask/ | 3 | //! See https://github.com/matklad/cargo-xtask/ |
4 | 4 | ||
5 | pub mod not_bash; | 5 | pub mod not_bash; |
6 | pub mod codegen; | ||
7 | mod ast_src; | ||
8 | |||
6 | pub mod install; | 9 | pub mod install; |
7 | pub mod release; | 10 | pub mod release; |
8 | pub mod dist; | 11 | pub mod dist; |
9 | pub mod pre_commit; | 12 | pub mod pre_commit; |
10 | pub mod metrics; | 13 | pub mod metrics; |
11 | 14 | pub mod pre_cache; | |
12 | pub mod codegen; | ||
13 | mod ast_src; | ||
14 | 15 | ||
15 | use std::{ | 16 | use std::{ |
16 | env, | 17 | env, |
@@ -21,7 +22,7 @@ use walkdir::{DirEntry, WalkDir}; | |||
21 | 22 | ||
22 | use crate::{ | 23 | use crate::{ |
23 | codegen::Mode, | 24 | codegen::Mode, |
24 | not_bash::{fs2, pushd, pushenv, rm_rf}, | 25 | not_bash::{pushd, pushenv}, |
25 | }; | 26 | }; |
26 | 27 | ||
27 | pub use anyhow::{bail, Context as _, Result}; | 28 | pub use anyhow::{bail, Context as _, Result}; |
@@ -108,42 +109,6 @@ pub fn run_fuzzer() -> Result<()> { | |||
108 | Ok(()) | 109 | Ok(()) |
109 | } | 110 | } |
110 | 111 | ||
111 | /// Cleans the `./target` dir after the build such that only | ||
112 | /// dependencies are cached on CI. | ||
113 | pub fn run_pre_cache() -> Result<()> { | ||
114 | let slow_tests_cookie = Path::new("./target/.slow_tests_cookie"); | ||
115 | if !slow_tests_cookie.exists() { | ||
116 | panic!("slow tests were skipped on CI!") | ||
117 | } | ||
118 | rm_rf(slow_tests_cookie)?; | ||
119 | |||
120 | for entry in Path::new("./target/debug").read_dir()? { | ||
121 | let entry = entry?; | ||
122 | if entry.file_type().map(|it| it.is_file()).ok() == Some(true) { | ||
123 | // Can't delete yourself on windows :-( | ||
124 | if !entry.path().ends_with("xtask.exe") { | ||
125 | rm_rf(&entry.path())? | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | |||
130 | fs2::remove_file("./target/.rustc_info.json")?; | ||
131 | let to_delete = ["hir", "heavy_test", "xtask", "ide", "rust-analyzer"]; | ||
132 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { | ||
133 | for entry in Path::new(dir).read_dir()? { | ||
134 | let entry = entry?; | ||
135 | if to_delete.iter().any(|&it| entry.path().display().to_string().contains(it)) { | ||
136 | // Can't delete yourself on windows :-( | ||
137 | if !entry.path().ends_with("xtask.exe") { | ||
138 | rm_rf(&entry.path())? | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | Ok(()) | ||
145 | } | ||
146 | |||
147 | fn is_release_tag(tag: &str) -> bool { | 112 | fn is_release_tag(tag: &str) -> bool { |
148 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) | 113 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) |
149 | } | 114 | } |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b69b884e5..fb38fdc92 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -17,9 +17,10 @@ use xtask::{ | |||
17 | install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, | 17 | install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, |
18 | metrics::MetricsCmd, | 18 | metrics::MetricsCmd, |
19 | not_bash::pushd, | 19 | not_bash::pushd, |
20 | pre_cache::PreCacheCmd, | ||
20 | pre_commit, project_root, | 21 | pre_commit, project_root, |
21 | release::{PromoteCmd, ReleaseCmd}, | 22 | release::{PromoteCmd, ReleaseCmd}, |
22 | run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result, | 23 | run_clippy, run_fuzzer, run_rustfmt, Result, |
23 | }; | 24 | }; |
24 | 25 | ||
25 | fn main() -> Result<()> { | 26 | fn main() -> Result<()> { |
@@ -100,7 +101,7 @@ FLAGS: | |||
100 | } | 101 | } |
101 | "pre-cache" => { | 102 | "pre-cache" => { |
102 | args.finish()?; | 103 | args.finish()?; |
103 | run_pre_cache() | 104 | PreCacheCmd.run() |
104 | } | 105 | } |
105 | "release" => { | 106 | "release" => { |
106 | let dry_run = args.contains("--dry-run"); | 107 | let dry_run = args.contains("--dry-run"); |
diff --git a/xtask/src/pre_cache.rs b/xtask/src/pre_cache.rs new file mode 100644 index 000000000..47ba6ba24 --- /dev/null +++ b/xtask/src/pre_cache.rs | |||
@@ -0,0 +1,80 @@ | |||
1 | use std::{ | ||
2 | fs::FileType, | ||
3 | path::{Path, PathBuf}, | ||
4 | }; | ||
5 | |||
6 | use anyhow::Result; | ||
7 | |||
8 | use crate::not_bash::{fs2, rm_rf}; | ||
9 | |||
10 | pub struct PreCacheCmd; | ||
11 | |||
12 | impl PreCacheCmd { | ||
13 | /// Cleans the `./target` dir after the build such that only | ||
14 | /// dependencies are cached on CI. | ||
15 | pub fn run(self) -> Result<()> { | ||
16 | let slow_tests_cookie = Path::new("./target/.slow_tests_cookie"); | ||
17 | if !slow_tests_cookie.exists() { | ||
18 | panic!("slow tests were skipped on CI!") | ||
19 | } | ||
20 | rm_rf(slow_tests_cookie)?; | ||
21 | |||
22 | for path in read_dir("./target/debug", FileType::is_file)? { | ||
23 | // Can't delete yourself on windows :-( | ||
24 | if !path.ends_with("xtask.exe") { | ||
25 | rm_rf(&path)? | ||
26 | } | ||
27 | } | ||
28 | |||
29 | fs2::remove_file("./target/.rustc_info.json")?; | ||
30 | |||
31 | let to_delete = read_dir("./crates", FileType::is_dir)? | ||
32 | .into_iter() | ||
33 | .map(|path| path.file_name().unwrap().to_string_lossy().replace('-', "_")) | ||
34 | .collect::<Vec<_>>(); | ||
35 | |||
36 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { | ||
37 | for path in read_dir(dir, |_file_type| true)? { | ||
38 | if path.ends_with("xtask.exe") { | ||
39 | continue; | ||
40 | } | ||
41 | let file_name = path.file_name().unwrap().to_string_lossy(); | ||
42 | let (stem, _) = match rsplit_once(&file_name, '-') { | ||
43 | Some(it) => it, | ||
44 | None => { | ||
45 | rm_rf(path)?; | ||
46 | continue; | ||
47 | } | ||
48 | }; | ||
49 | let stem = stem.replace('-', "_"); | ||
50 | if to_delete.contains(&stem) { | ||
51 | rm_rf(path)?; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | Ok(()) | ||
57 | } | ||
58 | } | ||
59 | fn read_dir(path: impl AsRef<Path>, cond: impl Fn(&FileType) -> bool) -> Result<Vec<PathBuf>> { | ||
60 | read_dir_impl(path.as_ref(), &cond) | ||
61 | } | ||
62 | |||
63 | fn read_dir_impl(path: &Path, cond: &dyn Fn(&FileType) -> bool) -> Result<Vec<PathBuf>> { | ||
64 | let mut res = Vec::new(); | ||
65 | for entry in path.read_dir()? { | ||
66 | let entry = entry?; | ||
67 | let file_type = entry.file_type()?; | ||
68 | if cond(&file_type) { | ||
69 | res.push(entry.path()) | ||
70 | } | ||
71 | } | ||
72 | Ok(res) | ||
73 | } | ||
74 | |||
75 | fn rsplit_once(haystack: &str, delim: char) -> Option<(&str, &str)> { | ||
76 | let mut split = haystack.rsplitn(2, delim); | ||
77 | let suffix = split.next()?; | ||
78 | let prefix = split.next()?; | ||
79 | Some((prefix, suffix)) | ||
80 | } | ||