Use CARGO_MANIFEST_DIR for locating the grammar.ron file

This commit is contained in:
Muhammad Mominul Huque 2018-10-15 23:52:11 +06:00
parent 33b378797c
commit ce73df065f
No known key found for this signature in database
GPG key ID: 9D472E8B36098956
3 changed files with 7 additions and 8 deletions

View 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)?;

View 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)?