aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/codegen')
-rw-r--r--xtask/src/codegen/gen_unstable_future_descriptor.rs55
1 files changed, 55 insertions, 0 deletions
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..298696fbb
--- /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 pub 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