-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
44 lines (38 loc) · 1.19 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#![feature(exit_status_error)]
use std::env;
use std::error::Error;
use std::process::Command;
fn main() {
gen_for_grammar().unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/parser/Cb.g4");
}
fn gen_for_grammar() -> Result<(), Box<dyn Error>> {
let input = env::current_dir().unwrap().join("src").join("parser");
let file_name = "Cb.g4";
let antlr_path = env::current_dir().unwrap().join("bin").join("antlr.jar");
Command::new("java")
.current_dir(input)
.env("CLASSPATH", antlr_path)
.arg("org.antlr.v4.Tool")
.arg("-Dlanguage=Rust")
.arg("-visitor")
.arg(&file_name)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()
.expect("antlr tool failed to start")
.wait()?
.exit_ok()
.unwrap();
// let _ = Command::new("cargo")
// .current_dir(env::current_dir()?)
// .arg("fmt")
// .spawn()
// .expect("failed to format antlr code")
// .wait_with_output()?;
// .unwrap()
// .stdout;
// eprintln!("xx{}",String::from_utf8(x).unwrap());
Ok(())
}