feat: provide a rebuild flag to force rebuild parsers

This commit is contained in:
Amaan Qureshi 2024-09-24 11:05:08 -04:00
parent 1aa28e04ee
commit 52f696096d
2 changed files with 16 additions and 1 deletions

View file

@ -132,6 +132,7 @@ pub struct Loader {
use_all_highlight_names: bool,
debug_build: bool,
sanitize_build: bool,
force_rebuild: bool,
#[cfg(feature = "wasm")]
wasm_store: Mutex<Option<tree_sitter::WasmStore>>,
@ -200,6 +201,7 @@ impl Loader {
use_all_highlight_names: true,
debug_build: false,
sanitize_build: false,
force_rebuild: false,
#[cfg(feature = "wasm")]
wasm_store: Mutex::default(),
@ -474,7 +476,7 @@ impl Loader {
fs::create_dir_all(&self.parser_lib_path)?;
}
let mut recompile = config.output_path.is_some(); // if specified, always recompile
let mut recompile = self.force_rebuild || config.output_path.is_some(); // if specified, always recompile
let output_path = config.output_path.unwrap_or_else(|| {
let mut path = self.parser_lib_path.join(lib_name);
@ -1185,6 +1187,10 @@ impl Loader {
self.sanitize_build = flag;
}
pub fn force_rebuild(&mut self, rebuild: bool) {
self.force_rebuild = rebuild;
}
#[cfg(feature = "wasm")]
pub fn use_wasm(&mut self, engine: &tree_sitter::wasmtime::Engine) {
*self.wasm_store.lock().unwrap() = Some(tree_sitter::WasmStore::new(engine).unwrap());

View file

@ -187,6 +187,8 @@ struct Parse {
#[arg(long, short = 'n', help = "Parse the contents of a specific test")]
#[clap(conflicts_with = "paths", conflicts_with = "paths_file")]
pub test_number: Option<u32>,
#[arg(short, long, help = "Force rebuild the parser")]
pub rebuild: bool,
}
#[derive(Args)]
@ -234,6 +236,8 @@ struct Test {
pub config_path: Option<PathBuf>,
#[arg(long, help = "Force showing fields in test diffs")]
pub show_fields: bool,
#[arg(short, long, help = "Force rebuild the parser")]
pub rebuild: bool,
}
#[derive(Args)]
@ -263,6 +267,8 @@ struct Fuzz {
pub log_graphs: bool,
#[arg(long, short, help = "Enable parser logging")]
pub log: bool,
#[arg(short, long, help = "Force rebuild the parser")]
pub rebuild: bool,
}
#[derive(Args)]
@ -560,6 +566,7 @@ fn run() -> Result<()> {
let mut parser = Parser::new();
loader.debug_build(parse_options.debug_build);
loader.force_rebuild(parse_options.rebuild);
#[cfg(feature = "wasm")]
if parse_options.wasm {
@ -656,6 +663,7 @@ fn run() -> Result<()> {
let config = Config::load(test_options.config_path)?;
loader.debug_build(test_options.debug_build);
loader.force_rebuild(test_options.rebuild);
let mut parser = Parser::new();
@ -731,6 +739,7 @@ fn run() -> Result<()> {
Commands::Fuzz(fuzz_options) => {
loader.sanitize_build(true);
loader.force_rebuild(fuzz_options.rebuild);
let languages = loader.languages_at_path(&current_dir)?;
let (language, language_name) = &languages