]> git.lizzy.rs Git - rust.git/commitdiff
Use CARGO_MANIFEST_DIR for locating the grammar.ron file
authorMuhammad Mominul Huque <mominul2082@gmail.com>
Mon, 15 Oct 2018 17:52:11 +0000 (23:52 +0600)
committerMuhammad Mominul Huque <mominul2082@gmail.com>
Mon, 15 Oct 2018 17:52:11 +0000 (23:52 +0600)
crates/tools/src/lib.rs
crates/tools/src/main.rs
crates/tools/tests/cli.rs

index 7b5a608477b15ae254a46e081b8a5ce4a3a5c089..ba7d10caa52c6d2c6b35fbc6dc2aa94c506d0c06 100644 (file)
@@ -71,9 +71,9 @@ pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
     Ok(())
 }
 
-pub fn render_template(template: &str, grammarfile: &str) -> Result<String> {
+pub fn render_template(template: &str) -> Result<String> {
     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)?;
index 179c1163fd86565da495a9148367cc2b01db29d5..aa6d964e62776236777ab84bf7f6f315688146d3 100644 (file)
@@ -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)?
index 4d5b03b65e904b962ae3db98dfd8f823ceee95ff..9ff1eecd9d71c8e0336b0cd0c89d913cb97bbf54 100644 (file)
@@ -3,7 +3,6 @@
 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";
 
 #[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
+}