Load all fixture grammars dynamically
This way the build doesn't take forever any time a single grammar has been regenerated.
This commit is contained in:
parent
5c3c1dd0bd
commit
a8292f4fe9
10 changed files with 119 additions and 143 deletions
53
lib/build.rs
53
lib/build.rs
|
|
@ -2,61 +2,8 @@ extern crate cc;
|
|||
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-env-changed=TREE_SITTER_TEST");
|
||||
if env::var("TREE_SITTER_TEST").is_ok() {
|
||||
let mut parser_config = cc::Build::new();
|
||||
parser_config
|
||||
.opt_level(0)
|
||||
.flag_if_supported("-Wno-unused-parameter");
|
||||
|
||||
let mut scanner_c_config = cc::Build::new();
|
||||
scanner_c_config
|
||||
.flag_if_supported("-std=c99")
|
||||
.flag_if_supported("-Wno-unused-parameter");
|
||||
|
||||
let mut scanner_cxx_config = cc::Build::new();
|
||||
scanner_cxx_config
|
||||
.cpp(true)
|
||||
.flag_if_supported("-Wno-unused-parameter");
|
||||
|
||||
let grammars_dir: PathBuf = ["..", "test", "fixtures", "grammars"].iter().collect();
|
||||
for entry in fs::read_dir(&grammars_dir).expect("Failed to list grammar directory") {
|
||||
let entry = entry.expect("Failed to load grammars directory entry");
|
||||
if !entry.path().is_dir() {
|
||||
continue;
|
||||
}
|
||||
let parser_dir_path = entry.path();
|
||||
let parser_src_path = parser_dir_path.join("src");
|
||||
let parser_c_path = parser_src_path.join("parser.c");
|
||||
let scanner_c_path = parser_src_path.join("scanner.c");
|
||||
let scanner_cc_path = parser_src_path.join("scanner.cc");
|
||||
|
||||
println!("cargo:rerun-if-changed={}", parser_c_path.to_str().unwrap());
|
||||
parser_config
|
||||
.include(&parser_src_path)
|
||||
.opt_level(0)
|
||||
.file(&parser_c_path);
|
||||
if scanner_cc_path.exists() {
|
||||
println!("cargo:rerun-if-changed={}", scanner_cc_path.to_str().unwrap());
|
||||
scanner_cxx_config
|
||||
.include(&parser_src_path)
|
||||
.file(&scanner_cc_path);
|
||||
} else if scanner_c_path.exists() {
|
||||
println!("cargo:rerun-if-changed={}", scanner_c_path.to_str().unwrap());
|
||||
scanner_c_config
|
||||
.include(&parser_src_path)
|
||||
.file(&scanner_c_path);
|
||||
}
|
||||
}
|
||||
|
||||
parser_config.compile("fixture-parsers");
|
||||
scanner_c_config.compile("fixture-scanners-c");
|
||||
scanner_cxx_config.compile("fixture-scanners-cxx");
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-env-changed=TREE_SITTER_STATIC_ANALYSIS");
|
||||
if env::var("TREE_SITTER_STATIC_ANALYSIS").is_ok() {
|
||||
let clang_path = which("clang").unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue