Skip to content

Commit 6f346c9

Browse files
committed
Re-implement tidy as an xtask action
1 parent d00f474 commit 6f346c9

File tree

12 files changed

+69
-60
lines changed

12 files changed

+69
-60
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ fn floating_point() {
426426
true,
427427
)),
428428
);
429-
#[allow(unknown_lints, unnecessary_min_or_max)]
429+
#[allow(unknown_lints, clippy::unnecessary_min_or_max)]
430430
check_number(
431431
r#"
432432
extern "rust-intrinsic" {

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
#![allow(clippy::disallowed_types)]
1212

1313
mod ratoml;
14-
#[cfg(not(feature = "in-rust-tree"))]
15-
mod sourcegen;
1614
mod support;
1715
mod testdir;
18-
mod tidy;
1916

2017
use std::{collections::HashMap, path::PathBuf, time::Instant};
2118

src/tools/rust-analyzer/xtask/src/codegen.rs

-30
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,6 @@ impl flags::Codegen {
3939
}
4040
}
4141

42-
fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
43-
let mut res = list_files(dir);
44-
res.retain(|it| {
45-
it.file_name().unwrap_or_default().to_str().unwrap_or_default().ends_with(".rs")
46-
});
47-
res
48-
}
49-
50-
fn list_files(dir: &Path) -> Vec<PathBuf> {
51-
let mut res = Vec::new();
52-
let mut work = vec![dir.to_path_buf()];
53-
while let Some(dir) = work.pop() {
54-
for entry in dir.read_dir().unwrap() {
55-
let entry = entry.unwrap();
56-
let file_type = entry.file_type().unwrap();
57-
let path = entry.path();
58-
let is_hidden =
59-
path.file_name().unwrap_or_default().to_str().unwrap_or_default().starts_with('.');
60-
if !is_hidden {
61-
if file_type.is_dir() {
62-
work.push(path);
63-
} else if file_type.is_file() {
64-
res.push(path);
65-
}
66-
}
67-
}
68-
}
69-
res
70-
}
71-
7242
#[derive(Clone)]
7343
pub(crate) struct CommentBlock {
7444
pub(crate) id: String,

src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use std::{fmt, fs, path::Path};
55
use stdx::format_to_acc;
66

77
use crate::{
8-
codegen::{
9-
add_preamble, ensure_file_contents, list_rust_files, reformat, CommentBlock, Location,
10-
},
8+
codegen::{add_preamble, ensure_file_contents, reformat, CommentBlock, Location},
119
project_root,
10+
util::list_rust_files,
1211
};
1312

1413
pub(crate) fn generate(check: bool) {

src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use std::{fmt, fs, io, path::PathBuf};
44

55
use crate::{
6-
codegen::{add_preamble, list_rust_files, CommentBlock, Location},
6+
codegen::{add_preamble, CommentBlock, Location},
77
project_root,
8+
util::list_rust_files,
89
};
910

1011
pub(crate) fn generate(check: bool) {

src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use std::{fmt, fs, io, path::PathBuf};
44

55
use crate::{
6-
codegen::{list_rust_files, CommentBlock, Location},
6+
codegen::{CommentBlock, Location},
77
project_root,
8+
util::list_rust_files,
89
};
910

1011
pub(crate) fn generate(_check: bool) {

src/tools/rust-analyzer/xtask/src/codegen/lints.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use stdx::format_to;
66
use xshell::{cmd, Shell};
77

88
use crate::{
9-
codegen::{add_preamble, ensure_file_contents, list_files, reformat},
9+
codegen::{add_preamble, ensure_file_contents, reformat},
1010
project_root,
11+
util::list_files,
1112
};
1213

1314
const DESTINATION: &str = "crates/ide-db/src/generated/lints.rs";

src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use std::{
99
};
1010

1111
use crate::{
12-
codegen::{ensure_file_contents, list_rust_files, CommentBlock},
12+
codegen::{ensure_file_contents, CommentBlock},
1313
project_root,
14+
util::list_rust_files,
1415
};
1516

1617
pub(crate) fn generate(check: bool) {

src/tools/rust-analyzer/xtask/src/flags.rs

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ xflags::xflags! {
7373
optional codegen_type: CodegenType
7474
optional --check
7575
}
76+
77+
cmd tidy {}
7678
}
7779
}
7880

@@ -96,8 +98,12 @@ pub enum XtaskCmd {
9698
Metrics(Metrics),
9799
Bb(Bb),
98100
Codegen(Codegen),
101+
Tidy(Tidy),
99102
}
100103

104+
#[derive(Debug)]
105+
pub struct Tidy {}
106+
101107
#[derive(Debug)]
102108
pub struct Install {
103109
pub client: bool,

src/tools/rust-analyzer/xtask/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod install;
1919
mod metrics;
2020
mod publish;
2121
mod release;
22+
mod tidy;
23+
mod util;
2224

2325
use anyhow::bail;
2426
use std::{env, path::PathBuf};
@@ -51,6 +53,7 @@ fn main() -> anyhow::Result<()> {
5153
)?;
5254
Ok(())
5355
}
56+
flags::XtaskCmd::Tidy(cmd) => cmd.run(sh),
5457
}
5558
}
5659

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs renamed to src/tools/rust-analyzer/xtask/src/tidy.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@ use std::{
66

77
use xshell::Shell;
88

9-
#[cfg(not(feature = "in-rust-tree"))]
109
use xshell::cmd;
1110

12-
#[test]
13-
fn check_lsp_extensions_docs() {
14-
let sh = &Shell::new().unwrap();
11+
use crate::{flags::Tidy, project_root, util::list_files};
1512

13+
impl Tidy {
14+
pub(crate) fn run(&self, sh: &Shell) -> anyhow::Result<()> {
15+
check_lsp_extensions_docs(sh);
16+
files_are_tidy(sh);
17+
check_licenses(sh);
18+
Ok(())
19+
}
20+
}
21+
22+
fn check_lsp_extensions_docs(sh: &Shell) {
1623
let expected_hash = {
17-
let lsp_ext_rs = sh
18-
.read_file(sourcegen::project_root().join("crates/rust-analyzer/src/lsp/ext.rs"))
19-
.unwrap();
24+
let lsp_ext_rs =
25+
sh.read_file(project_root().join("crates/rust-analyzer/src/lsp/ext.rs")).unwrap();
2026
stable_hash(lsp_ext_rs.as_str())
2127
};
2228

2329
let actual_hash = {
2430
let lsp_extensions_md =
25-
sh.read_file(sourcegen::project_root().join("docs/dev/lsp-extensions.md")).unwrap();
31+
sh.read_file(project_root().join("docs/dev/lsp-extensions.md")).unwrap();
2632
let text = lsp_extensions_md
2733
.lines()
2834
.find_map(|line| line.strip_prefix("lsp/ext.rs hash:"))
@@ -45,11 +51,8 @@ Please adjust docs/dev/lsp-extensions.md.
4551
}
4652
}
4753

48-
#[test]
49-
fn files_are_tidy() {
50-
let sh = &Shell::new().unwrap();
51-
52-
let files = sourcegen::list_files(&sourcegen::project_root().join("crates"));
54+
fn files_are_tidy(sh: &Shell) {
55+
let files = list_files(&project_root().join("crates"));
5356

5457
let mut tidy_docs = TidyDocs::default();
5558
let mut tidy_marks = TidyMarks::default();
@@ -121,11 +124,7 @@ fn check_cargo_toml(path: &Path, text: String) {
121124
}
122125
}
123126

124-
#[cfg(not(feature = "in-rust-tree"))]
125-
#[test]
126-
fn check_licenses() {
127-
let sh = &Shell::new().unwrap();
128-
127+
fn check_licenses(sh: &Shell) {
129128
let expected = "
130129
(MIT OR Apache-2.0) AND Unicode-DFS-2016
131130
0BSD OR MIT OR Apache-2.0
@@ -277,7 +276,7 @@ impl TidyDocs {
277276
}
278277

279278
fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
280-
p.strip_prefix(sourcegen::project_root())
279+
p.strip_prefix(project_root())
281280
.unwrap()
282281
.components()
283282
.rev()
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::path::{Path, PathBuf};
2+
3+
pub(crate) fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
4+
let mut res = list_files(dir);
5+
res.retain(|it| {
6+
it.file_name().unwrap_or_default().to_str().unwrap_or_default().ends_with(".rs")
7+
});
8+
res
9+
}
10+
11+
pub(crate) fn list_files(dir: &Path) -> Vec<PathBuf> {
12+
let mut res = Vec::new();
13+
let mut work = vec![dir.to_path_buf()];
14+
while let Some(dir) = work.pop() {
15+
for entry in dir.read_dir().unwrap() {
16+
let entry = entry.unwrap();
17+
let file_type = entry.file_type().unwrap();
18+
let path = entry.path();
19+
let is_hidden =
20+
path.file_name().unwrap_or_default().to_str().unwrap_or_default().starts_with('.');
21+
if !is_hidden {
22+
if file_type.is_dir() {
23+
work.push(path);
24+
} else if file_type.is_file() {
25+
res.push(path);
26+
}
27+
}
28+
}
29+
}
30+
res
31+
}

0 commit comments

Comments
 (0)