aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen.rs34
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs6
-rw-r--r--xtask/src/codegen/gen_feature_docs.rs4
-rw-r--r--xtask/src/codegen/gen_syntax.rs10
-rw-r--r--xtask/src/lib.rs15
5 files changed, 37 insertions, 32 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index f5f4b964a..98acd7fa6 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -15,7 +15,11 @@ use std::{
15 path::{Path, PathBuf}, 15 path::{Path, PathBuf},
16}; 16};
17 17
18use crate::{not_bash::fs2, project_root, Result}; 18use crate::{
19 ensure_rustfmt,
20 not_bash::{fs2, pushenv, run},
21 project_root, Result,
22};
19 23
20pub use self::{ 24pub use self::{
21 gen_assists_docs::{generate_assists_docs, generate_assists_tests}, 25 gen_assists_docs::{generate_assists_docs, generate_assists_tests},
@@ -24,16 +28,16 @@ pub use self::{
24 gen_syntax::generate_syntax, 28 gen_syntax::generate_syntax,
25}; 29};
26 30
27const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 31const GRAMMAR_DIR: &str = "crates/parser/src/grammar";
28const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok"; 32const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok";
29const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; 33const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err";
30 34
31const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs"; 35const SYNTAX_KINDS: &str = "crates/parser/src/syntax_kind/generated.rs";
32const AST_NODES: &str = "crates/ra_syntax/src/ast/generated/nodes.rs"; 36const AST_NODES: &str = "crates/syntax/src/ast/generated/nodes.rs";
33const AST_TOKENS: &str = "crates/ra_syntax/src/ast/generated/tokens.rs"; 37const AST_TOKENS: &str = "crates/syntax/src/ast/generated/tokens.rs";
34 38
35const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers"; 39const ASSISTS_DIR: &str = "crates/assists/src/handlers";
36const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs"; 40const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs";
37 41
38#[derive(Debug, PartialEq, Eq, Clone, Copy)] 42#[derive(Debug, PartialEq, Eq, Clone, Copy)]
39pub enum Mode { 43pub enum Mode {
@@ -62,6 +66,18 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
62 } 66 }
63} 67}
64 68
69const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`";
70
71fn reformat(text: impl std::fmt::Display) -> Result<String> {
72 let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
73 ensure_rustfmt()?;
74 let stdout = run!(
75 "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display();
76 <text.to_string().as_bytes()
77 )?;
78 Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout))
79}
80
65fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { 81fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
66 do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect() 82 do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect()
67} 83}
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs
index 526941f73..4f4968594 100644
--- a/xtask/src/codegen/gen_assists_docs.rs
+++ b/xtask/src/codegen/gen_assists_docs.rs
@@ -3,7 +3,7 @@
3use std::{fmt, fs, path::Path}; 3use std::{fmt, fs, path::Path};
4 4
5use crate::{ 5use crate::{
6 codegen::{self, extract_comment_blocks_with_empty_lines, Location, Mode}, 6 codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, Mode, PREAMBLE},
7 project_root, rust_files, Result, 7 project_root, rust_files, Result,
8}; 8};
9 9
@@ -15,7 +15,7 @@ pub fn generate_assists_tests(mode: Mode) -> Result<()> {
15pub fn generate_assists_docs(mode: Mode) -> Result<()> { 15pub 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 = contents.trim().to_string() + "\n"; 18 let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim());
19 let dst = project_root().join("docs/user/generated_assists.adoc"); 19 let dst = project_root().join("docs/user/generated_assists.adoc");
20 codegen::update(&dst, &contents, mode) 20 codegen::update(&dst, &contents, mode)
21} 21}
@@ -134,7 +134,7 @@ r#####"
134 134
135 buf.push_str(&test) 135 buf.push_str(&test)
136 } 136 }
137 let buf = crate::reformat(buf)?; 137 let buf = reformat(buf)?;
138 codegen::update(&project_root().join(codegen::ASSISTS_TESTS), &buf, mode) 138 codegen::update(&project_root().join(codegen::ASSISTS_TESTS), &buf, mode)
139} 139}
140 140
diff --git a/xtask/src/codegen/gen_feature_docs.rs b/xtask/src/codegen/gen_feature_docs.rs
index 31bc3839d..3f0013e82 100644
--- a/xtask/src/codegen/gen_feature_docs.rs
+++ b/xtask/src/codegen/gen_feature_docs.rs
@@ -3,14 +3,14 @@
3use std::{fmt, fs, path::PathBuf}; 3use std::{fmt, fs, path::PathBuf};
4 4
5use crate::{ 5use crate::{
6 codegen::{self, extract_comment_blocks_with_empty_lines, Location, Mode}, 6 codegen::{self, extract_comment_blocks_with_empty_lines, Location, Mode, PREAMBLE},
7 project_root, rust_files, Result, 7 project_root, rust_files, Result,
8}; 8};
9 9
10pub fn generate_feature_docs(mode: Mode) -> Result<()> { 10pub 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 = contents.trim().to_string() + "\n"; 13 let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim());
14 let dst = project_root().join("docs/user/generated_features.adoc"); 14 let dst = project_root().join("docs/user/generated_features.adoc");
15 codegen::update(&dst, &contents, mode)?; 15 codegen::update(&dst, &contents, mode)?;
16 Ok(()) 16 Ok(())
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index cafad8070..df3ec22c8 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -1,7 +1,7 @@
1//! This module generates AST datatype used by rust-analyzer. 1//! This module generates AST datatype used by rust-analyzer.
2//! 2//!
3//! Specifically, it generates the `SyntaxKind` enum and a number of newtype 3//! Specifically, it generates the `SyntaxKind` enum and a number of newtype
4//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. 4//! wrappers around `SyntaxNode` which implement `syntax::AstNode`.
5 5
6use std::{ 6use std::{
7 collections::{BTreeSet, HashSet}, 7 collections::{BTreeSet, HashSet},
@@ -14,7 +14,7 @@ use ungrammar::{rust_grammar, Grammar, Rule};
14 14
15use crate::{ 15use crate::{
16 ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Cardinality, Field, KindsSrc, KINDS_SRC}, 16 ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Cardinality, Field, KindsSrc, KINDS_SRC},
17 codegen::{self, update, Mode}, 17 codegen::{self, reformat, update, Mode},
18 project_root, Result, 18 project_root, Result,
19}; 19};
20 20
@@ -61,7 +61,7 @@ fn generate_tokens(grammar: &AstSrc) -> Result<String> {
61 } 61 }
62 }); 62 });
63 63
64 let pretty = crate::reformat(quote! { 64 let pretty = reformat(quote! {
65 use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken}; 65 use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken};
66 #(#tokens)* 66 #(#tokens)*
67 })? 67 })?
@@ -261,7 +261,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
261 } 261 }
262 } 262 }
263 263
264 let pretty = crate::reformat(res)?; 264 let pretty = reformat(res)?;
265 Ok(pretty) 265 Ok(pretty)
266} 266}
267 267
@@ -383,7 +383,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> {
383 } 383 }
384 }; 384 };
385 385
386 crate::reformat(ast) 386 reformat(ast)
387} 387}
388 388
389fn to_upper_snake_case(s: &str) -> String { 389fn to_upper_snake_case(s: &str) -> String {
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 2fdb08f2e..f3ad81ba7 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -62,17 +62,6 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> {
62 Ok(()) 62 Ok(())
63} 63}
64 64
65fn reformat(text: impl std::fmt::Display) -> Result<String> {
66 let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
67 ensure_rustfmt()?;
68 let stdout = run!(
69 "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display();
70 <text.to_string().as_bytes()
71 )?;
72 let preamble = "Generated file, do not edit by hand, see `xtask/src/codegen`";
73 Ok(format!("//! {}\n\n{}\n", preamble, stdout))
74}
75
76fn ensure_rustfmt() -> Result<()> { 65fn ensure_rustfmt() -> Result<()> {
77 let out = run!("rustfmt --version")?; 66 let out = run!("rustfmt --version")?;
78 if !out.contains("stable") { 67 if !out.contains("stable") {
@@ -103,7 +92,7 @@ pub fn run_clippy() -> Result<()> {
103} 92}
104 93
105pub fn run_fuzzer() -> Result<()> { 94pub fn run_fuzzer() -> Result<()> {
106 let _d = pushd("./crates/ra_syntax"); 95 let _d = pushd("./crates/syntax");
107 let _e = pushenv("RUSTUP_TOOLCHAIN", "nightly"); 96 let _e = pushenv("RUSTUP_TOOLCHAIN", "nightly");
108 if run!("cargo fuzz --help").is_err() { 97 if run!("cargo fuzz --help").is_err() {
109 run!("cargo install cargo-fuzz")?; 98 run!("cargo install cargo-fuzz")?;
@@ -139,7 +128,7 @@ pub fn run_pre_cache() -> Result<()> {
139 } 128 }
140 129
141 fs2::remove_file("./target/.rustc_info.json")?; 130 fs2::remove_file("./target/.rustc_info.json")?;
142 let to_delete = ["ra_", "heavy_test", "xtask"]; 131 let to_delete = ["hir", "heavy_test", "xtask", "ide", "rust-analyzer"];
143 for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { 132 for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
144 for entry in Path::new(dir).read_dir()? { 133 for entry in Path::new(dir).read_dir()? {
145 let entry = entry?; 134 let entry = entry?;