about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-07-07 09:11:46 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-07-07 09:12:16 +0200
commit6f346c91bee8d35b22fc5a94d9224b7e00178cb8 (patch)
tree80c08b2bf8e74056e5751e9084897fba99d1fef7
parentd00f4749b1f7efd0b4b513ef4940402f54e00e69 (diff)
downloadrust-6f346c91bee8d35b22fc5a94d9224b7e00178cb8.tar.gz
rust-6f346c91bee8d35b22fc5a94d9224b7e00178cb8.zip
Re-implement tidy as an xtask action
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs3
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen.rs30
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs5
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs3
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs3
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen/lints.rs3
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs3
-rw-r--r--src/tools/rust-analyzer/xtask/src/flags.rs6
-rw-r--r--src/tools/rust-analyzer/xtask/src/main.rs3
-rw-r--r--src/tools/rust-analyzer/xtask/src/tidy.rs (renamed from src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs)37
-rw-r--r--src/tools/rust-analyzer/xtask/src/util.rs31
12 files changed, 69 insertions, 60 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs b/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs
index 830042d0ed3..543328a57e3 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs
@@ -426,7 +426,7 @@ fn floating_point() {
             true,
         )),
     );
-    #[allow(unknown_lints, unnecessary_min_or_max)]
+    #[allow(unknown_lints, clippy::unnecessary_min_or_max)]
     check_number(
         r#"
         extern "rust-intrinsic" {
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
index c6236d8b4f9..56f416a0b6e 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -11,11 +11,8 @@
 #![allow(clippy::disallowed_types)]
 
 mod ratoml;
-#[cfg(not(feature = "in-rust-tree"))]
-mod sourcegen;
 mod support;
 mod testdir;
-mod tidy;
 
 use std::{collections::HashMap, path::PathBuf, time::Instant};
 
diff --git a/src/tools/rust-analyzer/xtask/src/codegen.rs b/src/tools/rust-analyzer/xtask/src/codegen.rs
index eb757c83d17..acaa65129df 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen.rs
+++ b/src/tools/rust-analyzer/xtask/src/codegen.rs
@@ -39,36 +39,6 @@ impl flags::Codegen {
     }
 }
 
-fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
-    let mut res = list_files(dir);
-    res.retain(|it| {
-        it.file_name().unwrap_or_default().to_str().unwrap_or_default().ends_with(".rs")
-    });
-    res
-}
-
-fn list_files(dir: &Path) -> Vec<PathBuf> {
-    let mut res = Vec::new();
-    let mut work = vec![dir.to_path_buf()];
-    while let Some(dir) = work.pop() {
-        for entry in dir.read_dir().unwrap() {
-            let entry = entry.unwrap();
-            let file_type = entry.file_type().unwrap();
-            let path = entry.path();
-            let is_hidden =
-                path.file_name().unwrap_or_default().to_str().unwrap_or_default().starts_with('.');
-            if !is_hidden {
-                if file_type.is_dir() {
-                    work.push(path);
-                } else if file_type.is_file() {
-                    res.push(path);
-                }
-            }
-        }
-    }
-    res
-}
-
 #[derive(Clone)]
 pub(crate) struct CommentBlock {
     pub(crate) id: String,
diff --git a/src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs b/src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs
index c868f702097..1256232287f 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs
+++ b/src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs
@@ -5,10 +5,9 @@ use std::{fmt, fs, path::Path};
 use stdx::format_to_acc;
 
 use crate::{
-    codegen::{
-        add_preamble, ensure_file_contents, list_rust_files, reformat, CommentBlock, Location,
-    },
+    codegen::{add_preamble, ensure_file_contents, reformat, CommentBlock, Location},
     project_root,
+    util::list_rust_files,
 };
 
 pub(crate) fn generate(check: bool) {
diff --git a/src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs b/src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs
index 316ae80f4c1..4cb8f3f259d 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs
+++ b/src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs
@@ -3,8 +3,9 @@
 use std::{fmt, fs, io, path::PathBuf};
 
 use crate::{
-    codegen::{add_preamble, list_rust_files, CommentBlock, Location},
+    codegen::{add_preamble, CommentBlock, Location},
     project_root,
+    util::list_rust_files,
 };
 
 pub(crate) fn generate(check: bool) {
diff --git a/src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs b/src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs
index 0c0fa838dd3..c6451d888b0 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs
+++ b/src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs
@@ -3,8 +3,9 @@
 use std::{fmt, fs, io, path::PathBuf};
 
 use crate::{
-    codegen::{list_rust_files, CommentBlock, Location},
+    codegen::{CommentBlock, Location},
     project_root,
+    util::list_rust_files,
 };
 
 pub(crate) fn generate(_check: bool) {
diff --git a/src/tools/rust-analyzer/xtask/src/codegen/lints.rs b/src/tools/rust-analyzer/xtask/src/codegen/lints.rs
index fafc87a0e22..f097b5817be 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen/lints.rs
+++ b/src/tools/rust-analyzer/xtask/src/codegen/lints.rs
@@ -6,8 +6,9 @@ use stdx::format_to;
 use xshell::{cmd, Shell};
 
 use crate::{
-    codegen::{add_preamble, ensure_file_contents, list_files, reformat},
+    codegen::{add_preamble, ensure_file_contents, reformat},
     project_root,
+    util::list_files,
 };
 
 const DESTINATION: &str = "crates/ide-db/src/generated/lints.rs";
diff --git a/src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs b/src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs
index 45be64c0055..7ad530ab01b 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs
+++ b/src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs
@@ -9,8 +9,9 @@ use std::{
 };
 
 use crate::{
-    codegen::{ensure_file_contents, list_rust_files, CommentBlock},
+    codegen::{ensure_file_contents, CommentBlock},
     project_root,
+    util::list_rust_files,
 };
 
 pub(crate) fn generate(check: bool) {
diff --git a/src/tools/rust-analyzer/xtask/src/flags.rs b/src/tools/rust-analyzer/xtask/src/flags.rs
index 9b3a2a034e1..cf4a22d476f 100644
--- a/src/tools/rust-analyzer/xtask/src/flags.rs
+++ b/src/tools/rust-analyzer/xtask/src/flags.rs
@@ -73,6 +73,8 @@ xflags::xflags! {
             optional codegen_type: CodegenType
             optional --check
         }
+
+        cmd tidy {}
     }
 }
 
@@ -96,9 +98,13 @@ pub enum XtaskCmd {
     Metrics(Metrics),
     Bb(Bb),
     Codegen(Codegen),
+    Tidy(Tidy),
 }
 
 #[derive(Debug)]
+pub struct Tidy {}
+
+#[derive(Debug)]
 pub struct Install {
     pub client: bool,
     pub code_bin: Option<String>,
diff --git a/src/tools/rust-analyzer/xtask/src/main.rs b/src/tools/rust-analyzer/xtask/src/main.rs
index e0705763035..5c312da1dd7 100644
--- a/src/tools/rust-analyzer/xtask/src/main.rs
+++ b/src/tools/rust-analyzer/xtask/src/main.rs
@@ -19,6 +19,8 @@ mod install;
 mod metrics;
 mod publish;
 mod release;
+mod tidy;
+mod util;
 
 use anyhow::bail;
 use std::{env, path::PathBuf};
@@ -51,6 +53,7 @@ fn main() -> anyhow::Result<()> {
             )?;
             Ok(())
         }
+        flags::XtaskCmd::Tidy(cmd) => cmd.run(sh),
     }
 }
 
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs b/src/tools/rust-analyzer/xtask/src/tidy.rs
index 8cd5cbf1c7c..98e52e7e970 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs
+++ b/src/tools/rust-analyzer/xtask/src/tidy.rs
@@ -6,23 +6,29 @@ use std::{
 
 use xshell::Shell;
 
-#[cfg(not(feature = "in-rust-tree"))]
 use xshell::cmd;
 
-#[test]
-fn check_lsp_extensions_docs() {
-    let sh = &Shell::new().unwrap();
+use crate::{flags::Tidy, project_root, util::list_files};
 
+impl Tidy {
+    pub(crate) fn run(&self, sh: &Shell) -> anyhow::Result<()> {
+        check_lsp_extensions_docs(sh);
+        files_are_tidy(sh);
+        check_licenses(sh);
+        Ok(())
+    }
+}
+
+fn check_lsp_extensions_docs(sh: &Shell) {
     let expected_hash = {
-        let lsp_ext_rs = sh
-            .read_file(sourcegen::project_root().join("crates/rust-analyzer/src/lsp/ext.rs"))
-            .unwrap();
+        let lsp_ext_rs =
+            sh.read_file(project_root().join("crates/rust-analyzer/src/lsp/ext.rs")).unwrap();
         stable_hash(lsp_ext_rs.as_str())
     };
 
     let actual_hash = {
         let lsp_extensions_md =
-            sh.read_file(sourcegen::project_root().join("docs/dev/lsp-extensions.md")).unwrap();
+            sh.read_file(project_root().join("docs/dev/lsp-extensions.md")).unwrap();
         let text = lsp_extensions_md
             .lines()
             .find_map(|line| line.strip_prefix("lsp/ext.rs hash:"))
@@ -45,11 +51,8 @@ Please adjust docs/dev/lsp-extensions.md.
     }
 }
 
-#[test]
-fn files_are_tidy() {
-    let sh = &Shell::new().unwrap();
-
-    let files = sourcegen::list_files(&sourcegen::project_root().join("crates"));
+fn files_are_tidy(sh: &Shell) {
+    let files = list_files(&project_root().join("crates"));
 
     let mut tidy_docs = TidyDocs::default();
     let mut tidy_marks = TidyMarks::default();
@@ -121,11 +124,7 @@ fn check_cargo_toml(path: &Path, text: String) {
     }
 }
 
-#[cfg(not(feature = "in-rust-tree"))]
-#[test]
-fn check_licenses() {
-    let sh = &Shell::new().unwrap();
-
+fn check_licenses(sh: &Shell) {
     let expected = "
 (MIT OR Apache-2.0) AND Unicode-DFS-2016
 0BSD OR MIT OR Apache-2.0
@@ -277,7 +276,7 @@ impl TidyDocs {
 }
 
 fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
-    p.strip_prefix(sourcegen::project_root())
+    p.strip_prefix(project_root())
         .unwrap()
         .components()
         .rev()
diff --git a/src/tools/rust-analyzer/xtask/src/util.rs b/src/tools/rust-analyzer/xtask/src/util.rs
new file mode 100644
index 00000000000..39f52938c8c
--- /dev/null
+++ b/src/tools/rust-analyzer/xtask/src/util.rs
@@ -0,0 +1,31 @@
+use std::path::{Path, PathBuf};
+
+pub(crate) fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
+    let mut res = list_files(dir);
+    res.retain(|it| {
+        it.file_name().unwrap_or_default().to_str().unwrap_or_default().ends_with(".rs")
+    });
+    res
+}
+
+pub(crate) fn list_files(dir: &Path) -> Vec<PathBuf> {
+    let mut res = Vec::new();
+    let mut work = vec![dir.to_path_buf()];
+    while let Some(dir) = work.pop() {
+        for entry in dir.read_dir().unwrap() {
+            let entry = entry.unwrap();
+            let file_type = entry.file_type().unwrap();
+            let path = entry.path();
+            let is_hidden =
+                path.file_name().unwrap_or_default().to_str().unwrap_or_default().starts_with('.');
+            if !is_hidden {
+                if file_type.is_dir() {
+                    work.push(path);
+                } else if file_type.is_file() {
+                    res.push(path);
+                }
+            }
+        }
+    }
+    res
+}