diff options
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/codegen.rs | 2 | ||||
-rw-r--r-- | xtask/src/codegen/gen_unstable_future_descriptor.rs | 49 |
2 files changed, 30 insertions, 21 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 209caacc3..c7cac50fe 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -26,7 +26,7 @@ pub use self::{ | |||
26 | gen_unstable_future_descriptor::generate_unstable_future_descriptor, | 26 | gen_unstable_future_descriptor::generate_unstable_future_descriptor, |
27 | }; | 27 | }; |
28 | 28 | ||
29 | // Directory used by xtask | 29 | // Directory used by xtask |
30 | const STORAGE: &str = ".xtask"; | 30 | const STORAGE: &str = ".xtask"; |
31 | 31 | ||
32 | const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; | 32 | const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; |
diff --git a/xtask/src/codegen/gen_unstable_future_descriptor.rs b/xtask/src/codegen/gen_unstable_future_descriptor.rs index 6dce8ba0a..75b603d7d 100644 --- a/xtask/src/codegen/gen_unstable_future_descriptor.rs +++ b/xtask/src/codegen/gen_unstable_future_descriptor.rs | |||
@@ -1,23 +1,27 @@ | |||
1 | //! Generates descriptors structure for unstable feature from Unstable Book | 1 | //! Generates descriptors structure for unstable feature from Unstable Book |
2 | 2 | ||
3 | use crate::{ | 3 | use crate::codegen::update; |
4 | codegen::{self, project_root, Mode, Result}, | 4 | use crate::codegen::{self, project_root, Mode, Result}; |
5 | }; | 5 | use quote::quote; |
6 | use std::process::Command; | ||
7 | use std::fs; | 6 | use std::fs; |
7 | use std::process::Command; | ||
8 | use walkdir::WalkDir; | 8 | use walkdir::WalkDir; |
9 | use quote::quote; | ||
10 | use crate::codegen::update; | ||
11 | 9 | ||
12 | pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { | 10 | pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { |
13 | let path = project_root().join(codegen::STORAGE); | 11 | let path = project_root().join(codegen::STORAGE); |
14 | fs::create_dir_all(path.clone())?; | 12 | fs::create_dir_all(path.clone())?; |
15 | 13 | ||
16 | Command::new("git").current_dir(path.clone()).arg("init").output()?; | 14 | Command::new("git").current_dir(path.clone()).arg("init").output()?; |
17 | Command::new("git").current_dir(path.clone()).args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]).output()?; | 15 | Command::new("git") |
18 | Command::new("git").current_dir(path.clone()).args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]).output()?; | 16 | .current_dir(path.clone()) |
17 | .args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]) | ||
18 | .output()?; | ||
19 | Command::new("git") | ||
20 | .current_dir(path.clone()) | ||
21 | .args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]) | ||
22 | .output()?; | ||
19 | Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?; | 23 | Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?; |
20 | //TODO: check git, and do pull | 24 | //TODO: check git, and do pull |
21 | 25 | ||
22 | let src_dir = path.join("src/doc/unstable-book/src"); | 26 | let src_dir = path.join("src/doc/unstable-book/src"); |
23 | let files = WalkDir::new(src_dir.join("language-features")) | 27 | let files = WalkDir::new(src_dir.join("language-features")) |
@@ -26,18 +30,23 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { | |||
26 | .filter_map(|e| e.ok()) | 30 | .filter_map(|e| e.ok()) |
27 | .filter(|entry| { | 31 | .filter(|entry| { |
28 | // Get all `.md ` files | 32 | // Get all `.md ` files |
29 | entry.file_type().is_file() && entry.path().extension().map(|ext| ext == "md").unwrap_or(false) | 33 | entry.file_type().is_file() |
34 | && entry.path().extension().map(|ext| ext == "md").unwrap_or(false) | ||
35 | }) | ||
36 | .collect::<Vec<_>>(); | ||
37 | |||
38 | let definitions = files | ||
39 | .iter() | ||
40 | .map(|entry| { | ||
41 | let path = entry.path(); | ||
42 | let feature_ident = | ||
43 | format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_")); | ||
44 | let doc = format!("{}", std::fs::read_to_string(path).unwrap()); | ||
45 | |||
46 | quote! { LintCompletion { label: #feature_ident, description: #doc } } | ||
30 | }) | 47 | }) |
31 | .collect::<Vec<_>>(); | 48 | .collect::<Vec<_>>(); |
32 | 49 | ||
33 | let definitions = files.iter().map(|entry| { | ||
34 | let path = entry.path(); | ||
35 | let feature_ident = format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_")); | ||
36 | let doc = format!("{}", std::fs::read_to_string(path).unwrap() ); | ||
37 | |||
38 | quote!{ LintCompletion { label: #feature_ident, description: #doc } } | ||
39 | }).collect::<Vec<_>>(); | ||
40 | |||
41 | let ts = quote! { | 50 | let ts = quote! { |
42 | use crate::completion::LintCompletion; | 51 | use crate::completion::LintCompletion; |
43 | 52 | ||
@@ -45,10 +54,10 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { | |||
45 | #(#definitions),* | 54 | #(#definitions),* |
46 | ]; | 55 | ]; |
47 | }; | 56 | }; |
48 | 57 | ||
49 | let destination = project_root().join(codegen::UNSTABLE_FEATURE); | 58 | let destination = project_root().join(codegen::UNSTABLE_FEATURE); |
50 | let contents = crate::reformat(ts.to_string())?; | 59 | let contents = crate::reformat(ts.to_string())?; |
51 | update(destination.as_path(), &contents, mode)?; | 60 | update(destination.as_path(), &contents, mode)?; |
52 | 61 | ||
53 | Ok(()) | 62 | Ok(()) |
54 | } \ No newline at end of file | 63 | } |