From ce73df065f89bb5aa17517de16c10f9e4d3abaeb Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Mon, 15 Oct 2018 23:52:11 +0600 Subject: Use CARGO_MANIFEST_DIR for locating the grammar.ron file --- crates/tools/src/lib.rs | 4 ++-- crates/tools/src/main.rs | 4 ++-- crates/tools/tests/cli.rs | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'crates/tools') 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<()> { Ok(()) } -pub fn render_template(template: &str, grammarfile: &str) -> Result { +pub fn render_template(template: &str) -> Result { let grammar: ron::value::Value = { - let text = fs::read_to_string(grammarfile)?; + 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"))?; ron::de::from_str(&text)? }; 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<()> { fn run_gen_command(name: &str, verify: bool) -> Result<()> { match name { "gen-kinds" => { - update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR)?, verify)?; - update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR)?, verify)?; + update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE)?, verify)?; + update(Path::new(AST), &render_template(AST_TEMPLATE)?, verify)?; }, "gen-tests" => { 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; use std::path::Path; use tools::{render_template, update}; -const GRAMMAR: &str = "../ra_syntax/src/grammar.ron"; const SYNTAX_KINDS: &str = "../ra_syntax/src/syntax_kinds/generated.rs"; const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera"; const AST: &str = "../ra_syntax/src/ast/generated.rs"; @@ -11,10 +10,10 @@ const AST_TEMPLATE: &str = "../ra_syntax/src/ast/generated.rs.tera"; #[test] fn verify_template_generation() { - if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR).unwrap(), true) { + if let Err(error) = update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE).unwrap(), true) { panic!("{}. Please update it by running `cargo gen-kinds`", error); } - if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR).unwrap(), true) { + if let Err(error) = update(Path::new(AST), &render_template(AST_TEMPLATE).unwrap(), true) { panic!("{}. Please update it by running `cargo gen-kinds`", error); } -} \ No newline at end of file +} -- cgit v1.2.3