From 52f696096dc2c2c7abc307221a0a65f9a485e430 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Tue, 24 Sep 2024 11:05:08 -0400 Subject: [PATCH] feat: provide a `rebuild` flag to force rebuild parsers --- cli/loader/src/lib.rs | 8 +++++++- cli/src/main.rs | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 1268e700..7f1c6bfd 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -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>, @@ -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()); diff --git a/cli/src/main.rs b/cli/src/main.rs index af89bd01..1f24ccc9 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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, + #[arg(short, long, help = "Force rebuild the parser")] + pub rebuild: bool, } #[derive(Args)] @@ -234,6 +236,8 @@ struct Test { pub config_path: Option, #[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(¤t_dir)?; let (language, language_name) = &languages