diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/Cargo.toml | 7 | ||||
-rw-r--r-- | xtask/src/codegen.rs | 14 | ||||
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 10 | ||||
-rw-r--r-- | xtask/src/codegen/gen_diagnostic_docs.rs | 4 | ||||
-rw-r--r-- | xtask/src/codegen/gen_feature_docs.rs | 4 | ||||
-rw-r--r-- | xtask/src/codegen/gen_features.rs | 48 | ||||
-rw-r--r-- | xtask/src/codegen/gen_lint_completions.rs | 71 | ||||
-rw-r--r-- | xtask/src/codegen/gen_parser_tests.rs | 2 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 2 | ||||
-rw-r--r-- | xtask/src/dist.rs | 10 | ||||
-rw-r--r-- | xtask/src/flags.rs | 139 | ||||
-rw-r--r-- | xtask/src/install.rs | 28 | ||||
-rw-r--r-- | xtask/src/lib.rs | 118 | ||||
-rw-r--r-- | xtask/src/main.rs | 282 | ||||
-rw-r--r-- | xtask/src/metrics.rs | 10 | ||||
-rw-r--r-- | xtask/src/pre_cache.rs | 6 | ||||
-rw-r--r-- | xtask/src/pre_commit.rs | 38 | ||||
-rw-r--r-- | xtask/src/release.rs | 75 | ||||
-rw-r--r-- | xtask/src/tidy.rs (renamed from xtask/tests/tidy.rs) | 66 |
19 files changed, 478 insertions, 456 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 4abc7b053..b17dde598 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml | |||
@@ -6,17 +6,14 @@ authors = ["rust-analyzer developers"] | |||
6 | publish = false | 6 | publish = false |
7 | license = "MIT OR Apache-2.0" | 7 | license = "MIT OR Apache-2.0" |
8 | 8 | ||
9 | [lib] | ||
10 | doctest = false | ||
11 | |||
12 | [dependencies] | 9 | [dependencies] |
13 | anyhow = "1.0.26" | 10 | anyhow = "1.0.26" |
14 | flate2 = "1.0" | 11 | flate2 = "1.0" |
15 | pico-args = "0.3.1" | ||
16 | proc-macro2 = "1.0.8" | 12 | proc-macro2 = "1.0.8" |
17 | quote = "1.0.2" | 13 | quote = "1.0.2" |
18 | ungrammar = "1.9" | 14 | ungrammar = "=1.11" |
19 | walkdir = "2.3.1" | 15 | walkdir = "2.3.1" |
20 | write-json = "0.1.0" | 16 | write-json = "0.1.0" |
21 | xshell = "0.1" | 17 | xshell = "0.1" |
18 | xflags = "0.1.2" | ||
22 | # Avoid adding more dependencies to this crate | 19 | # Avoid adding more dependencies to this crate |
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index adea053b6..2f56c5ad0 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -18,9 +18,9 @@ use std::{ | |||
18 | }; | 18 | }; |
19 | use xshell::{cmd, pushenv, read_file, write_file}; | 19 | use xshell::{cmd, pushenv, read_file, write_file}; |
20 | 20 | ||
21 | use crate::{ensure_rustfmt, project_root, Result}; | 21 | use crate::{ensure_rustfmt, flags, project_root, Result}; |
22 | 22 | ||
23 | pub use self::{ | 23 | pub(crate) use self::{ |
24 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, | 24 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, |
25 | gen_diagnostic_docs::generate_diagnostic_docs, | 25 | gen_diagnostic_docs::generate_diagnostic_docs, |
26 | gen_feature_docs::generate_feature_docs, | 26 | gen_feature_docs::generate_feature_docs, |
@@ -30,17 +30,13 @@ pub use self::{ | |||
30 | }; | 30 | }; |
31 | 31 | ||
32 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 32 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
33 | pub enum Mode { | 33 | pub(crate) enum Mode { |
34 | Overwrite, | 34 | Overwrite, |
35 | Verify, | 35 | Verify, |
36 | } | 36 | } |
37 | 37 | ||
38 | pub struct CodegenCmd { | 38 | impl flags::Codegen { |
39 | pub features: bool, | 39 | pub(crate) fn run(self) -> Result<()> { |
40 | } | ||
41 | |||
42 | impl CodegenCmd { | ||
43 | pub fn run(self) -> Result<()> { | ||
44 | if self.features { | 40 | if self.features { |
45 | generate_lint_completions(Mode::Overwrite)?; | 41 | generate_lint_completions(Mode::Overwrite)?; |
46 | } | 42 | } |
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 6e18a50a6..c469b388d 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs | |||
@@ -4,15 +4,15 @@ use std::{fmt, path::Path}; | |||
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, Mode, PREAMBLE}, | 6 | codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, Mode, PREAMBLE}, |
7 | project_root, rust_files, Result, | 7 | project_root, rust_files_in, Result, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | pub fn generate_assists_tests(mode: Mode) -> Result<()> { | 10 | pub(crate) fn generate_assists_tests(mode: Mode) -> Result<()> { |
11 | let assists = Assist::collect()?; | 11 | let assists = Assist::collect()?; |
12 | generate_tests(&assists, mode) | 12 | generate_tests(&assists, mode) |
13 | } | 13 | } |
14 | 14 | ||
15 | pub fn generate_assists_docs(mode: Mode) -> Result<()> { | 15 | pub(crate) fn generate_assists_docs(mode: Mode) -> Result<()> { |
16 | let assists = Assist::collect()?; | 16 | let assists = Assist::collect()?; |
17 | let contents = assists.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); | 17 | let contents = assists.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); |
18 | let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); | 18 | let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); |
@@ -32,7 +32,7 @@ struct Assist { | |||
32 | impl Assist { | 32 | impl Assist { |
33 | fn collect() -> Result<Vec<Assist>> { | 33 | fn collect() -> Result<Vec<Assist>> { |
34 | let mut res = Vec::new(); | 34 | let mut res = Vec::new(); |
35 | for path in rust_files(&project_root().join("crates/assists/src/handlers")) { | 35 | for path in rust_files_in(&project_root().join("crates/ide_assists/src/handlers")) { |
36 | collect_file(&mut res, path.as_path())?; | 36 | collect_file(&mut res, path.as_path())?; |
37 | } | 37 | } |
38 | res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); | 38 | res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); |
@@ -135,7 +135,7 @@ r#####" | |||
135 | buf.push_str(&test) | 135 | buf.push_str(&test) |
136 | } | 136 | } |
137 | let buf = reformat(&buf)?; | 137 | let buf = reformat(&buf)?; |
138 | codegen::update(&project_root().join("crates/assists/src/tests/generated.rs"), &buf, mode) | 138 | codegen::update(&project_root().join("crates/ide_assists/src/tests/generated.rs"), &buf, mode) |
139 | } | 139 | } |
140 | 140 | ||
141 | fn hide_hash_comments(text: &str) -> String { | 141 | fn hide_hash_comments(text: &str) -> String { |
diff --git a/xtask/src/codegen/gen_diagnostic_docs.rs b/xtask/src/codegen/gen_diagnostic_docs.rs index 00aaea5b7..a2561817b 100644 --- a/xtask/src/codegen/gen_diagnostic_docs.rs +++ b/xtask/src/codegen/gen_diagnostic_docs.rs | |||
@@ -7,7 +7,7 @@ use crate::{ | |||
7 | project_root, rust_files, Result, | 7 | project_root, rust_files, Result, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | pub fn generate_diagnostic_docs(mode: Mode) -> Result<()> { | 10 | pub(crate) fn generate_diagnostic_docs(mode: Mode) -> Result<()> { |
11 | let diagnostics = Diagnostic::collect()?; | 11 | let diagnostics = Diagnostic::collect()?; |
12 | let contents = | 12 | let contents = |
13 | diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); | 13 | diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); |
@@ -27,7 +27,7 @@ struct Diagnostic { | |||
27 | impl Diagnostic { | 27 | impl Diagnostic { |
28 | fn collect() -> Result<Vec<Diagnostic>> { | 28 | fn collect() -> Result<Vec<Diagnostic>> { |
29 | let mut res = Vec::new(); | 29 | let mut res = Vec::new(); |
30 | for path in rust_files(&project_root()) { | 30 | for path in rust_files() { |
31 | collect_file(&mut res, path)?; | 31 | collect_file(&mut res, path)?; |
32 | } | 32 | } |
33 | res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); | 33 | res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); |
diff --git a/xtask/src/codegen/gen_feature_docs.rs b/xtask/src/codegen/gen_feature_docs.rs index 065dd33f1..cad7ff477 100644 --- a/xtask/src/codegen/gen_feature_docs.rs +++ b/xtask/src/codegen/gen_feature_docs.rs | |||
@@ -7,7 +7,7 @@ use crate::{ | |||
7 | project_root, rust_files, Result, | 7 | project_root, rust_files, Result, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | pub fn generate_feature_docs(mode: Mode) -> Result<()> { | 10 | pub(crate) fn generate_feature_docs(mode: Mode) -> Result<()> { |
11 | let features = Feature::collect()?; | 11 | let features = Feature::collect()?; |
12 | let contents = features.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); | 12 | let contents = features.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); |
13 | let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); | 13 | let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); |
@@ -26,7 +26,7 @@ struct Feature { | |||
26 | impl Feature { | 26 | impl Feature { |
27 | fn collect() -> Result<Vec<Feature>> { | 27 | fn collect() -> Result<Vec<Feature>> { |
28 | let mut res = Vec::new(); | 28 | let mut res = Vec::new(); |
29 | for path in rust_files(&project_root()) { | 29 | for path in rust_files() { |
30 | collect_file(&mut res, path)?; | 30 | collect_file(&mut res, path)?; |
31 | } | 31 | } |
32 | res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); | 32 | res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); |
diff --git a/xtask/src/codegen/gen_features.rs b/xtask/src/codegen/gen_features.rs deleted file mode 100644 index 3cf15ce02..000000000 --- a/xtask/src/codegen/gen_features.rs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | //! Generates descriptors structure for unstable feature from Unstable Book | ||
2 | use std::path::{Path, PathBuf}; | ||
3 | |||
4 | use quote::quote; | ||
5 | use walkdir::WalkDir; | ||
6 | use xshell::{cmd, read_file}; | ||
7 | |||
8 | use crate::codegen::{project_root, reformat, update, Mode, Result}; | ||
9 | |||
10 | pub fn generate_features(mode: Mode) -> Result<()> { | ||
11 | if !Path::new("./target/rust").exists() { | ||
12 | cmd!("git clone https://github.com/rust-lang/rust ./target/rust").run()?; | ||
13 | } | ||
14 | |||
15 | let contents = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?; | ||
16 | |||
17 | let destination = project_root().join("crates/ide/src/completion/generated_features.rs"); | ||
18 | update(destination.as_path(), &contents, mode)?; | ||
19 | |||
20 | Ok(()) | ||
21 | } | ||
22 | |||
23 | fn generate_descriptor(src_dir: PathBuf) -> Result<String> { | ||
24 | let definitions = ["language-features", "library-features"] | ||
25 | .iter() | ||
26 | .flat_map(|it| WalkDir::new(src_dir.join(it))) | ||
27 | .filter_map(|e| e.ok()) | ||
28 | .filter(|entry| { | ||
29 | // Get all `.md ` files | ||
30 | entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md" | ||
31 | }) | ||
32 | .map(|entry| { | ||
33 | let path = entry.path(); | ||
34 | let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_"); | ||
35 | let doc = read_file(path).unwrap(); | ||
36 | |||
37 | quote! { LintCompletion { label: #feature_ident, description: #doc } } | ||
38 | }); | ||
39 | |||
40 | let ts = quote! { | ||
41 | use crate::completion::complete_attribute::LintCompletion; | ||
42 | |||
43 | pub(super) const FEATURES: &[LintCompletion] = &[ | ||
44 | #(#definitions),* | ||
45 | ]; | ||
46 | }; | ||
47 | reformat(&ts.to_string()) | ||
48 | } | ||
diff --git a/xtask/src/codegen/gen_lint_completions.rs b/xtask/src/codegen/gen_lint_completions.rs index b97421217..b1c057037 100644 --- a/xtask/src/codegen/gen_lint_completions.rs +++ b/xtask/src/codegen/gen_lint_completions.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Generates descriptors structure for unstable feature from Unstable Book | 1 | //! Generates descriptors structure for unstable feature from Unstable Book |
2 | use std::fmt::Write; | ||
2 | use std::path::{Path, PathBuf}; | 3 | use std::path::{Path, PathBuf}; |
3 | 4 | ||
4 | use quote::quote; | ||
5 | use walkdir::WalkDir; | 5 | use walkdir::WalkDir; |
6 | use xshell::{cmd, read_file}; | 6 | use xshell::{cmd, read_file}; |
7 | 7 | ||
@@ -10,31 +10,31 @@ use crate::{ | |||
10 | run_rustfmt, | 10 | run_rustfmt, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | pub fn generate_lint_completions(mode: Mode) -> Result<()> { | 13 | pub(crate) fn generate_lint_completions(mode: Mode) -> Result<()> { |
14 | if !Path::new("./target/rust").exists() { | 14 | if !Path::new("./target/rust").exists() { |
15 | cmd!("git clone --depth=1 https://github.com/rust-lang/rust ./target/rust").run()?; | 15 | cmd!("git clone --depth=1 https://github.com/rust-lang/rust ./target/rust").run()?; |
16 | } | 16 | } |
17 | 17 | ||
18 | let ts_features = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?; | 18 | let mut contents = String::from("use crate::completions::attribute::LintCompletion;\n\n"); |
19 | cmd!("curl http://rust-lang.github.io/rust-clippy/master/lints.json --output ./target/clippy_lints.json").run()?; | 19 | generate_descriptor(&mut contents, "./target/rust/src/doc/unstable-book/src".into())?; |
20 | contents.push('\n'); | ||
20 | 21 | ||
21 | let ts_clippy = generate_descriptor_clippy(&Path::new("./target/clippy_lints.json"))?; | 22 | cmd!("curl http://rust-lang.github.io/rust-clippy/master/lints.json --output ./target/clippy_lints.json").run()?; |
22 | let ts = quote! { | 23 | generate_descriptor_clippy(&mut contents, &Path::new("./target/clippy_lints.json"))?; |
23 | use crate::completions::attribute::LintCompletion; | 24 | let contents = reformat(&contents)?; |
24 | #ts_features | ||
25 | #ts_clippy | ||
26 | }; | ||
27 | let contents = reformat(ts.to_string().as_str())?; | ||
28 | 25 | ||
29 | let destination = project_root().join("crates/completion/src/generated_lint_completions.rs"); | 26 | let destination = |
27 | project_root().join("crates/ide_completion/src/generated_lint_completions.rs"); | ||
30 | update(destination.as_path(), &contents, mode)?; | 28 | update(destination.as_path(), &contents, mode)?; |
31 | run_rustfmt(mode)?; | 29 | run_rustfmt(mode)?; |
32 | 30 | ||
33 | Ok(()) | 31 | Ok(()) |
34 | } | 32 | } |
35 | 33 | ||
36 | fn generate_descriptor(src_dir: PathBuf) -> Result<proc_macro2::TokenStream> { | 34 | fn generate_descriptor(buf: &mut String, src_dir: PathBuf) -> Result<()> { |
37 | let definitions = ["language-features", "library-features"] | 35 | buf.push_str(r#"pub(super) const FEATURES: &[LintCompletion] = &["#); |
36 | buf.push('\n'); | ||
37 | ["language-features", "library-features"] | ||
38 | .iter() | 38 | .iter() |
39 | .flat_map(|it| WalkDir::new(src_dir.join(it))) | 39 | .flat_map(|it| WalkDir::new(src_dir.join(it))) |
40 | .filter_map(|e| e.ok()) | 40 | .filter_map(|e| e.ok()) |
@@ -42,21 +42,15 @@ fn generate_descriptor(src_dir: PathBuf) -> Result<proc_macro2::TokenStream> { | |||
42 | // Get all `.md ` files | 42 | // Get all `.md ` files |
43 | entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md" | 43 | entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md" |
44 | }) | 44 | }) |
45 | .map(|entry| { | 45 | .for_each(|entry| { |
46 | let path = entry.path(); | 46 | let path = entry.path(); |
47 | let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_"); | 47 | let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_"); |
48 | let doc = read_file(path).unwrap(); | 48 | let doc = read_file(path).unwrap(); |
49 | 49 | ||
50 | quote! { LintCompletion { label: #feature_ident, description: #doc } } | 50 | push_lint_completion(buf, &feature_ident, &doc); |
51 | }); | 51 | }); |
52 | 52 | buf.push_str("];\n"); | |
53 | let ts = quote! { | 53 | Ok(()) |
54 | pub(super) const FEATURES: &[LintCompletion] = &[ | ||
55 | #(#definitions),* | ||
56 | ]; | ||
57 | }; | ||
58 | |||
59 | Ok(ts) | ||
60 | } | 54 | } |
61 | 55 | ||
62 | #[derive(Default)] | 56 | #[derive(Default)] |
@@ -65,7 +59,7 @@ struct ClippyLint { | |||
65 | id: String, | 59 | id: String, |
66 | } | 60 | } |
67 | 61 | ||
68 | fn generate_descriptor_clippy(path: &Path) -> Result<proc_macro2::TokenStream> { | 62 | fn generate_descriptor_clippy(buf: &mut String, path: &Path) -> Result<()> { |
69 | let file_content = read_file(path)?; | 63 | let file_content = read_file(path)?; |
70 | let mut clippy_lints: Vec<ClippyLint> = vec![]; | 64 | let mut clippy_lints: Vec<ClippyLint> = vec![]; |
71 | 65 | ||
@@ -96,18 +90,27 @@ fn generate_descriptor_clippy(path: &Path) -> Result<proc_macro2::TokenStream> { | |||
96 | } | 90 | } |
97 | } | 91 | } |
98 | 92 | ||
99 | let definitions = clippy_lints.into_iter().map(|clippy_lint| { | 93 | buf.push_str(r#"pub(super) const CLIPPY_LINTS: &[LintCompletion] = &["#); |
94 | buf.push('\n'); | ||
95 | clippy_lints.into_iter().for_each(|clippy_lint| { | ||
100 | let lint_ident = format!("clippy::{}", clippy_lint.id); | 96 | let lint_ident = format!("clippy::{}", clippy_lint.id); |
101 | let doc = clippy_lint.help; | 97 | let doc = clippy_lint.help; |
102 | 98 | push_lint_completion(buf, &lint_ident, &doc); | |
103 | quote! { LintCompletion { label: #lint_ident, description: #doc } } | ||
104 | }); | 99 | }); |
105 | 100 | ||
106 | let ts = quote! { | 101 | buf.push_str("];\n"); |
107 | pub(super) const CLIPPY_LINTS: &[LintCompletion] = &[ | 102 | |
108 | #(#definitions),* | 103 | Ok(()) |
109 | ]; | 104 | } |
110 | }; | ||
111 | 105 | ||
112 | Ok(ts) | 106 | fn push_lint_completion(buf: &mut String, label: &str, description: &str) { |
107 | writeln!( | ||
108 | buf, | ||
109 | r###" LintCompletion {{ | ||
110 | label: "{}", | ||
111 | description: r##"{}"## | ||
112 | }},"###, | ||
113 | label, description | ||
114 | ) | ||
115 | .unwrap(); | ||
113 | } | 116 | } |
diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index 6e4abd10c..cb8939063 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs | |||
@@ -12,7 +12,7 @@ use crate::{ | |||
12 | project_root, Result, | 12 | project_root, Result, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | pub fn generate_parser_tests(mode: Mode) -> Result<()> { | 15 | pub(crate) fn generate_parser_tests(mode: Mode) -> Result<()> { |
16 | let tests = tests_from_dir(&project_root().join(Path::new("crates/parser/src/grammar")))?; | 16 | let tests = tests_from_dir(&project_root().join(Path::new("crates/parser/src/grammar")))?; |
17 | fn install_tests(tests: &HashMap<String, Test>, into: &str, mode: Mode) -> Result<()> { | 17 | fn install_tests(tests: &HashMap<String, Test>, into: &str, mode: Mode) -> Result<()> { |
18 | let tests_dir = project_root().join(into); | 18 | let tests_dir = project_root().join(into); |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index eb524d85a..191bc0e9d 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | project_root, Result, | 18 | project_root, Result, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pub fn generate_syntax(mode: Mode) -> Result<()> { | 21 | pub(crate) fn generate_syntax(mode: Mode) -> Result<()> { |
22 | let grammar = rust_grammar(); | 22 | let grammar = rust_grammar(); |
23 | let ast = lower(&grammar); | 23 | let ast = lower(&grammar); |
24 | 24 | ||
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index 6bc34106b..f2503f807 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs | |||
@@ -11,13 +11,13 @@ use xshell::{cmd, cp, mkdir_p, pushd, read_file, rm_rf, write_file}; | |||
11 | 11 | ||
12 | use crate::{date_iso, project_root}; | 12 | use crate::{date_iso, project_root}; |
13 | 13 | ||
14 | pub struct DistCmd { | 14 | pub(crate) struct DistCmd { |
15 | pub nightly: bool, | 15 | pub(crate) nightly: bool, |
16 | pub client_version: Option<String>, | 16 | pub(crate) client_version: Option<String>, |
17 | } | 17 | } |
18 | 18 | ||
19 | impl DistCmd { | 19 | impl DistCmd { |
20 | pub fn run(self) -> Result<()> { | 20 | pub(crate) fn run(self) -> Result<()> { |
21 | let dist = project_root().join("dist"); | 21 | let dist = project_root().join("dist"); |
22 | rm_rf(&dist)?; | 22 | rm_rf(&dist)?; |
23 | mkdir_p(&dist)?; | 23 | mkdir_p(&dist)?; |
@@ -59,7 +59,7 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { | |||
59 | 59 | ||
60 | fn dist_server() -> Result<()> { | 60 | fn dist_server() -> Result<()> { |
61 | let target = get_target(); | 61 | let target = get_target(); |
62 | if target.contains("-linux-gnu") { | 62 | if target.contains("-linux-gnu") || target.contains("-linux-musl") { |
63 | env::set_var("CC", "clang"); | 63 | env::set_var("CC", "clang"); |
64 | } | 64 | } |
65 | 65 | ||
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs new file mode 100644 index 000000000..5710fbdb5 --- /dev/null +++ b/xtask/src/flags.rs | |||
@@ -0,0 +1,139 @@ | |||
1 | #![allow(unreachable_pub)] | ||
2 | |||
3 | xflags::args_parser! { | ||
4 | /// Run custom build command. | ||
5 | cmd xtask { | ||
6 | default cmd help { | ||
7 | /// Print help information. | ||
8 | optional -h, --help | ||
9 | } | ||
10 | |||
11 | /// Install rust-analyzer server or editor plugin. | ||
12 | cmd install { | ||
13 | /// Install only VS Code plugin. | ||
14 | optional --client | ||
15 | /// One of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'. | ||
16 | optional --code-bin name: String | ||
17 | |||
18 | /// Install only the language server. | ||
19 | optional --server | ||
20 | /// Use mimalloc allocator for server | ||
21 | optional --mimalloc | ||
22 | /// Use jemalloc allocator for server | ||
23 | optional --jemalloc | ||
24 | } | ||
25 | |||
26 | cmd codegen { | ||
27 | optional --features | ||
28 | } | ||
29 | |||
30 | cmd lint {} | ||
31 | cmd fuzz-tests {} | ||
32 | cmd pre-cache {} | ||
33 | |||
34 | cmd release { | ||
35 | optional --dry-run | ||
36 | } | ||
37 | cmd promote { | ||
38 | optional --dry-run | ||
39 | } | ||
40 | cmd dist { | ||
41 | optional --nightly | ||
42 | optional --client version: String | ||
43 | } | ||
44 | cmd metrics { | ||
45 | optional --dry-run | ||
46 | } | ||
47 | /// Builds a benchmark version of rust-analyzer and puts it into `./target`. | ||
48 | cmd bb | ||
49 | required suffix: String | ||
50 | {} | ||
51 | } | ||
52 | } | ||
53 | |||
54 | // generated start | ||
55 | // The following code is generated by `xflags` macro. | ||
56 | // Run `env XFLAGS_DUMP= cargo build` to regenerate. | ||
57 | #[derive(Debug)] | ||
58 | pub struct Xtask { | ||
59 | pub subcommand: XtaskCmd, | ||
60 | } | ||
61 | |||
62 | #[derive(Debug)] | ||
63 | pub enum XtaskCmd { | ||
64 | Help(Help), | ||
65 | Install(Install), | ||
66 | Codegen(Codegen), | ||
67 | Lint(Lint), | ||
68 | FuzzTests(FuzzTests), | ||
69 | PreCache(PreCache), | ||
70 | Release(Release), | ||
71 | Promote(Promote), | ||
72 | Dist(Dist), | ||
73 | Metrics(Metrics), | ||
74 | Bb(Bb), | ||
75 | } | ||
76 | |||
77 | #[derive(Debug)] | ||
78 | pub struct Help { | ||
79 | pub help: bool, | ||
80 | } | ||
81 | |||
82 | #[derive(Debug)] | ||
83 | pub struct Install { | ||
84 | pub client: bool, | ||
85 | pub code_bin: Option<String>, | ||
86 | pub server: bool, | ||
87 | pub mimalloc: bool, | ||
88 | pub jemalloc: bool, | ||
89 | } | ||
90 | |||
91 | #[derive(Debug)] | ||
92 | pub struct Codegen { | ||
93 | pub features: bool, | ||
94 | } | ||
95 | |||
96 | #[derive(Debug)] | ||
97 | pub struct Lint {} | ||
98 | |||
99 | #[derive(Debug)] | ||
100 | pub struct FuzzTests {} | ||
101 | |||
102 | #[derive(Debug)] | ||
103 | pub struct PreCache {} | ||
104 | |||
105 | #[derive(Debug)] | ||
106 | pub struct Release { | ||
107 | pub dry_run: bool, | ||
108 | } | ||
109 | |||
110 | #[derive(Debug)] | ||
111 | pub struct Promote { | ||
112 | pub dry_run: bool, | ||
113 | } | ||
114 | |||
115 | #[derive(Debug)] | ||
116 | pub struct Dist { | ||
117 | pub nightly: bool, | ||
118 | pub client: Option<String>, | ||
119 | } | ||
120 | |||
121 | #[derive(Debug)] | ||
122 | pub struct Metrics { | ||
123 | pub dry_run: bool, | ||
124 | } | ||
125 | |||
126 | #[derive(Debug)] | ||
127 | pub struct Bb { | ||
128 | pub suffix: String, | ||
129 | } | ||
130 | |||
131 | impl Xtask { | ||
132 | pub const HELP: &'static str = Self::_HELP; | ||
133 | |||
134 | pub fn from_env() -> xflags::Result<Self> { | ||
135 | let mut p = xflags::rt::Parser::new_from_env(); | ||
136 | Self::_parse(&mut p) | ||
137 | } | ||
138 | } | ||
139 | // generated end | ||
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 12962bcfa..ea2194248 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -6,15 +6,15 @@ use anyhow::{bail, format_err, Context, Result}; | |||
6 | use xshell::{cmd, pushd}; | 6 | use xshell::{cmd, pushd}; |
7 | 7 | ||
8 | // Latest stable, feel free to send a PR if this lags behind. | 8 | // Latest stable, feel free to send a PR if this lags behind. |
9 | const REQUIRED_RUST_VERSION: u32 = 47; | 9 | const REQUIRED_RUST_VERSION: u32 = 50; |
10 | 10 | ||
11 | pub struct InstallCmd { | 11 | pub(crate) struct InstallCmd { |
12 | pub client: Option<ClientOpt>, | 12 | pub(crate) client: Option<ClientOpt>, |
13 | pub server: Option<ServerOpt>, | 13 | pub(crate) server: Option<ServerOpt>, |
14 | } | 14 | } |
15 | 15 | ||
16 | #[derive(Clone, Copy)] | 16 | #[derive(Clone, Copy)] |
17 | pub enum ClientOpt { | 17 | pub(crate) enum ClientOpt { |
18 | VsCode, | 18 | VsCode, |
19 | VsCodeExploration, | 19 | VsCodeExploration, |
20 | VsCodeInsiders, | 20 | VsCodeInsiders, |
@@ -24,7 +24,7 @@ pub enum ClientOpt { | |||
24 | } | 24 | } |
25 | 25 | ||
26 | impl ClientOpt { | 26 | impl ClientOpt { |
27 | pub const fn as_cmds(&self) -> &'static [&'static str] { | 27 | pub(crate) const fn as_cmds(&self) -> &'static [&'static str] { |
28 | match self { | 28 | match self { |
29 | ClientOpt::VsCode => &["code"], | 29 | ClientOpt::VsCode => &["code"], |
30 | ClientOpt::VsCodeExploration => &["code-exploration"], | 30 | ClientOpt::VsCodeExploration => &["code-exploration"], |
@@ -60,17 +60,18 @@ impl std::str::FromStr for ClientOpt { | |||
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | pub struct ServerOpt { | 63 | pub(crate) struct ServerOpt { |
64 | pub malloc: Malloc, | 64 | pub(crate) malloc: Malloc, |
65 | } | 65 | } |
66 | 66 | ||
67 | pub enum Malloc { | 67 | pub(crate) enum Malloc { |
68 | System, | 68 | System, |
69 | Mimalloc, | 69 | Mimalloc, |
70 | Jemalloc, | ||
70 | } | 71 | } |
71 | 72 | ||
72 | impl InstallCmd { | 73 | impl InstallCmd { |
73 | pub fn run(self) -> Result<()> { | 74 | pub(crate) fn run(self) -> Result<()> { |
74 | if cfg!(target_os = "macos") { | 75 | if cfg!(target_os = "macos") { |
75 | fix_path_for_mac().context("Fix path for mac")? | 76 | fix_path_for_mac().context("Fix path for mac")? |
76 | } | 77 | } |
@@ -128,7 +129,7 @@ fn install_client(client_opt: ClientOpt) -> Result<()> { | |||
128 | 129 | ||
129 | let installed_extensions = if cfg!(unix) { | 130 | let installed_extensions = if cfg!(unix) { |
130 | cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?; | 131 | cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?; |
131 | cmd!("npm install").run()?; | 132 | cmd!("npm ci").run()?; |
132 | 133 | ||
133 | cmd!("npm run package --scripts-prepend-node-path").run()?; | 134 | cmd!("npm run package --scripts-prepend-node-path").run()?; |
134 | 135 | ||
@@ -139,7 +140,7 @@ fn install_client(client_opt: ClientOpt) -> Result<()> { | |||
139 | cmd!("cmd.exe /c npm --version") | 140 | cmd!("cmd.exe /c npm --version") |
140 | .run() | 141 | .run() |
141 | .context("`npm` is required to build the VS Code plugin")?; | 142 | .context("`npm` is required to build the VS Code plugin")?; |
142 | cmd!("cmd.exe /c npm install").run()?; | 143 | cmd!("cmd.exe /c npm ci").run()?; |
143 | 144 | ||
144 | cmd!("cmd.exe /c npm run package").run()?; | 145 | cmd!("cmd.exe /c npm run package").run()?; |
145 | 146 | ||
@@ -176,9 +177,10 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
176 | let features = match opts.malloc { | 177 | let features = match opts.malloc { |
177 | Malloc::System => &[][..], | 178 | Malloc::System => &[][..], |
178 | Malloc::Mimalloc => &["--features", "mimalloc"], | 179 | Malloc::Mimalloc => &["--features", "mimalloc"], |
180 | Malloc::Jemalloc => &["--features", "jemalloc"], | ||
179 | }; | 181 | }; |
180 | 182 | ||
181 | let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}"); | 183 | let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force --features force-always-assert {features...}"); |
182 | let res = cmd.run(); | 184 | let res = cmd.run(); |
183 | 185 | ||
184 | if res.is_err() && old_rust { | 186 | if res.is_err() && old_rust { |
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs deleted file mode 100644 index babec2dbd..000000000 --- a/xtask/src/lib.rs +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | //! Support library for `cargo xtask` command. | ||
2 | //! | ||
3 | //! See https://github.com/matklad/cargo-xtask/ | ||
4 | |||
5 | pub mod codegen; | ||
6 | mod ast_src; | ||
7 | |||
8 | pub mod install; | ||
9 | pub mod release; | ||
10 | pub mod dist; | ||
11 | pub mod pre_commit; | ||
12 | pub mod metrics; | ||
13 | pub mod pre_cache; | ||
14 | |||
15 | use std::{ | ||
16 | env, | ||
17 | path::{Path, PathBuf}, | ||
18 | }; | ||
19 | |||
20 | use walkdir::{DirEntry, WalkDir}; | ||
21 | use xshell::{cmd, pushd, pushenv}; | ||
22 | |||
23 | use crate::codegen::Mode; | ||
24 | |||
25 | pub use anyhow::{bail, Context as _, Result}; | ||
26 | |||
27 | pub fn project_root() -> PathBuf { | ||
28 | Path::new( | ||
29 | &env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()), | ||
30 | ) | ||
31 | .ancestors() | ||
32 | .nth(1) | ||
33 | .unwrap() | ||
34 | .to_path_buf() | ||
35 | } | ||
36 | |||
37 | pub fn rust_files(path: &Path) -> impl Iterator<Item = PathBuf> { | ||
38 | let iter = WalkDir::new(path); | ||
39 | return iter | ||
40 | .into_iter() | ||
41 | .filter_entry(|e| !is_hidden(e)) | ||
42 | .map(|e| e.unwrap()) | ||
43 | .filter(|e| !e.file_type().is_dir()) | ||
44 | .map(|e| e.into_path()) | ||
45 | .filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false)); | ||
46 | |||
47 | fn is_hidden(entry: &DirEntry) -> bool { | ||
48 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | ||
49 | } | ||
50 | } | ||
51 | |||
52 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | ||
53 | let _dir = pushd(project_root())?; | ||
54 | let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); | ||
55 | ensure_rustfmt()?; | ||
56 | let check = match mode { | ||
57 | Mode::Overwrite => &[][..], | ||
58 | Mode::Verify => &["--", "--check"], | ||
59 | }; | ||
60 | cmd!("cargo fmt {check...}").run()?; | ||
61 | Ok(()) | ||
62 | } | ||
63 | |||
64 | fn ensure_rustfmt() -> Result<()> { | ||
65 | let out = cmd!("rustfmt --version").read()?; | ||
66 | if !out.contains("stable") { | ||
67 | bail!( | ||
68 | "Failed to run rustfmt from toolchain 'stable'. \ | ||
69 | Please run `rustup component add rustfmt --toolchain stable` to install it.", | ||
70 | ) | ||
71 | } | ||
72 | Ok(()) | ||
73 | } | ||
74 | |||
75 | pub fn run_clippy() -> Result<()> { | ||
76 | if cmd!("cargo clippy --version").read().is_err() { | ||
77 | bail!( | ||
78 | "Failed run cargo clippy. \ | ||
79 | Please run `rustup component add clippy` to install it.", | ||
80 | ) | ||
81 | } | ||
82 | |||
83 | let allowed_lints = " | ||
84 | -A clippy::collapsible_if | ||
85 | -A clippy::needless_pass_by_value | ||
86 | -A clippy::nonminimal_bool | ||
87 | -A clippy::redundant_pattern_matching | ||
88 | " | ||
89 | .split_ascii_whitespace(); | ||
90 | cmd!("cargo clippy --all-features --all-targets -- {allowed_lints...}").run()?; | ||
91 | Ok(()) | ||
92 | } | ||
93 | |||
94 | pub fn run_fuzzer() -> Result<()> { | ||
95 | let _d = pushd("./crates/syntax")?; | ||
96 | let _e = pushenv("RUSTUP_TOOLCHAIN", "nightly"); | ||
97 | if cmd!("cargo fuzz --help").read().is_err() { | ||
98 | cmd!("cargo install cargo-fuzz").run()?; | ||
99 | }; | ||
100 | |||
101 | // Expecting nightly rustc | ||
102 | let out = cmd!("rustc --version").read()?; | ||
103 | if !out.contains("nightly") { | ||
104 | bail!("fuzz tests require nightly rustc") | ||
105 | } | ||
106 | |||
107 | cmd!("cargo fuzz run parser").run()?; | ||
108 | Ok(()) | ||
109 | } | ||
110 | |||
111 | fn date_iso() -> Result<String> { | ||
112 | let res = cmd!("date --iso --utc").read()?; | ||
113 | Ok(res) | ||
114 | } | ||
115 | |||
116 | fn is_release_tag(tag: &str) -> bool { | ||
117 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) | ||
118 | } | ||
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index dec48629c..e419db7a7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -7,57 +7,44 @@ | |||
7 | //! | 7 | //! |
8 | //! This binary is integrated into the `cargo` command line by using an alias in | 8 | //! This binary is integrated into the `cargo` command line by using an alias in |
9 | //! `.cargo/config`. | 9 | //! `.cargo/config`. |
10 | mod flags; | ||
10 | 11 | ||
11 | use std::env; | 12 | mod codegen; |
13 | mod ast_src; | ||
14 | #[cfg(test)] | ||
15 | mod tidy; | ||
12 | 16 | ||
13 | use codegen::CodegenCmd; | 17 | mod install; |
14 | use pico_args::Arguments; | 18 | mod release; |
15 | use xshell::{cmd, cp, pushd}; | 19 | mod dist; |
16 | use xtask::{ | 20 | mod metrics; |
17 | codegen::{self, Mode}, | 21 | mod pre_cache; |
22 | |||
23 | use anyhow::{bail, Result}; | ||
24 | use std::{ | ||
25 | env, | ||
26 | path::{Path, PathBuf}, | ||
27 | }; | ||
28 | use walkdir::{DirEntry, WalkDir}; | ||
29 | use xshell::{cmd, cp, pushd, pushenv}; | ||
30 | |||
31 | use crate::{ | ||
32 | codegen::Mode, | ||
18 | dist::DistCmd, | 33 | dist::DistCmd, |
19 | install::{InstallCmd, Malloc, ServerOpt}, | 34 | install::{InstallCmd, Malloc, ServerOpt}, |
20 | metrics::MetricsCmd, | ||
21 | pre_cache::PreCacheCmd, | ||
22 | pre_commit, project_root, | ||
23 | release::{PromoteCmd, ReleaseCmd}, | ||
24 | run_clippy, run_fuzzer, run_rustfmt, Result, | ||
25 | }; | 35 | }; |
26 | 36 | ||
27 | fn main() -> Result<()> { | 37 | fn main() -> Result<()> { |
28 | if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) { | ||
29 | return pre_commit::run_hook(); | ||
30 | } | ||
31 | |||
32 | let _d = pushd(project_root())?; | 38 | let _d = pushd(project_root())?; |
33 | 39 | ||
34 | let mut args = Arguments::from_env(); | 40 | let flags = flags::Xtask::from_env()?; |
35 | let subcommand = args.subcommand()?.unwrap_or_default(); | 41 | match flags.subcommand { |
36 | 42 | flags::XtaskCmd::Help(_) => { | |
37 | match subcommand.as_str() { | 43 | println!("{}", flags::Xtask::HELP); |
38 | "install" => { | 44 | return Ok(()); |
39 | if args.contains(["-h", "--help"]) { | 45 | } |
40 | eprintln!( | 46 | flags::XtaskCmd::Install(flags) => { |
41 | "\ | 47 | if flags.server && flags.client { |
42 | cargo xtask install | ||
43 | Install rust-analyzer server or editor plugin. | ||
44 | |||
45 | USAGE: | ||
46 | cargo xtask install [FLAGS] | ||
47 | |||
48 | FLAGS: | ||
49 | --client[=CLIENT] Install only VS Code plugin. | ||
50 | CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss' | ||
51 | --server Install only the language server | ||
52 | --mimalloc Use mimalloc for server | ||
53 | -h, --help Prints help information | ||
54 | " | ||
55 | ); | ||
56 | return Ok(()); | ||
57 | } | ||
58 | let server = args.contains("--server"); | ||
59 | let client_code = args.contains("--client"); | ||
60 | if server && client_code { | ||
61 | eprintln!( | 48 | eprintln!( |
62 | "error: The argument `--server` cannot be used with `--client`\n\n\ | 49 | "error: The argument `--server` cannot be used with `--client`\n\n\ |
63 | For more information try --help" | 50 | For more information try --help" |
@@ -65,93 +52,146 @@ FLAGS: | |||
65 | return Ok(()); | 52 | return Ok(()); |
66 | } | 53 | } |
67 | 54 | ||
68 | let malloc = | 55 | let malloc = if flags.mimalloc { |
69 | if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; | 56 | Malloc::Mimalloc |
57 | } else if flags.jemalloc { | ||
58 | Malloc::Jemalloc | ||
59 | } else { | ||
60 | Malloc::System | ||
61 | }; | ||
70 | 62 | ||
71 | let client_opt = args.opt_value_from_str("--client")?; | 63 | let client_bin = flags.code_bin.map(|it| it.parse()).transpose()?; |
72 | |||
73 | args.finish()?; | ||
74 | 64 | ||
75 | InstallCmd { | 65 | InstallCmd { |
76 | client: if server { None } else { Some(client_opt.unwrap_or_default()) }, | 66 | client: if flags.server { None } else { client_bin }, |
77 | server: if client_code { None } else { Some(ServerOpt { malloc }) }, | 67 | server: if flags.client { None } else { Some(ServerOpt { malloc }) }, |
78 | } | 68 | } |
79 | .run() | 69 | .run() |
80 | } | 70 | } |
81 | "codegen" => { | 71 | flags::XtaskCmd::Codegen(cmd) => cmd.run(), |
82 | let features = args.contains("--features"); | 72 | flags::XtaskCmd::Lint(_) => run_clippy(), |
83 | args.finish()?; | 73 | flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), |
84 | CodegenCmd { features }.run() | 74 | flags::XtaskCmd::PreCache(cmd) => cmd.run(), |
85 | } | 75 | flags::XtaskCmd::Release(cmd) => cmd.run(), |
86 | "format" => { | 76 | flags::XtaskCmd::Promote(cmd) => cmd.run(), |
87 | args.finish()?; | 77 | flags::XtaskCmd::Dist(flags) => { |
88 | run_rustfmt(Mode::Overwrite) | 78 | DistCmd { nightly: flags.nightly, client_version: flags.client }.run() |
89 | } | ||
90 | "install-pre-commit-hook" => { | ||
91 | args.finish()?; | ||
92 | pre_commit::install_hook() | ||
93 | } | 79 | } |
94 | "lint" => { | 80 | flags::XtaskCmd::Metrics(cmd) => cmd.run(), |
95 | args.finish()?; | 81 | flags::XtaskCmd::Bb(cmd) => { |
96 | run_clippy() | 82 | { |
97 | } | 83 | let _d = pushd("./crates/rust-analyzer")?; |
98 | "fuzz-tests" => { | 84 | cmd!("cargo build --release --features jemalloc").run()?; |
99 | args.finish()?; | 85 | } |
100 | run_fuzzer() | 86 | cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", cmd.suffix))?; |
101 | } | ||
102 | "pre-cache" => { | ||
103 | args.finish()?; | ||
104 | PreCacheCmd.run() | ||
105 | } | ||
106 | "release" => { | ||
107 | let dry_run = args.contains("--dry-run"); | ||
108 | args.finish()?; | ||
109 | ReleaseCmd { dry_run }.run() | ||
110 | } | ||
111 | "promote" => { | ||
112 | let dry_run = args.contains("--dry-run"); | ||
113 | args.finish()?; | ||
114 | PromoteCmd { dry_run }.run() | ||
115 | } | ||
116 | "dist" => { | ||
117 | let nightly = args.contains("--nightly"); | ||
118 | let client_version: Option<String> = args.opt_value_from_str("--client")?; | ||
119 | args.finish()?; | ||
120 | DistCmd { nightly, client_version }.run() | ||
121 | } | ||
122 | "metrics" => { | ||
123 | let dry_run = args.contains("--dry-run"); | ||
124 | args.finish()?; | ||
125 | MetricsCmd { dry_run }.run() | ||
126 | } | ||
127 | "bb" => { | ||
128 | let suffix: String = args.free_from_str()?.unwrap(); | ||
129 | args.finish()?; | ||
130 | cmd!("cargo build --release").run()?; | ||
131 | cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", suffix))?; | ||
132 | Ok(()) | ||
133 | } | ||
134 | _ => { | ||
135 | eprintln!( | ||
136 | "\ | ||
137 | cargo xtask | ||
138 | Run custom build command. | ||
139 | |||
140 | USAGE: | ||
141 | cargo xtask <SUBCOMMAND> | ||
142 | |||
143 | SUBCOMMANDS: | ||
144 | format | ||
145 | install-pre-commit-hook | ||
146 | fuzz-tests | ||
147 | codegen | ||
148 | install | ||
149 | lint | ||
150 | dist | ||
151 | promote | ||
152 | bb" | ||
153 | ); | ||
154 | Ok(()) | 87 | Ok(()) |
155 | } | 88 | } |
156 | } | 89 | } |
157 | } | 90 | } |
91 | |||
92 | fn project_root() -> PathBuf { | ||
93 | Path::new( | ||
94 | &env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()), | ||
95 | ) | ||
96 | .ancestors() | ||
97 | .nth(1) | ||
98 | .unwrap() | ||
99 | .to_path_buf() | ||
100 | } | ||
101 | |||
102 | fn rust_files() -> impl Iterator<Item = PathBuf> { | ||
103 | rust_files_in(&project_root().join("crates")) | ||
104 | } | ||
105 | |||
106 | #[cfg(test)] | ||
107 | fn cargo_files() -> impl Iterator<Item = PathBuf> { | ||
108 | files_in(&project_root(), "toml") | ||
109 | .filter(|path| path.file_name().map(|it| it == "Cargo.toml").unwrap_or(false)) | ||
110 | } | ||
111 | |||
112 | fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> { | ||
113 | files_in(path, "rs") | ||
114 | } | ||
115 | |||
116 | fn run_rustfmt(mode: Mode) -> Result<()> { | ||
117 | let _dir = pushd(project_root())?; | ||
118 | let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); | ||
119 | ensure_rustfmt()?; | ||
120 | let check = match mode { | ||
121 | Mode::Overwrite => &[][..], | ||
122 | Mode::Verify => &["--", "--check"], | ||
123 | }; | ||
124 | cmd!("cargo fmt {check...}").run()?; | ||
125 | Ok(()) | ||
126 | } | ||
127 | |||
128 | fn ensure_rustfmt() -> Result<()> { | ||
129 | let out = cmd!("rustfmt --version").read()?; | ||
130 | if !out.contains("stable") { | ||
131 | bail!( | ||
132 | "Failed to run rustfmt from toolchain 'stable'. \ | ||
133 | Please run `rustup component add rustfmt --toolchain stable` to install it.", | ||
134 | ) | ||
135 | } | ||
136 | Ok(()) | ||
137 | } | ||
138 | |||
139 | fn run_clippy() -> Result<()> { | ||
140 | if cmd!("cargo clippy --version").read().is_err() { | ||
141 | bail!( | ||
142 | "Failed run cargo clippy. \ | ||
143 | Please run `rustup component add clippy` to install it.", | ||
144 | ) | ||
145 | } | ||
146 | |||
147 | let allowed_lints = " | ||
148 | -A clippy::collapsible_if | ||
149 | -A clippy::needless_pass_by_value | ||
150 | -A clippy::nonminimal_bool | ||
151 | -A clippy::redundant_pattern_matching | ||
152 | " | ||
153 | .split_ascii_whitespace(); | ||
154 | cmd!("cargo clippy --all-features --all-targets -- {allowed_lints...}").run()?; | ||
155 | Ok(()) | ||
156 | } | ||
157 | |||
158 | fn run_fuzzer() -> Result<()> { | ||
159 | let _d = pushd("./crates/syntax")?; | ||
160 | let _e = pushenv("RUSTUP_TOOLCHAIN", "nightly"); | ||
161 | if cmd!("cargo fuzz --help").read().is_err() { | ||
162 | cmd!("cargo install cargo-fuzz").run()?; | ||
163 | }; | ||
164 | |||
165 | // Expecting nightly rustc | ||
166 | let out = cmd!("rustc --version").read()?; | ||
167 | if !out.contains("nightly") { | ||
168 | bail!("fuzz tests require nightly rustc") | ||
169 | } | ||
170 | |||
171 | cmd!("cargo fuzz run parser").run()?; | ||
172 | Ok(()) | ||
173 | } | ||
174 | |||
175 | fn date_iso() -> Result<String> { | ||
176 | let res = cmd!("date --iso --utc").read()?; | ||
177 | Ok(res) | ||
178 | } | ||
179 | |||
180 | fn is_release_tag(tag: &str) -> bool { | ||
181 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) | ||
182 | } | ||
183 | |||
184 | fn files_in(path: &Path, ext: &'static str) -> impl Iterator<Item = PathBuf> { | ||
185 | let iter = WalkDir::new(path); | ||
186 | return iter | ||
187 | .into_iter() | ||
188 | .filter_entry(|e| !is_hidden(e)) | ||
189 | .map(|e| e.unwrap()) | ||
190 | .filter(|e| !e.file_type().is_dir()) | ||
191 | .map(|e| e.into_path()) | ||
192 | .filter(move |path| path.extension().map(|it| it == ext).unwrap_or(false)); | ||
193 | |||
194 | fn is_hidden(entry: &DirEntry) -> bool { | ||
195 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | ||
196 | } | ||
197 | } | ||
diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs index 624ad3b7e..eb58b3274 100644 --- a/xtask/src/metrics.rs +++ b/xtask/src/metrics.rs | |||
@@ -9,14 +9,12 @@ use std::{ | |||
9 | use anyhow::{bail, format_err, Result}; | 9 | use anyhow::{bail, format_err, Result}; |
10 | use xshell::{cmd, mkdir_p, pushd, pushenv, read_file, rm_rf}; | 10 | use xshell::{cmd, mkdir_p, pushd, pushenv, read_file, rm_rf}; |
11 | 11 | ||
12 | type Unit = String; | 12 | use crate::flags; |
13 | 13 | ||
14 | pub struct MetricsCmd { | 14 | type Unit = String; |
15 | pub dry_run: bool, | ||
16 | } | ||
17 | 15 | ||
18 | impl MetricsCmd { | 16 | impl flags::Metrics { |
19 | pub fn run(self) -> Result<()> { | 17 | pub(crate) fn run(self) -> Result<()> { |
20 | let mut metrics = Metrics::new()?; | 18 | let mut metrics = Metrics::new()?; |
21 | if !self.dry_run { | 19 | if !self.dry_run { |
22 | rm_rf("./target/release")?; | 20 | rm_rf("./target/release")?; |
diff --git a/xtask/src/pre_cache.rs b/xtask/src/pre_cache.rs index 569f88f68..b456224fd 100644 --- a/xtask/src/pre_cache.rs +++ b/xtask/src/pre_cache.rs | |||
@@ -6,12 +6,12 @@ use std::{ | |||
6 | use anyhow::Result; | 6 | use anyhow::Result; |
7 | use xshell::rm_rf; | 7 | use xshell::rm_rf; |
8 | 8 | ||
9 | pub struct PreCacheCmd; | 9 | use crate::flags; |
10 | 10 | ||
11 | impl PreCacheCmd { | 11 | impl flags::PreCache { |
12 | /// Cleans the `./target` dir after the build such that only | 12 | /// Cleans the `./target` dir after the build such that only |
13 | /// dependencies are cached on CI. | 13 | /// dependencies are cached on CI. |
14 | pub fn run(self) -> Result<()> { | 14 | pub(crate) fn run(self) -> Result<()> { |
15 | let slow_tests_cookie = Path::new("./target/.slow_tests_cookie"); | 15 | let slow_tests_cookie = Path::new("./target/.slow_tests_cookie"); |
16 | if !slow_tests_cookie.exists() { | 16 | if !slow_tests_cookie.exists() { |
17 | panic!("slow tests were skipped on CI!") | 17 | panic!("slow tests were skipped on CI!") |
diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs deleted file mode 100644 index 8f2dbea19..000000000 --- a/xtask/src/pre_commit.rs +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | //! pre-commit hook for code formatting. | ||
2 | |||
3 | use std::{fs, path::PathBuf}; | ||
4 | |||
5 | use anyhow::{bail, Result}; | ||
6 | use xshell::cmd; | ||
7 | |||
8 | use crate::{project_root, run_rustfmt, Mode}; | ||
9 | |||
10 | // FIXME: if there are changed `.ts` files, also reformat TypeScript (by | ||
11 | // shelling out to `npm fmt`). | ||
12 | pub fn run_hook() -> Result<()> { | ||
13 | run_rustfmt(Mode::Overwrite)?; | ||
14 | |||
15 | let diff = cmd!("git diff --diff-filter=MAR --name-only --cached").read()?; | ||
16 | |||
17 | let root = project_root(); | ||
18 | for line in diff.lines() { | ||
19 | let file = root.join(line); | ||
20 | cmd!("git update-index --add {file}").run()?; | ||
21 | } | ||
22 | |||
23 | Ok(()) | ||
24 | } | ||
25 | |||
26 | pub fn install_hook() -> Result<()> { | ||
27 | let hook_path: PathBuf = | ||
28 | format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX).into(); | ||
29 | |||
30 | if hook_path.exists() { | ||
31 | bail!("Git hook already created"); | ||
32 | } | ||
33 | |||
34 | let me = std::env::current_exe()?; | ||
35 | fs::copy(me, hook_path)?; | ||
36 | |||
37 | Ok(()) | ||
38 | } | ||
diff --git a/xtask/src/release.rs b/xtask/src/release.rs index 2d716253e..d8d86fd63 100644 --- a/xtask/src/release.rs +++ b/xtask/src/release.rs | |||
@@ -1,13 +1,11 @@ | |||
1 | use xshell::{cmd, cp, pushd, read_dir, write_file}; | 1 | use std::fmt::Write; |
2 | 2 | ||
3 | use crate::{codegen, date_iso, is_release_tag, project_root, Mode, Result}; | 3 | use xshell::{cmd, cp, pushd, read_dir, write_file}; |
4 | 4 | ||
5 | pub struct ReleaseCmd { | 5 | use crate::{codegen, date_iso, flags, is_release_tag, project_root, Mode, Result}; |
6 | pub dry_run: bool, | ||
7 | } | ||
8 | 6 | ||
9 | impl ReleaseCmd { | 7 | impl flags::Release { |
10 | pub fn run(self) -> Result<()> { | 8 | pub(crate) fn run(self) -> Result<()> { |
11 | if !self.dry_run { | 9 | if !self.dry_run { |
12 | cmd!("git switch release").run()?; | 10 | cmd!("git switch release").run()?; |
13 | cmd!("git fetch upstream --tags --force").run()?; | 11 | cmd!("git fetch upstream --tags --force").run()?; |
@@ -24,6 +22,34 @@ impl ReleaseCmd { | |||
24 | let commit = cmd!("git rev-parse HEAD").read()?; | 22 | let commit = cmd!("git rev-parse HEAD").read()?; |
25 | let changelog_n = read_dir(changelog_dir.as_path())?.len(); | 23 | let changelog_n = read_dir(changelog_dir.as_path())?.len(); |
26 | 24 | ||
25 | for &adoc in [ | ||
26 | "manual.adoc", | ||
27 | "generated_assists.adoc", | ||
28 | "generated_config.adoc", | ||
29 | "generated_diagnostic.adoc", | ||
30 | "generated_features.adoc", | ||
31 | ] | ||
32 | .iter() | ||
33 | { | ||
34 | let src = project_root().join("./docs/user/").join(adoc); | ||
35 | let dst = website_root.join(adoc); | ||
36 | cp(src, dst)?; | ||
37 | } | ||
38 | |||
39 | let tags = cmd!("git tag --list").read()?; | ||
40 | let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap(); | ||
41 | |||
42 | let git_log = cmd!("git log {prev_tag}..HEAD --merges --reverse").read()?; | ||
43 | let mut git_log_summary = String::new(); | ||
44 | for line in git_log.lines() { | ||
45 | let line = line.trim_start(); | ||
46 | if let Some(p) = line.find(':') { | ||
47 | if let Ok(pr) = line[..p].parse::<u32>() { | ||
48 | writeln!(git_log_summary, "* pr:{}[]{}", pr, &line[p + 1..]).unwrap(); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
27 | let contents = format!( | 53 | let contents = format!( |
28 | "\ | 54 | "\ |
29 | = Changelog #{} | 55 | = Changelog #{} |
@@ -40,49 +66,24 @@ https://github.com/sponsors/rust-analyzer[GitHub Sponsors]. | |||
40 | 66 | ||
41 | == New Features | 67 | == New Features |
42 | 68 | ||
43 | * pr:[] . | 69 | {} |
44 | 70 | ||
45 | == Fixes | 71 | == Fixes |
46 | 72 | ||
47 | == Internal Improvements | 73 | == Internal Improvements |
48 | ", | 74 | ", |
49 | changelog_n, commit, today | 75 | changelog_n, commit, today, git_log_summary |
50 | ); | 76 | ); |
51 | 77 | ||
52 | let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); | 78 | let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); |
53 | write_file(&path, &contents)?; | 79 | write_file(&path, &contents)?; |
54 | 80 | ||
55 | for &adoc in [ | ||
56 | "manual.adoc", | ||
57 | "generated_assists.adoc", | ||
58 | "generated_config.adoc", | ||
59 | "generated_diagnostic.adoc", | ||
60 | "generated_features.adoc", | ||
61 | ] | ||
62 | .iter() | ||
63 | { | ||
64 | let src = project_root().join("./docs/user/").join(adoc); | ||
65 | let dst = website_root.join(adoc); | ||
66 | cp(src, dst)?; | ||
67 | } | ||
68 | |||
69 | let tags = cmd!("git tag --list").read()?; | ||
70 | let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap(); | ||
71 | |||
72 | let git_log = cmd!("git log {prev_tag}..HEAD --merges --reverse").read()?; | ||
73 | let git_log_dst = website_root.join("git.log"); | ||
74 | write_file(git_log_dst, &git_log)?; | ||
75 | |||
76 | Ok(()) | 81 | Ok(()) |
77 | } | 82 | } |
78 | } | 83 | } |
79 | 84 | ||
80 | pub struct PromoteCmd { | 85 | impl flags::Promote { |
81 | pub dry_run: bool, | 86 | pub(crate) fn run(self) -> Result<()> { |
82 | } | ||
83 | |||
84 | impl PromoteCmd { | ||
85 | pub fn run(self) -> Result<()> { | ||
86 | let _dir = pushd("../rust-rust-analyzer")?; | 87 | let _dir = pushd("../rust-rust-analyzer")?; |
87 | cmd!("git switch master").run()?; | 88 | cmd!("git switch master").run()?; |
88 | cmd!("git fetch upstream").run()?; | 89 | cmd!("git fetch upstream").run()?; |
@@ -99,7 +100,7 @@ impl PromoteCmd { | |||
99 | cmd!("git add src/tools/rust-analyzer").run()?; | 100 | cmd!("git add src/tools/rust-analyzer").run()?; |
100 | cmd!("git commit -m':arrow_up: rust-analyzer'").run()?; | 101 | cmd!("git commit -m':arrow_up: rust-analyzer'").run()?; |
101 | if !self.dry_run { | 102 | if !self.dry_run { |
102 | cmd!("git push").run()?; | 103 | cmd!("git push -u").run()?; |
103 | cmd!("xdg-open https://github.com/matklad/rust/pull/new/{branch}?body=r%3F%20%40ghost") | 104 | cmd!("xdg-open https://github.com/matklad/rust/pull/new/{branch}?body=r%3F%20%40ghost") |
104 | .run()?; | 105 | .run()?; |
105 | } | 106 | } |
diff --git a/xtask/tests/tidy.rs b/xtask/src/tidy.rs index 6abad189a..349ca14d0 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/src/tidy.rs | |||
@@ -4,7 +4,9 @@ use std::{ | |||
4 | }; | 4 | }; |
5 | 5 | ||
6 | use xshell::{cmd, read_file}; | 6 | use xshell::{cmd, read_file}; |
7 | use xtask::{ | 7 | |
8 | use crate::{ | ||
9 | cargo_files, | ||
8 | codegen::{self, Mode}, | 10 | codegen::{self, Mode}, |
9 | project_root, run_rustfmt, rust_files, | 11 | project_root, run_rustfmt, rust_files, |
10 | }; | 12 | }; |
@@ -82,7 +84,7 @@ Please adjust docs/dev/lsp-extensions.md. | |||
82 | #[test] | 84 | #[test] |
83 | fn rust_files_are_tidy() { | 85 | fn rust_files_are_tidy() { |
84 | let mut tidy_docs = TidyDocs::default(); | 86 | let mut tidy_docs = TidyDocs::default(); |
85 | for path in rust_files(&project_root().join("crates")) { | 87 | for path in rust_files() { |
86 | let text = read_file(&path).unwrap(); | 88 | let text = read_file(&path).unwrap(); |
87 | check_todo(&path, &text); | 89 | check_todo(&path, &text); |
88 | check_dbg(&path, &text); | 90 | check_dbg(&path, &text); |
@@ -94,6 +96,55 @@ fn rust_files_are_tidy() { | |||
94 | } | 96 | } |
95 | 97 | ||
96 | #[test] | 98 | #[test] |
99 | fn cargo_files_are_tidy() { | ||
100 | for cargo in cargo_files() { | ||
101 | let mut section = None; | ||
102 | for (line_no, text) in read_file(&cargo).unwrap().lines().enumerate() { | ||
103 | let text = text.trim(); | ||
104 | if text.starts_with('[') { | ||
105 | if !text.ends_with(']') { | ||
106 | panic!( | ||
107 | "\nplease don't add comments or trailing whitespace in section lines.\n\ | ||
108 | {}:{}\n", | ||
109 | cargo.display(), | ||
110 | line_no + 1 | ||
111 | ) | ||
112 | } | ||
113 | section = Some(text); | ||
114 | continue; | ||
115 | } | ||
116 | let text: String = text.split_whitespace().collect(); | ||
117 | if !text.contains("path=") { | ||
118 | continue; | ||
119 | } | ||
120 | match section { | ||
121 | Some(s) if s.contains("dev-dependencies") => { | ||
122 | if text.contains("version") { | ||
123 | panic!( | ||
124 | "\ncargo internal dev-dependencies should not have a version.\n\ | ||
125 | {}:{}\n", | ||
126 | cargo.display(), | ||
127 | line_no + 1 | ||
128 | ); | ||
129 | } | ||
130 | } | ||
131 | Some(s) if s.contains("dependencies") => { | ||
132 | if !text.contains("version") { | ||
133 | panic!( | ||
134 | "\ncargo internal dependencies should have a version.\n\ | ||
135 | {}:{}\n", | ||
136 | cargo.display(), | ||
137 | line_no + 1 | ||
138 | ); | ||
139 | } | ||
140 | } | ||
141 | _ => {} | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | #[test] | ||
97 | fn check_merge_commits() { | 148 | fn check_merge_commits() { |
98 | let stdout = cmd!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19..") | 149 | let stdout = cmd!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19..") |
99 | .read() | 150 | .read() |
@@ -145,7 +196,7 @@ https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/#redo-after- | |||
145 | fn deny_clippy(path: &PathBuf, text: &String) { | 196 | fn deny_clippy(path: &PathBuf, text: &String) { |
146 | let ignore = &[ | 197 | let ignore = &[ |
147 | // The documentation in string literals may contain anything for its own purposes | 198 | // The documentation in string literals may contain anything for its own purposes |
148 | "completion/src/generated_lint_completions.rs", | 199 | "ide_completion/src/generated_lint_completions.rs", |
149 | ]; | 200 | ]; |
150 | if ignore.iter().any(|p| path.ends_with(p)) { | 201 | if ignore.iter().any(|p| path.ends_with(p)) { |
151 | return; | 202 | return; |
@@ -171,7 +222,6 @@ fn check_licenses() { | |||
171 | Apache-2.0 | 222 | Apache-2.0 |
172 | Apache-2.0 OR BSL-1.0 | 223 | Apache-2.0 OR BSL-1.0 |
173 | Apache-2.0 OR MIT | 224 | Apache-2.0 OR MIT |
174 | Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT | ||
175 | Apache-2.0/MIT | 225 | Apache-2.0/MIT |
176 | BSD-3-Clause | 226 | BSD-3-Clause |
177 | CC0-1.0 | 227 | CC0-1.0 |
@@ -232,7 +282,7 @@ fn check_todo(path: &Path, text: &str) { | |||
232 | // `ast::make`. | 282 | // `ast::make`. |
233 | "ast/make.rs", | 283 | "ast/make.rs", |
234 | // The documentation in string literals may contain anything for its own purposes | 284 | // The documentation in string literals may contain anything for its own purposes |
235 | "completion/src/generated_lint_completions.rs", | 285 | "ide_completion/src/generated_lint_completions.rs", |
236 | ]; | 286 | ]; |
237 | if need_todo.iter().any(|p| path.ends_with(p)) { | 287 | if need_todo.iter().any(|p| path.ends_with(p)) { |
238 | return; | 288 | return; |
@@ -259,10 +309,10 @@ fn check_dbg(path: &Path, text: &str) { | |||
259 | // Assists to remove `dbg!()` | 309 | // Assists to remove `dbg!()` |
260 | "handlers/remove_dbg.rs", | 310 | "handlers/remove_dbg.rs", |
261 | // We have .dbg postfix | 311 | // We have .dbg postfix |
262 | "completion/src/completions/postfix.rs", | 312 | "ide_completion/src/completions/postfix.rs", |
263 | // The documentation in string literals may contain anything for its own purposes | 313 | // The documentation in string literals may contain anything for its own purposes |
264 | "completion/src/lib.rs", | 314 | "ide_completion/src/lib.rs", |
265 | "completion/src/generated_lint_completions.rs", | 315 | "ide_completion/src/generated_lint_completions.rs", |
266 | // test for doc test for remove_dbg | 316 | // test for doc test for remove_dbg |
267 | "src/tests/generated.rs", | 317 | "src/tests/generated.rs", |
268 | ]; | 318 | ]; |