git: f57ee6874d46 - main - textproc/tree-sitter-grammars: Fix build with BUILD_AS_NON_ROOT=yes

From: Mikael Urankar <mikael_at_FreeBSD.org>
Date: Wed, 10 Sep 2025 09:45:42 UTC
The branch main has been updated by mikael:

URL: https://cgit.FreeBSD.org/ports/commit/?id=f57ee6874d4635f71f775449dafb172547b4ee23

commit f57ee6874d4635f71f775449dafb172547b4ee23
Author:     Mikael Urankar <mikael@FreeBSD.org>
AuthorDate: 2025-09-07 09:06:53 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2025-09-10 09:45:36 +0000

    textproc/tree-sitter-grammars: Fix build with BUILD_AS_NON_ROOT=yes
    
    PR:             289260
---
 textproc/tree-sitter-grammars/Makefile                | 4 ++++
 textproc/tree-sitter-grammars/files/patch-src_main.rs | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/textproc/tree-sitter-grammars/Makefile b/textproc/tree-sitter-grammars/Makefile
index 586c9ea4c669..c2aec35d5499 100644
--- a/textproc/tree-sitter-grammars/Makefile
+++ b/textproc/tree-sitter-grammars/Makefile
@@ -60,6 +60,10 @@ post-extract:
 
 	${CP} ${DISTDIR}/${LANG_HASH}/languages.toml ${WRKSRC}
 
+post-patch:
+	${REINPLACE_CMD} "s#WRKDIR#${WRKDIR}#" \
+		${WRKSRC}/src/main.rs
+
 post-build:
 	cd ${WRKSRC}; \
 		${CARGO_TARGET_DIR}/release/build-tree-sitter --output ./output --tmp ${WRKSRC}/grammars
diff --git a/textproc/tree-sitter-grammars/files/patch-src_main.rs b/textproc/tree-sitter-grammars/files/patch-src_main.rs
index 4197c86a3f26..ea6c62211292 100644
--- a/textproc/tree-sitter-grammars/files/patch-src_main.rs
+++ b/textproc/tree-sitter-grammars/files/patch-src_main.rs
@@ -31,3 +31,11 @@
      let path = if let Some(subpath) = grammar.source.subpath.as_ref() {
          path.join(subpath)
      } else {
+@@ -171,6 +171,7 @@ fn build_tree_sitter(name: &str, path: &Path, output: 
+ fn build_tree_sitter(name: &str, path: &Path, output: &Path) -> Result<()> {
+     println!("-----------------------------------");
+     println!("now building tree sitter for {name}");
++    std::env::set_var("XDG_CACHE_HOME", "WRKDIR/.cache");
+     let output = Command::new("tree-sitter")
+         .current_dir(path)
+         .arg("build")