From 8f1ce15df9304c16491e2ef4181beeeb619e562c Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Nov 19 2023 19:38:23 +0000
Subject: [PATCH 1/6] New template for Tree-sitter parsers


---

diff --git a/Makefile.am b/Makefile.am
index d55f397..11323cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,9 +14,12 @@ man8_MANS = rpmdev-rmdevelrpms.8
 
 dist_pkgsysconf_DATA = curlrc newspec.conf rmdevelrpms.conf \
 	spectemplate-lib.spec spectemplate-minimal.spec \
+	spectemplate-ocaml.spec \
 	spectemplate-perl.spec spectemplate-php-pear.spec \
 	spectemplate-python.spec spectemplate-pyproject.spec spectemplate-ruby.spec \
-	spectemplate-ocaml.spec spectemplate-R.spec spectemplate-dummy.spec \
+	spectemplate-R.spec \
+	spectemplate-tree-sitter.spec \
+	spectemplate-dummy.spec \
 	template.init
 
 bashcomp_DATA = rpmdevtools.bash-completion
diff --git a/NEWS b/NEWS
index 8657aa8..10ff2d8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+rpmdevtools 9.7 (????-??-??)
+
+  Peter Oliver:
+  - New template for Tree-sitter parsers
+
 rpmdevtools 9.6 (2022-02-04)
 
   Fabio Valentini:
diff --git a/rpmdev-newspec.in b/rpmdev-newspec.in
index 27af10f..5ffbe78 100644
--- a/rpmdev-newspec.in
+++ b/rpmdev-newspec.in
@@ -200,6 +200,11 @@ if [[ -z $spectype ]] ; then
         ruby-*)
             spectype="${appname%%-*}"
             ;;
+        tree-sitter-*)
+            spectype=tree-sitter
+            language="${appname#tree-sitter-}"
+            specfilter="s/<LANGUAGE>/${language@u}/g"
+            ;;
         lib*|*-lib|*-libs)
             spectype=lib
             ;;
diff --git a/spectemplate-tree-sitter.spec b/spectemplate-tree-sitter.spec
new file mode 100644
index 0000000..819710c
--- /dev/null
+++ b/spectemplate-tree-sitter.spec
@@ -0,0 +1,78 @@
+Name:
+Version:
+
+%global forgeurl https://github.com/tree-sitter/%{name}
+%forgemeta
+%global libname  lib%{name}
+%global summary  <LANGUAGE> grammar for Tree-sitter
+%global desc     Add support for <LANGUAGE> to Tree-sitter, an incremental parsing system for \
+programming tools.
+
+
+Release:        %autorelease
+Summary:        %{summary}
+License:        MIT
+URL:            %{forgeurl}
+
+Source:         %{forgesource}
+
+BuildRequires:  gcc
+# BuildRequires:  gcc-c++
+# BuildRequires:  git
+BuildRequires:  libtree-sitter-devel
+BuildRequires:  make
+
+%description
+%{desc}
+
+
+%package -n %{libname}
+Summary:        %{summary}
+Recommends:     libtree-sitter
+Enhances:       libtree-sitter
+
+%description -n %{libname}
+%{desc}
+
+
+%package -n %{libname}-devel
+Summary:        Development files for %{libname}
+Requires:       %{libname}%{?_isa} = %{version}-%{release}
+
+%description -n %{libname}-devel
+Libraries and header files for developing applications that use
+%{name}.
+
+
+%prep
+%forgesetup
+## The Makefiles of some parsers require the following workaround:
+# git init
+# git remote add origin %{forgeurl}
+
+
+%build
+%make_build all
+
+
+%install
+%make_install PARSER_REPO_URL=%{forgeurl} \
+              PREFIX=%{_prefix} INCLUDEDIR=%{_includedir} LIBDIR=%{_libdir}
+find $RPM_BUILD_ROOT -name '*.a' -delete
+
+
+%{?ldconfig_scriptlets}
+
+
+%files -n %{libname}
+%license LICENSE
+%doc README.md
+%{_libdir}/%{libname}.so.*
+
+%files -n %{libname}-devel
+%{_includedir}/*
+%{_libdir}/%{libname}.so
+%{_libdir}/pkgconfig/*.pc
+
+
+%changelog

From 744b1622f2f53b828bb1ee15ae9ba3626ddf9837 Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Dec 17 2023 11:38:01 +0000
Subject: [PATCH 2/6] Don’t use %forge macros


`rpmdev-newspec` is used for non-Fedora platforms that lack these macros.

---

diff --git a/spectemplate-tree-sitter.spec b/spectemplate-tree-sitter.spec
index 819710c..32ffa77 100644
--- a/spectemplate-tree-sitter.spec
+++ b/spectemplate-tree-sitter.spec
@@ -1,8 +1,6 @@
 Name:
 Version:
 
-%global forgeurl https://github.com/tree-sitter/%{name}
-%forgemeta
 %global libname  lib%{name}
 %global summary  <LANGUAGE> grammar for Tree-sitter
 %global desc     Add support for <LANGUAGE> to Tree-sitter, an incremental parsing system for \
@@ -12,9 +10,9 @@ programming tools.
 Release:        %autorelease
 Summary:        %{summary}
 License:        MIT
-URL:            %{forgeurl}
+URL:            https://github.com/tree-sitter/%{name}
 
-Source:         %{forgesource}
+Source:         %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
 
 BuildRequires:  gcc
 # BuildRequires:  gcc-c++
@@ -45,10 +43,10 @@ Libraries and header files for developing applications that use
 
 
 %prep
-%forgesetup
+%autosetup
 ## The Makefiles of some parsers require the following workaround:
 # git init
-# git remote add origin %{forgeurl}
+# git remote add origin %{url}
 
 
 %build
@@ -56,7 +54,7 @@ Libraries and header files for developing applications that use
 
 
 %install
-%make_install PARSER_REPO_URL=%{forgeurl} \
+%make_install PARSER_REPO_URL=%{url} \
               PREFIX=%{_prefix} INCLUDEDIR=%{_includedir} LIBDIR=%{_libdir}
 find $RPM_BUILD_ROOT -name '*.a' -delete
 

From 5ca3ab429c373b3dbe8ad98188d61714efffdbe8 Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Aug 23 2024 19:57:43 +0000
Subject: [PATCH 3/6] Refresh for recent Tree-sitter Makefile templates.


---

diff --git a/spectemplate-tree-sitter.spec b/spectemplate-tree-sitter.spec
index 32ffa77..131cd06 100644
--- a/spectemplate-tree-sitter.spec
+++ b/spectemplate-tree-sitter.spec
@@ -1,9 +1,9 @@
 Name:
 Version:
 
-%global libname  lib%{name}
-%global summary  <LANGUAGE> grammar for Tree-sitter
-%global desc     Add support for <LANGUAGE> to Tree-sitter, an incremental parsing system for \
+%global libname lib%{name}
+%global summary <LANGUAGE> grammar for Tree-sitter
+%global desc    Add support for <LANGUAGE> to Tree-sitter, an incremental parsing system for \
 programming tools.
 
 
@@ -15,8 +15,6 @@ URL:            https://github.com/tree-sitter/%{name}
 Source:         %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
 
 BuildRequires:  gcc
-# BuildRequires:  gcc-c++
-# BuildRequires:  git
 BuildRequires:  libtree-sitter-devel
 BuildRequires:  make
 
@@ -44,18 +42,14 @@ Libraries and header files for developing applications that use
 
 %prep
 %autosetup
-## The Makefiles of some parsers require the following workaround:
-# git init
-# git remote add origin %{url}
 
 
 %build
-%make_build all
+%make_build all PARSER_URL=%{url}
 
 
 %install
-%make_install PARSER_REPO_URL=%{url} \
-              PREFIX=%{_prefix} INCLUDEDIR=%{_includedir} LIBDIR=%{_libdir}
+%make_install PREFIX=%{_prefix} INCLUDEDIR=%{_includedir} LIBDIR=%{_libdir}
 find $RPM_BUILD_ROOT -name '*.a' -delete
 
 

From 619bf37c217b61aa7dd3c1ee2455fd2b5278a218 Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Oct 10 2024 11:31:21 +0000
Subject: [PATCH 4/6] Explicit filenames in tree-sitter template.


---

diff --git a/spectemplate-tree-sitter.spec b/spectemplate-tree-sitter.spec
index 131cd06..a0a5c0f 100644
--- a/spectemplate-tree-sitter.spec
+++ b/spectemplate-tree-sitter.spec
@@ -62,9 +62,9 @@ find $RPM_BUILD_ROOT -name '*.a' -delete
 %{_libdir}/%{libname}.so.*
 
 %files -n %{libname}-devel
-%{_includedir}/*
+%{_includedir}/tree_sitter/%{name}.h
 %{_libdir}/%{libname}.so
-%{_libdir}/pkgconfig/*.pc
+%{_libdir}/pkgconfig/%{name}.pc
 
 
 %changelog

From 8173d544d9ae9e6c7a0897edfa4fd607f705047d Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Oct 10 2024 11:32:09 +0000
Subject: [PATCH 5/6] Run tests in tree-sitter template.


---

diff --git a/spectemplate-tree-sitter.spec b/spectemplate-tree-sitter.spec
index a0a5c0f..4dfee24 100644
--- a/spectemplate-tree-sitter.spec
+++ b/spectemplate-tree-sitter.spec
@@ -53,6 +53,10 @@ Libraries and header files for developing applications that use
 find $RPM_BUILD_ROOT -name '*.a' -delete
 
 
+%check
+%{__make} test
+
+
 %{?ldconfig_scriptlets}
 
 

From 5650e06989ebae1a6a56035ab131ced9a68ebf5a Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Oct 10 2024 11:52:10 +0000
Subject: [PATCH 6/6] Tree-sitter tests require /usr/bin/tree-sitter.


---

diff --git a/spectemplate-tree-sitter.spec b/spectemplate-tree-sitter.spec
index 4dfee24..60b964d 100644
--- a/spectemplate-tree-sitter.spec
+++ b/spectemplate-tree-sitter.spec
@@ -14,6 +14,7 @@ URL:            https://github.com/tree-sitter/%{name}
 
 Source:         %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
 
+BuildRequires:  /usr/bin/tree-sitter
 BuildRequires:  gcc
 BuildRequires:  libtree-sitter-devel
 BuildRequires:  make

