aboutsummaryrefslogtreecommitdiff
path: root/crates/tools
diff options
context:
space:
mode:
authorMuhammad Mominul Huque <[email protected]>2018-10-15 18:52:11 +0100
committerMuhammad Mominul Huque <[email protected]>2018-10-15 18:52:11 +0100
commitce73df065f89bb5aa17517de16c10f9e4d3abaeb (patch)
treec8afdd06e562f5cd0040b41f577a881887b5a26a /crates/tools
parent33b378797c33bf29af4104e0b11c31252451df0c (diff)
Use CARGO_MANIFEST_DIR for locating the grammar.ron file
Diffstat (limited to 'crates/tools')
-rw-r--r--crates/tools/src/lib.rs4
-rw-r--r--crates/tools/src/main.rs4
-rw-r--r--crates/tools/tests/cli.rs7
3 files changed, 7 insertions, 8 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index 7b5a60847..ba7d10caa 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -71,9 +71,9 @@ pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
71 Ok(()) 71 Ok(())
72} 72}
73 73
74pub fn render_template(template: &str, grammarfile: &str) -> Result<String> { 74pub fn render_template(template: &str) -> Result<String> {
75 let grammar: ron::value::Value = { 75 let grammar: ron::value::Value = {
76 let text = fs::read_to_string(grammarfile)?; 76 let text = fs::read_to_string(format!("{}{}", Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).parent().unwrap().to_str().unwrap(), "/ra_syntax/src/grammar.ron"))?;
77 ron::de::from_str(&text)? 77 ron::de::from_str(&text)?
78 }; 78 };
79 let template = fs::read_to_string(template)?; 79 let template = fs::read_to_string(template)?;
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index 179c1163f..aa6d964e6 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -45,8 +45,8 @@ fn main() -> Result<()> {
45fn run_gen_command(name: &str, verify: bool) -> Result<()> { 45fn run_gen_command(name: &str, verify: bool) -> Result<()> {
46 match name { 46 match name {
47 "gen-kinds" => { 47 "gen-kinds" => {
48 update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR)?, verify)?; 48 update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE)?, verify)?;
49 update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR)?, verify)?; 49 update(Path::new(AST), &render_template(AST_TEMPLATE)?, verify)?;
50 }, 50 },
51 "gen-tests" => { 51 "gen-tests" => {
52 gen_tests(verify)? 52 gen_tests(verify)?
diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs
index 4d5b03b65..9ff1eecd9 100644
--- a/crates/tools/tests/cli.rs
+++ b/crates/tools/tests/cli.rs
@@ -3,7 +3,6 @@ extern crate tools;
3use std::path::Path; 3use std::path::Path;
4use tools::{render_template, update}; 4use tools::{render_template, update};
5 5
6const GRAMMAR: &str = "../ra_syntax/src/grammar.ron";
7const SYNTAX_KINDS: &str = "../ra_syntax/src/syntax_kinds/generated.rs"; 6const SYNTAX_KINDS: &str = "../ra_syntax/src/syntax_kinds/generated.rs";
8const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera"; 7const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera";
9const AST: &str = "../ra_syntax/src/ast/generated.rs"; 8const AST: &str = "../ra_syntax/src/ast/generated.rs";
@@ -11,10 +10,10 @@ const AST_TEMPLATE: &str = "../ra_syntax/src/ast/generated.rs.tera";
11 10
12#[test] 11#[test]
13fn verify_template_generation() { 12fn verify_template_generation() {
14 if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR).unwrap(), true) { 13 if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE).unwrap(), true) {
15 panic!("{}. Please update it by running `cargo gen-kinds`", error); 14 panic!("{}. Please update it by running `cargo gen-kinds`", error);
16 } 15 }
17 if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR).unwrap(), true) { 16 if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE).unwrap(), true) {
18 panic!("{}. Please update it by running `cargo gen-kinds`", error); 17 panic!("{}. Please update it by running `cargo gen-kinds`", error);
19 } 18 }
20} \ No newline at end of file 19}