feat: allow setting the output directory for generated source files

This commit is contained in:
JCWasmx86 2023-09-09 19:25:14 +02:00 committed by Amaan Qureshi
parent 5e8401fb1d
commit 099fd4efb7
2 changed files with 12 additions and 1 deletions

View file

@ -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.

View file

@ -101,6 +101,13 @@ struct Generate {
help = "The path to the directory containing the parser library"
)]
pub libdir: Option<String>,
#[arg(
long,
short,
value_name = "DIRECTORY",
help = "The path to output the generated source files"
)]
pub output: Option<String>,
#[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(),