From ad45f5cd2cabda2de406a480f6d660aa5c96a85b Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Fri, 6 Jan 2023 06:05:07 +0200 Subject: [PATCH 1/3] Remove unused no-minimize arg for the generate command --- cli/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index ce6743bf..9e3331c0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -111,8 +111,7 @@ fn run() -> Result<()> { .long("report-states-for-rule") .value_name("rule-name") .takes_value(true), - ) - .arg(Arg::with_name("no-minimize").long("no-minimize")), + ), ) .subcommand( SubCommand::with_name("parse") From 5088781ef965c5cd7187c5308e3cb45f8f892860 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Fri, 6 Jan 2023 06:13:08 +0200 Subject: [PATCH 2/3] cli: add -b, --build flags for `tree-sitter generate` --- cli/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cli/src/main.rs b/cli/src/main.rs index 9e3331c0..a6e75bf5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -106,6 +106,11 @@ fn run() -> Result<()> { )), ) .arg(Arg::with_name("no-bindings").long("no-bindings")) + .arg( + Arg::with_name("build").long("build").short("b") + .help("Compile all defined languages in the current dir") + ) + .arg(&debug_build_arg) .arg( Arg::with_name("report-states-for-rule") .long("report-states-for-rule") @@ -269,6 +274,8 @@ fn run() -> Result<()> { ("generate", Some(matches)) => { let grammar_path = matches.value_of("grammar-path"); + let debug_build = matches.is_present("debug-build"); + let build = matches.is_present("build"); let report_symbol_name = matches.value_of("report-states-for-rule").or_else(|| { if matches.is_present("report-states") { Some("") @@ -297,6 +304,10 @@ fn run() -> Result<()> { generate_bindings, report_symbol_name, )?; + if build { + loader.use_debug_build(debug_build); + loader.languages_at_path(¤t_dir)?; + } } ("test", Some(matches)) => { From 108d0ecede9312e88ac12475ffac62af9fba5dbf Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Fri, 6 Jan 2023 06:37:22 +0200 Subject: [PATCH 3/3] loader: add TREE_SITTER_LIBDIR; cli: add --libdir to `tree-sitter generate` Closes #1336 --- cli/loader/src/lib.rs | 11 +++++++---- cli/src/main.rs | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 6f8605f4..0f92b051 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::Mutex; use std::time::SystemTime; -use std::{fs, mem}; +use std::{env, fs, mem}; use tree_sitter::{Language, QueryError, QueryErrorKind}; use tree_sitter_highlight::HighlightConfiguration; use tree_sitter_tags::{Error as TagsError, TagsConfiguration}; @@ -108,9 +108,12 @@ unsafe impl Sync for Loader {} impl Loader { pub fn new() -> Result { - let parser_lib_path = dirs::cache_dir() - .ok_or(anyhow!("Cannot determine cache directory"))? - .join("tree-sitter/lib"); + let parser_lib_path = match env::var("TREE_SITTER_LIBDIR") { + Ok(path) => PathBuf::from(path), + _ => dirs::cache_dir() + .ok_or(anyhow!("Cannot determine cache directory"))? + .join("tree-sitter/lib"), + }; Ok(Self::with_parser_lib_path(parser_lib_path)) } diff --git a/cli/src/main.rs b/cli/src/main.rs index a6e75bf5..c1dd2501 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Context, Result}; use clap::{App, AppSettings, Arg, SubCommand}; use glob::glob; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::{env, fs, u64}; use tree_sitter_cli::{ generate, highlight, logger, parse, playground, query, tags, test, test_highlight, test_tags, @@ -107,10 +107,18 @@ fn run() -> Result<()> { ) .arg(Arg::with_name("no-bindings").long("no-bindings")) .arg( - Arg::with_name("build").long("build").short("b") - .help("Compile all defined languages in the current dir") + Arg::with_name("build") + .long("build") + .short("b") + .help("Compile all defined languages in the current dir"), ) .arg(&debug_build_arg) + .arg( + Arg::with_name("libdir") + .long("libdir") + .takes_value(true) + .value_name("path"), + ) .arg( Arg::with_name("report-states-for-rule") .long("report-states-for-rule") @@ -276,6 +284,7 @@ fn run() -> Result<()> { let grammar_path = matches.value_of("grammar-path"); let debug_build = matches.is_present("debug-build"); let build = matches.is_present("build"); + let libdir = matches.value_of("libdir"); let report_symbol_name = matches.value_of("report-states-for-rule").or_else(|| { if matches.is_present("report-states") { Some("") @@ -305,6 +314,9 @@ fn run() -> Result<()> { report_symbol_name, )?; if build { + if let Some(path) = libdir { + loader = loader::Loader::with_parser_lib_path(PathBuf::from(path)); + } loader.use_debug_build(debug_build); loader.languages_at_path(¤t_dir)?; }