diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/codegen.rs | 9 | ||||
-rw-r--r-- | xtask/src/codegen/gen_unstable_future_descriptor.rs | 61 | ||||
-rw-r--r-- | xtask/src/main.rs | 1 | ||||
-rw-r--r-- | xtask/tests/tidy.rs | 2 |
4 files changed, 73 insertions, 0 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 98acd7fa6..c468468de 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -9,6 +9,7 @@ mod gen_syntax; | |||
9 | mod gen_parser_tests; | 9 | mod gen_parser_tests; |
10 | mod gen_assists_docs; | 10 | mod gen_assists_docs; |
11 | mod gen_feature_docs; | 11 | mod gen_feature_docs; |
12 | mod gen_unstable_future_descriptor; | ||
12 | 13 | ||
13 | use std::{ | 14 | use std::{ |
14 | fmt, mem, | 15 | fmt, mem, |
@@ -26,8 +27,12 @@ pub use self::{ | |||
26 | gen_feature_docs::generate_feature_docs, | 27 | gen_feature_docs::generate_feature_docs, |
27 | gen_parser_tests::generate_parser_tests, | 28 | gen_parser_tests::generate_parser_tests, |
28 | gen_syntax::generate_syntax, | 29 | gen_syntax::generate_syntax, |
30 | gen_unstable_future_descriptor::generate_unstable_future_descriptor, | ||
29 | }; | 31 | }; |
30 | 32 | ||
33 | // Directory used by xtask | ||
34 | const STORAGE: &str = ".xtask"; | ||
35 | |||
31 | const GRAMMAR_DIR: &str = "crates/parser/src/grammar"; | 36 | const GRAMMAR_DIR: &str = "crates/parser/src/grammar"; |
32 | const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok"; | 37 | const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok"; |
33 | const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err"; | 38 | const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err"; |
@@ -39,6 +44,10 @@ const AST_TOKENS: &str = "crates/syntax/src/ast/generated/tokens.rs"; | |||
39 | const ASSISTS_DIR: &str = "crates/assists/src/handlers"; | 44 | const ASSISTS_DIR: &str = "crates/assists/src/handlers"; |
40 | const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs"; | 45 | const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs"; |
41 | 46 | ||
47 | const REPOSITORY_URL: &str = "https://github.com/rust-lang/rust"; | ||
48 | const UNSTABLE_FEATURE: &str = "crates/ide/src/completion/unstable_feature_descriptor.rs"; | ||
49 | const REPO_PATH: &str = "src/doc/unstable-book/src"; | ||
50 | |||
42 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 51 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
43 | pub enum Mode { | 52 | pub enum Mode { |
44 | Overwrite, | 53 | Overwrite, |
diff --git a/xtask/src/codegen/gen_unstable_future_descriptor.rs b/xtask/src/codegen/gen_unstable_future_descriptor.rs new file mode 100644 index 000000000..907a9afae --- /dev/null +++ b/xtask/src/codegen/gen_unstable_future_descriptor.rs | |||
@@ -0,0 +1,61 @@ | |||
1 | //! Generates descriptors structure for unstable feature from Unstable Book | ||
2 | |||
3 | use crate::codegen::{self, project_root, Mode, Result}; | ||
4 | use crate::codegen::{reformat, update}; | ||
5 | use crate::not_bash::{fs2, pushd, run}; | ||
6 | use proc_macro2::TokenStream; | ||
7 | use quote::quote; | ||
8 | use std::path::PathBuf; | ||
9 | use walkdir::WalkDir; | ||
10 | |||
11 | fn generate_descriptor(src_dir: PathBuf) -> Result<TokenStream> { | ||
12 | let files = WalkDir::new(src_dir.join("language-features")) | ||
13 | .into_iter() | ||
14 | .chain(WalkDir::new(src_dir.join("library-features"))) | ||
15 | .filter_map(|e| e.ok()) | ||
16 | .filter(|entry| { | ||
17 | // Get all `.md ` files | ||
18 | entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md" | ||
19 | }) | ||
20 | .collect::<Vec<_>>(); | ||
21 | |||
22 | let definitions = files | ||
23 | .iter() | ||
24 | .map(|entry| { | ||
25 | let path = entry.path(); | ||
26 | let feature_ident = | ||
27 | format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_")); | ||
28 | let doc = format!("{}", std::fs::read_to_string(path).unwrap()); | ||
29 | |||
30 | quote! { LintCompletion { label: #feature_ident, description: #doc } } | ||
31 | }) | ||
32 | .collect::<Vec<_>>(); | ||
33 | |||
34 | let ts = quote! { | ||
35 | use crate::completion::LintCompletion; | ||
36 | |||
37 | pub(crate) const UNSTABLE_FEATURE_DESCRIPTOR: &[LintCompletion] = &[ | ||
38 | #(#definitions),* | ||
39 | ]; | ||
40 | }; | ||
41 | Ok(ts) | ||
42 | } | ||
43 | |||
44 | pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { | ||
45 | let path = project_root().join(codegen::STORAGE); | ||
46 | fs2::create_dir_all(path.clone())?; | ||
47 | |||
48 | let _d = pushd(path.clone()); | ||
49 | run!("git init")?; | ||
50 | run!("git remote add -f origin {}", codegen::REPOSITORY_URL)?; | ||
51 | run!("git pull origin master")?; | ||
52 | |||
53 | let src_dir = path.join(codegen::REPO_PATH); | ||
54 | let content = generate_descriptor(src_dir)?.to_string(); | ||
55 | |||
56 | let contents = reformat(content)?; | ||
57 | let destination = project_root().join(codegen::UNSTABLE_FEATURE); | ||
58 | update(destination.as_path(), &contents, mode)?; | ||
59 | |||
60 | Ok(()) | ||
61 | } | ||
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index fb38fdc92..c4a15f4bd 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -77,6 +77,7 @@ FLAGS: | |||
77 | "codegen" => { | 77 | "codegen" => { |
78 | args.finish()?; | 78 | args.finish()?; |
79 | codegen::generate_syntax(Mode::Overwrite)?; | 79 | codegen::generate_syntax(Mode::Overwrite)?; |
80 | codegen::generate_unstable_future_descriptor(Mode::Overwrite)?; | ||
80 | codegen::generate_parser_tests(Mode::Overwrite)?; | 81 | codegen::generate_parser_tests(Mode::Overwrite)?; |
81 | codegen::generate_assists_tests(Mode::Overwrite)?; | 82 | codegen::generate_assists_tests(Mode::Overwrite)?; |
82 | codegen::generate_assists_docs(Mode::Overwrite)?; | 83 | codegen::generate_assists_docs(Mode::Overwrite)?; |
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index ebd42cef7..bec3c630b 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs | |||
@@ -112,6 +112,8 @@ fn check_todo(path: &Path, text: &str) { | |||
112 | // To support generating `todo!()` in assists, we have `expr_todo()` in | 112 | // To support generating `todo!()` in assists, we have `expr_todo()` in |
113 | // `ast::make`. | 113 | // `ast::make`. |
114 | "ast/make.rs", | 114 | "ast/make.rs", |
115 | // The documentation in string literals may contain anything for its own purposes | ||
116 | "completion/unstable_feature_descriptor.rs", | ||
115 | ]; | 117 | ]; |
116 | if need_todo.iter().any(|p| path.ends_with(p)) { | 118 | if need_todo.iter().any(|p| path.ends_with(p)) { |
117 | return; | 119 | return; |