aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen.rs9
-rw-r--r--xtask/src/codegen/gen_unstable_future_descriptor.rs61
-rw-r--r--xtask/src/main.rs1
3 files changed, 71 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;
9mod gen_parser_tests; 9mod gen_parser_tests;
10mod gen_assists_docs; 10mod gen_assists_docs;
11mod gen_feature_docs; 11mod gen_feature_docs;
12mod gen_unstable_future_descriptor;
12 13
13use std::{ 14use 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
34const STORAGE: &str = ".xtask";
35
31const GRAMMAR_DIR: &str = "crates/parser/src/grammar"; 36const GRAMMAR_DIR: &str = "crates/parser/src/grammar";
32const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok"; 37const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok";
33const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err"; 38const 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";
39const ASSISTS_DIR: &str = "crates/assists/src/handlers"; 44const ASSISTS_DIR: &str = "crates/assists/src/handlers";
40const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs"; 45const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs";
41 46
47const REPOSITORY_URL: &str = "https://github.com/rust-lang/rust";
48const UNSTABLE_FEATURE: &str = "crates/ide/src/completion/unstable_feature_descriptor.rs";
49const REPO_PATH: &str = "src/doc/unstable-book/src";
50
42#[derive(Debug, PartialEq, Eq, Clone, Copy)] 51#[derive(Debug, PartialEq, Eq, Clone, Copy)]
43pub enum Mode { 52pub 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..f220f85d3
--- /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
3use crate::codegen::update;
4use crate::codegen::{self, project_root, Mode, Result};
5use crate::not_bash::{fs2, pushd, run};
6use proc_macro2::TokenStream;
7use quote::quote;
8use std::path::PathBuf;
9use walkdir::WalkDir;
10
11fn 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
44pub 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 = crate::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)?;