aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
Diffstat (limited to 'xtask')
-rw-r--r--xtask/Cargo.toml4
-rw-r--r--xtask/src/ast_src.rs1
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs4
-rw-r--r--xtask/src/codegen/gen_diagnostic_docs.rs2
-rw-r--r--xtask/src/codegen/gen_feature_docs.rs2
-rw-r--r--xtask/src/install.rs2
-rw-r--r--xtask/src/lib.rs6
-rw-r--r--xtask/src/main.rs46
-rw-r--r--xtask/tests/tidy.rs2
9 files changed, 45 insertions, 24 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 1bb9222d7..4e6b439fd 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -12,10 +12,10 @@ doctest = false
12[dependencies] 12[dependencies]
13anyhow = "1.0.26" 13anyhow = "1.0.26"
14flate2 = "1.0" 14flate2 = "1.0"
15pico-args = "0.3.1" 15pico-args = "0.4.0"
16proc-macro2 = "1.0.8" 16proc-macro2 = "1.0.8"
17quote = "1.0.2" 17quote = "1.0.2"
18ungrammar = "1.8" 18ungrammar = "1.9"
19walkdir = "2.3.1" 19walkdir = "2.3.1"
20write-json = "0.1.0" 20write-json = "0.1.0"
21xshell = "0.1" 21xshell = "0.1"
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index 046d68f52..0fd1d13e6 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -104,6 +104,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
104 "MACRO_DEF", 104 "MACRO_DEF",
105 "PAREN_TYPE", 105 "PAREN_TYPE",
106 "TUPLE_TYPE", 106 "TUPLE_TYPE",
107 "MACRO_TYPE",
107 "NEVER_TYPE", 108 "NEVER_TYPE",
108 "PATH_TYPE", 109 "PATH_TYPE",
109 "PTR_TYPE", 110 "PTR_TYPE",
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs
index 6e18a50a6..51f58180c 100644
--- a/xtask/src/codegen/gen_assists_docs.rs
+++ b/xtask/src/codegen/gen_assists_docs.rs
@@ -4,7 +4,7 @@ use std::{fmt, path::Path};
4 4
5use crate::{ 5use 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
10pub fn generate_assists_tests(mode: Mode) -> Result<()> { 10pub fn generate_assists_tests(mode: Mode) -> Result<()> {
@@ -32,7 +32,7 @@ struct Assist {
32impl Assist { 32impl 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/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));
diff --git a/xtask/src/codegen/gen_diagnostic_docs.rs b/xtask/src/codegen/gen_diagnostic_docs.rs
index 00aaea5b7..7c14d4a07 100644
--- a/xtask/src/codegen/gen_diagnostic_docs.rs
+++ b/xtask/src/codegen/gen_diagnostic_docs.rs
@@ -27,7 +27,7 @@ struct Diagnostic {
27impl Diagnostic { 27impl 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..61081063b 100644
--- a/xtask/src/codegen/gen_feature_docs.rs
+++ b/xtask/src/codegen/gen_feature_docs.rs
@@ -26,7 +26,7 @@ struct Feature {
26impl Feature { 26impl 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/install.rs b/xtask/src/install.rs
index 12962bcfa..202c74426 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -67,6 +67,7 @@ pub struct ServerOpt {
67pub enum Malloc { 67pub enum Malloc {
68 System, 68 System,
69 Mimalloc, 69 Mimalloc,
70 Jemalloc,
70} 71}
71 72
72impl InstallCmd { 73impl InstallCmd {
@@ -176,6 +177,7 @@ 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...}");
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index babec2dbd..16b06b853 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -34,7 +34,11 @@ pub fn project_root() -> PathBuf {
34 .to_path_buf() 34 .to_path_buf()
35} 35}
36 36
37pub fn rust_files(path: &Path) -> impl Iterator<Item = PathBuf> { 37pub fn rust_files() -> impl Iterator<Item = PathBuf> {
38 rust_files_in(&project_root().join("crates"))
39}
40
41pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> {
38 let iter = WalkDir::new(path); 42 let iter = WalkDir::new(path);
39 return iter 43 return iter
40 .into_iter() 44 .into_iter()
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index dec48629c..5a99f4a76 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -10,6 +10,7 @@
10 10
11use std::env; 11use std::env;
12 12
13use anyhow::bail;
13use codegen::CodegenCmd; 14use codegen::CodegenCmd;
14use pico_args::Arguments; 15use pico_args::Arguments;
15use xshell::{cmd, cp, pushd}; 16use xshell::{cmd, cp, pushd};
@@ -49,7 +50,8 @@ FLAGS:
49 --client[=CLIENT] Install only VS Code plugin. 50 --client[=CLIENT] Install only VS Code plugin.
50 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss' 51 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
51 --server Install only the language server 52 --server Install only the language server
52 --mimalloc Use mimalloc for server 53 --mimalloc Use mimalloc allocator for server
54 --jemalloc Use jemalloc allocator for server
53 -h, --help Prints help information 55 -h, --help Prints help information
54 " 56 "
55 ); 57 );
@@ -65,12 +67,17 @@ FLAGS:
65 return Ok(()); 67 return Ok(());
66 } 68 }
67 69
68 let malloc = 70 let malloc = if args.contains("--mimalloc") {
69 if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; 71 Malloc::Mimalloc
72 } else if args.contains("--jemalloc") {
73 Malloc::Jemalloc
74 } else {
75 Malloc::System
76 };
70 77
71 let client_opt = args.opt_value_from_str("--client")?; 78 let client_opt = args.opt_value_from_str("--client")?;
72 79
73 args.finish()?; 80 finish_args(args)?;
74 81
75 InstallCmd { 82 InstallCmd {
76 client: if server { None } else { Some(client_opt.unwrap_or_default()) }, 83 client: if server { None } else { Some(client_opt.unwrap_or_default()) },
@@ -80,53 +87,53 @@ FLAGS:
80 } 87 }
81 "codegen" => { 88 "codegen" => {
82 let features = args.contains("--features"); 89 let features = args.contains("--features");
83 args.finish()?; 90 finish_args(args)?;
84 CodegenCmd { features }.run() 91 CodegenCmd { features }.run()
85 } 92 }
86 "format" => { 93 "format" => {
87 args.finish()?; 94 finish_args(args)?;
88 run_rustfmt(Mode::Overwrite) 95 run_rustfmt(Mode::Overwrite)
89 } 96 }
90 "install-pre-commit-hook" => { 97 "install-pre-commit-hook" => {
91 args.finish()?; 98 finish_args(args)?;
92 pre_commit::install_hook() 99 pre_commit::install_hook()
93 } 100 }
94 "lint" => { 101 "lint" => {
95 args.finish()?; 102 finish_args(args)?;
96 run_clippy() 103 run_clippy()
97 } 104 }
98 "fuzz-tests" => { 105 "fuzz-tests" => {
99 args.finish()?; 106 finish_args(args)?;
100 run_fuzzer() 107 run_fuzzer()
101 } 108 }
102 "pre-cache" => { 109 "pre-cache" => {
103 args.finish()?; 110 finish_args(args)?;
104 PreCacheCmd.run() 111 PreCacheCmd.run()
105 } 112 }
106 "release" => { 113 "release" => {
107 let dry_run = args.contains("--dry-run"); 114 let dry_run = args.contains("--dry-run");
108 args.finish()?; 115 finish_args(args)?;
109 ReleaseCmd { dry_run }.run() 116 ReleaseCmd { dry_run }.run()
110 } 117 }
111 "promote" => { 118 "promote" => {
112 let dry_run = args.contains("--dry-run"); 119 let dry_run = args.contains("--dry-run");
113 args.finish()?; 120 finish_args(args)?;
114 PromoteCmd { dry_run }.run() 121 PromoteCmd { dry_run }.run()
115 } 122 }
116 "dist" => { 123 "dist" => {
117 let nightly = args.contains("--nightly"); 124 let nightly = args.contains("--nightly");
118 let client_version: Option<String> = args.opt_value_from_str("--client")?; 125 let client_version: Option<String> = args.opt_value_from_str("--client")?;
119 args.finish()?; 126 finish_args(args)?;
120 DistCmd { nightly, client_version }.run() 127 DistCmd { nightly, client_version }.run()
121 } 128 }
122 "metrics" => { 129 "metrics" => {
123 let dry_run = args.contains("--dry-run"); 130 let dry_run = args.contains("--dry-run");
124 args.finish()?; 131 finish_args(args)?;
125 MetricsCmd { dry_run }.run() 132 MetricsCmd { dry_run }.run()
126 } 133 }
127 "bb" => { 134 "bb" => {
128 let suffix: String = args.free_from_str()?.unwrap(); 135 let suffix: String = args.free_from_str()?;
129 args.finish()?; 136 finish_args(args)?;
130 cmd!("cargo build --release").run()?; 137 cmd!("cargo build --release").run()?;
131 cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", suffix))?; 138 cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", suffix))?;
132 Ok(()) 139 Ok(())
@@ -155,3 +162,10 @@ SUBCOMMANDS:
155 } 162 }
156 } 163 }
157} 164}
165
166fn finish_args(args: Arguments) -> Result<()> {
167 if !args.finish().is_empty() {
168 bail!("Unused arguments.");
169 }
170 Ok(())
171}
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index 6abad189a..9a6933b09 100644
--- a/xtask/tests/tidy.rs
+++ b/xtask/tests/tidy.rs
@@ -82,7 +82,7 @@ Please adjust docs/dev/lsp-extensions.md.
82#[test] 82#[test]
83fn rust_files_are_tidy() { 83fn rust_files_are_tidy() {
84 let mut tidy_docs = TidyDocs::default(); 84 let mut tidy_docs = TidyDocs::default();
85 for path in rust_files(&project_root().join("crates")) { 85 for path in rust_files() {
86 let text = read_file(&path).unwrap(); 86 let text = read_file(&path).unwrap();
87 check_todo(&path, &text); 87 check_todo(&path, &text);
88 check_dbg(&path, &text); 88 check_dbg(&path, &text);