From 099fd4efb765e1421fd6a5b00948f95c17a1bf5e Mon Sep 17 00:00:00 2001 From: JCWasmx86 Date: Sat, 9 Sep 2023 19:25:14 +0200 Subject: [PATCH] feat: allow setting the output directory for generated source files --- cli/generate/src/lib.rs | 5 ++++- cli/src/main.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/generate/src/lib.rs b/cli/generate/src/lib.rs index cd31cdcf..9695e821 100644 --- a/cli/generate/src/lib.rs +++ b/cli/generate/src/lib.rs @@ -44,6 +44,7 @@ pub const ARRAY_HEADER: &str = include_str!("templates/array.h"); pub fn generate_parser_in_directory( repo_path: &Path, + out_path: Option<&str>, grammar_path: Option<&str>, abi_version: usize, report_symbol_name: Option<&str>, @@ -72,7 +73,9 @@ pub fn generate_parser_in_directory( // Read the grammar file. let grammar_json = load_grammar_file(&grammar_path, js_runtime)?; - let src_path = repo_path.join("src"); + let src_path = out_path + .map(PathBuf::from) + .unwrap_or_else(|| repo_path.join("src")); let header_path = src_path.join("tree_sitter"); // Ensure that the output directories exist. diff --git a/cli/src/main.rs b/cli/src/main.rs index 72d70a4e..256a5229 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -101,6 +101,13 @@ struct Generate { help = "The path to the directory containing the parser library" )] pub libdir: Option, + #[arg( + long, + short, + value_name = "DIRECTORY", + help = "The path to output the generated source files" + )] + pub output: Option, #[arg( long, help = "Produce a report of the states for the given rule, use `-` to report every rule" @@ -693,6 +700,7 @@ impl Generate { }); tree_sitter_generate::generate_parser_in_directory( current_dir, + self.output.as_deref(), self.grammar_path.as_deref(), abi_version, self.report_states_for_rule.as_deref(),