mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Use CARGO_MANIFEST_DIR for locating the grammar.ron file
This commit is contained in:
parent
33b378797c
commit
ce73df065f
3 changed files with 7 additions and 8 deletions
|
@ -71,9 +71,9 @@ pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
|
||||||
Ok(())
|
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 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)?
|
ron::de::from_str(&text)?
|
||||||
};
|
};
|
||||||
let template = fs::read_to_string(template)?;
|
let template = fs::read_to_string(template)?;
|
||||||
|
|
|
@ -45,8 +45,8 @@ fn main() -> Result<()> {
|
||||||
fn run_gen_command(name: &str, verify: bool) -> Result<()> {
|
fn run_gen_command(name: &str, verify: bool) -> Result<()> {
|
||||||
match name {
|
match name {
|
||||||
"gen-kinds" => {
|
"gen-kinds" => {
|
||||||
update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE, GRAMMAR)?, verify)?;
|
update(Path::new(SYNTAX_KINDS), &render_template(SYNTAX_KINDS_TEMPLATE)?, verify)?;
|
||||||
update(Path::new(AST), &render_template(AST_TEMPLATE, GRAMMAR)?, verify)?;
|
update(Path::new(AST), &render_template(AST_TEMPLATE)?, verify)?;
|
||||||
},
|
},
|
||||||
"gen-tests" => {
|
"gen-tests" => {
|
||||||
gen_tests(verify)?
|
gen_tests(verify)?
|
||||||
|
|
|
@ -3,7 +3,6 @@ extern crate tools;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tools::{render_template, update};
|
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: &str = "../ra_syntax/src/syntax_kinds/generated.rs";
|
||||||
const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera";
|
const SYNTAX_KINDS_TEMPLATE: &str = "../ra_syntax/src/syntax_kinds/generated.rs.tera";
|
||||||
const AST: &str = "../ra_syntax/src/ast/generated.rs";
|
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]
|
#[test]
|
||||||
fn verify_template_generation() {
|
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);
|
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);
|
panic!("{}. Please update it by running `cargo gen-kinds`", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue