aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 17:47:02 +0100
committerDmitry <[email protected]>2020-08-09 17:47:02 +0100
commitcff0fba5e5fb4a5de470bf923b93b0bdd89d9efb (patch)
tree6203f06dd105aa0d3a70282e9f3f4978d48bcc38 /xtask
parent7f71ae8d73ea2a2203897703324e11c2096706fa (diff)
apply format
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/codegen.rs2
-rw-r--r--xtask/src/codegen/gen_unstable_future_descriptor.rs49
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
30const STORAGE: &str = ".xtask"; 30const STORAGE: &str = ".xtask";
31 31
32const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 32const 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
3use crate::{ 3use crate::codegen::update;
4 codegen::{self, project_root, Mode, Result}, 4use crate::codegen::{self, project_root, Mode, Result};
5}; 5use quote::quote;
6use std::process::Command;
7use std::fs; 6use std::fs;
7use std::process::Command;
8use walkdir::WalkDir; 8use walkdir::WalkDir;
9use quote::quote;
10use crate::codegen::update;
11 9
12pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { 10pub 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}