aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:33:47 +0100
committerDmitry <[email protected]>2020-08-09 14:33:47 +0100
commit1a43a0f63e0008787225abb6fb2baef97b6a39e0 (patch)
treec5ee106cf8dd15f6df0bca041f36ec387d6b3214 /xtask/src
parent020a40335bb2d45245d1164e4075e7f622084705 (diff)
Added competition for unstable features
Added xtask for download unstable book from rust repository and codegene for it. Also small changes from lint
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen.rs8
-rw-r--r--xtask/src/codegen/gen_unstable_future_descriptor.rs55
-rw-r--r--xtask/src/main.rs1
3 files changed, 64 insertions, 0 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index f5f4b964a..209caacc3 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,
@@ -22,8 +23,12 @@ pub use self::{
22 gen_feature_docs::generate_feature_docs, 23 gen_feature_docs::generate_feature_docs,
23 gen_parser_tests::generate_parser_tests, 24 gen_parser_tests::generate_parser_tests,
24 gen_syntax::generate_syntax, 25 gen_syntax::generate_syntax,
26 gen_unstable_future_descriptor::generate_unstable_future_descriptor,
25}; 27};
26 28
29// Directory used by xtask
30const STORAGE: &str = ".xtask";
31
27const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 32const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
28const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok"; 33const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok";
29const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; 34const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err";
@@ -35,6 +40,9 @@ const AST_TOKENS: &str = "crates/ra_syntax/src/ast/generated/tokens.rs";
35const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers"; 40const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers";
36const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs"; 41const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs";
37 42
43const REPOSITORY_URL: &str = "https://github.com/rust-lang/rust";
44const UNSTABLE_FEATURE: &str = "crates/ra_ide/src/completion/unstable_feature_descriptor.rs";
45
38#[derive(Debug, PartialEq, Eq, Clone, Copy)] 46#[derive(Debug, PartialEq, Eq, Clone, Copy)]
39pub enum Mode { 47pub enum Mode {
40 Overwrite, 48 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..09c4f61f2
--- /dev/null
+++ b/xtask/src/codegen/gen_unstable_future_descriptor.rs
@@ -0,0 +1,55 @@
1//! Generates descriptors structure for unstable feature from Unstable Book
2
3use crate::{
4 codegen::{self, project_root, Mode, Result},
5};
6use std::process::Command;
7use std::fs;
8use std::path::{Path, PathBuf};
9use walkdir::{DirEntry, WalkDir};
10use quote::{format_ident, quote};
11use crate::codegen::update;
12
13pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
14 let path = project_root().join(codegen::STORAGE);
15 fs::create_dir_all(path.clone())?;
16
17 Command::new("git").current_dir(path.clone()).arg("init").output()?;
18 Command::new("git").current_dir(path.clone()).args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]).output()?;
19 Command::new("git").current_dir(path.clone()).args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]).output()?;
20 Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?;
21 //TODO: check git, and do pull
22
23 let src_dir = path.join("src/doc/unstable-book/src");
24 let files = WalkDir::new(src_dir.join("language-features"))
25 .into_iter()
26 .chain(WalkDir::new(src_dir.join("library-features")))
27 .filter_map(|e| e.ok())
28 .filter(|entry| {
29 // Get all `.md ` files
30 entry.file_type().is_file() && entry.path().extension().map(|ext| ext == "md").unwrap_or(false)
31 })
32 .collect::<Vec<_>>();
33
34 let definitions = files.iter().map(|entry| {
35 let path = entry.path();
36 let feature_ident = format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_"));
37 let doc = format!("{}", std::fs::read_to_string(path).unwrap() );
38
39 quote!{ LintCompletion { label: #feature_ident, description: #doc } }
40 }).collect::<Vec<_>>();
41
42 let ts = quote! {
43 use crate::completion::LintCompletion;
44
45 const UNSTABLE_FEATURE_DESCRIPTOR: &[LintCompletion] = &[
46 #(#definitions),*
47 ];
48 };
49
50 let destination = project_root().join(codegen::UNSTABLE_FEATURE);
51 let contents = crate::reformat(ts.to_string())?;
52 update(destination.as_path(), &contents, mode)?;
53
54 Ok(())
55} \ No newline at end of file
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index b69b884e5..71caff248 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -76,6 +76,7 @@ FLAGS:
76 "codegen" => { 76 "codegen" => {
77 args.finish()?; 77 args.finish()?;
78 codegen::generate_syntax(Mode::Overwrite)?; 78 codegen::generate_syntax(Mode::Overwrite)?;
79 codegen::generate_unstable_future_descriptor(Mode::Overwrite)?;
79 codegen::generate_parser_tests(Mode::Overwrite)?; 80 codegen::generate_parser_tests(Mode::Overwrite)?;
80 codegen::generate_assists_tests(Mode::Overwrite)?; 81 codegen::generate_assists_tests(Mode::Overwrite)?;
81 codegen::generate_assists_docs(Mode::Overwrite)?; 82 codegen::generate_assists_docs(Mode::Overwrite)?;