public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton
@ 2021-12-09  3:10 Vadim Misbakh-Soloviov
  2021-12-09  7:26 ` Michał Górny
  0 siblings, 1 reply; 5+ messages in thread
From: Vadim Misbakh-Soloviov @ 2021-12-09  3:10 UTC (permalink / raw
  To: gentoo-dev; +Cc: sarnex, matt, Vadim Misbakh-Soloviov

  Some grammars packages (like, for example, tree-sitter-agda) uses
  different versioning scheme from vast majority of grammars in
  tree-sitter github organization.

  Also, third-party grammars doesn't follow tree-sitter versioning.

  Also, some grammars (like tree-sitter-haskell, for example) only had
  old release tagged, but having compatible and useful grammars in
  current HEAD.

  Also, some grammars like tree-sitter-verilog, even have only v0.0 tag.

  So, instead of assuming grammar ABI version based on ${PV} (ver_test)
  we decided to take ABI version drectly from source code.
---
 eclass/tree-sitter-grammar.eclass | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass
index 46573027f96..939a36ccb8c 100644
--- a/eclass/tree-sitter-grammar.eclass
+++ b/eclass/tree-sitter-grammar.eclass
@@ -40,15 +40,13 @@ EXPORT_FUNCTIONS src_compile src_install
 # @INTERNAL
 # @DESCRIPTION:
 # This internal function determines the ABI version of a grammar library based
-# on the package version.
+# on a constant in the source file.
 _get_tsg_abi_ver() {
-	if ver_test -gt 0.21; then
-		die "Grammar too new; unknown ABI version"
-	elif ver_test -ge 0.19.0; then
-		echo 13
-	else
-		die "Grammar too old; unknown ABI version"
-	fi
+	# This sed script finds ABI definition string in parser source file,
+	# substitutes all the string until the ABI number, and prints remains
+	# (the ABI number itself)
+	sed -n '/#define LANGUAGE_VERSION/s/.* //p' "${S}"/parser.c ||
+		die "Unable to extract ABI version for this grammar"
 }

 # @FUNCTION: tree-sitter-grammar_src_compile
@@ -89,8 +87,10 @@ tree-sitter-grammar_src_compile() {
 tree-sitter-grammar_src_install() {
 	debug-print-function ${FUNCNAME} "${@}"

-	dolib.so "${WORKDIR}"/lib${PN}$(get_libname $(_get_tsg_abi_ver))
-	dosym lib${PN}$(get_libname $(_get_tsg_abi_ver)) \
+	local soname=lib${PN}$(get_libname $(_get_tsg_abi_ver))
+
+	dolib.so "${WORKDIR}/${soname}"
+	dosym "${soname}" \
 		  /usr/$(get_libdir)/lib${PN}$(get_libname)
 }
 fi
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton
  2021-12-09  3:10 [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton Vadim Misbakh-Soloviov
@ 2021-12-09  7:26 ` Michał Górny
  2021-12-09 16:27   ` Vadim Misbakh-Soloviov
  0 siblings, 1 reply; 5+ messages in thread
From: Michał Górny @ 2021-12-09  7:26 UTC (permalink / raw
  To: gentoo-dev; +Cc: sarnex, matt, Vadim Misbakh-Soloviov

On Thu, 2021-12-09 at 10:10 +0700, Vadim Misbakh-Soloviov wrote:
>   Some grammars packages (like, for example, tree-sitter-agda) uses
>   different versioning scheme from vast majority of grammars in
>   tree-sitter github organization.
> 
>   Also, third-party grammars doesn't follow tree-sitter versioning.
> 
>   Also, some grammars (like tree-sitter-haskell, for example) only had
>   old release tagged, but having compatible and useful grammars in
>   current HEAD.
> 
>   Also, some grammars like tree-sitter-verilog, even have only v0.0 tag.
> 
>   So, instead of assuming grammar ABI version based on ${PV} (ver_test)
>   we decided to take ABI version drectly from source code.
> ---
>  eclass/tree-sitter-grammar.eclass | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass
> index 46573027f96..939a36ccb8c 100644
> --- a/eclass/tree-sitter-grammar.eclass
> +++ b/eclass/tree-sitter-grammar.eclass
> @@ -40,15 +40,13 @@ EXPORT_FUNCTIONS src_compile src_install
>  # @INTERNAL
>  # @DESCRIPTION:
>  # This internal function determines the ABI version of a grammar library based
> -# on the package version.
> +# on a constant in the source file.
>  _get_tsg_abi_ver() {
> -	if ver_test -gt 0.21; then
> -		die "Grammar too new; unknown ABI version"
> -	elif ver_test -ge 0.19.0; then
> -		echo 13
> -	else
> -		die "Grammar too old; unknown ABI version"
> -	fi
> +	# This sed script finds ABI definition string in parser source file,
> +	# substitutes all the string until the ABI number, and prints remains
> +	# (the ABI number itself)
> +	sed -n '/#define LANGUAGE_VERSION/s/.* //p' "${S}"/parser.c ||

I think you can do:

  sed -n 's/#define LANGUAGE_VERSION //p' ...

'p' applies only on successful replacement.

> +		die "Unable to extract ABI version for this grammar"
>  }
> 
>  # @FUNCTION: tree-sitter-grammar_src_compile
> @@ -89,8 +87,10 @@ tree-sitter-grammar_src_compile() {
>  tree-sitter-grammar_src_install() {
>  	debug-print-function ${FUNCNAME} "${@}"
> 
> -	dolib.so "${WORKDIR}"/lib${PN}$(get_libname $(_get_tsg_abi_ver))
> -	dosym lib${PN}$(get_libname $(_get_tsg_abi_ver)) \
> +	local soname=lib${PN}$(get_libname $(_get_tsg_abi_ver))
> +
> +	dolib.so "${WORKDIR}/${soname}"
> +	dosym "${soname}" \
>  		  /usr/$(get_libdir)/lib${PN}$(get_libname)
>  }
>  fi

-- 
Best regards,
Michał Górny



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton
  2021-12-09  7:26 ` Michał Górny
@ 2021-12-09 16:27   ` Vadim Misbakh-Soloviov
  2021-12-09 16:29     ` Vadim A. Misbakh-Soloviov
  0 siblings, 1 reply; 5+ messages in thread
From: Vadim Misbakh-Soloviov @ 2021-12-09 16:27 UTC (permalink / raw
  To: gentoo-dev; +Cc: sarnex, matt

  Some grammars packages (like, for example, tree-sitter-agda) uses
  different versioning scheme from vast majority of grammars in
  tree-sitter github organization.

  Also, third-party grammars doesn't follow tree-sitter versioning.

  Also, some grammars (like tree-sitter-haskell, for example) only had
  old release tagged, but having compatible and useful grammars in
  current HEAD.

  Also, some grammars like tree-sitter-verilog, even have only v0.0 tag.

  So, instead of assuming grammar ABI version based on ${PV} (ver_test)
  we decided to take ABI version drectly from source code.

Signed-off-by: Vadim Misbakh-Soloviov <mva@gentoo.org>
---
Changes since previous commit: applied @mgorny's suggestion about sed
script.

 eclass/tree-sitter-grammar.eclass | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass
index 46573027f96..7207ecf3ddd 100644
--- a/eclass/tree-sitter-grammar.eclass
+++ b/eclass/tree-sitter-grammar.eclass
@@ -40,15 +40,13 @@ EXPORT_FUNCTIONS src_compile src_install
 # @INTERNAL
 # @DESCRIPTION:
 # This internal function determines the ABI version of a grammar library based
-# on the package version.
+# on a constant in the source file.
 _get_tsg_abi_ver() {
-	if ver_test -gt 0.21; then
-		die "Grammar too new; unknown ABI version"
-	elif ver_test -ge 0.19.0; then
-		echo 13
-	else
-		die "Grammar too old; unknown ABI version"
-	fi
+	# This sed script finds ABI definition string in parser source file,
+	# substitutes all the string until the ABI number, and prints remains
+	# (the ABI number itself)
+	sed -n 's/#define LANGUAGE_VERSION //p' "${S}"/parser.c ||
+		die "Unable to extract ABI version for this grammar"
 }

 # @FUNCTION: tree-sitter-grammar_src_compile
@@ -89,8 +87,10 @@ tree-sitter-grammar_src_compile() {
 tree-sitter-grammar_src_install() {
 	debug-print-function ${FUNCNAME} "${@}"

-	dolib.so "${WORKDIR}"/lib${PN}$(get_libname $(_get_tsg_abi_ver))
-	dosym lib${PN}$(get_libname $(_get_tsg_abi_ver)) \
+	local soname=lib${PN}$(get_libname $(_get_tsg_abi_ver))
+
+	dolib.so "${WORKDIR}/${soname}"
+	dosym "${soname}" \
 		  /usr/$(get_libdir)/lib${PN}$(get_libname)
 }
 fi
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton
  2021-12-09 16:27   ` Vadim Misbakh-Soloviov
@ 2021-12-09 16:29     ` Vadim A. Misbakh-Soloviov
  2021-12-20  4:13       ` Vadim A. Misbakh-Soloviov
  0 siblings, 1 reply; 5+ messages in thread
From: Vadim A. Misbakh-Soloviov @ 2021-12-09 16:29 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 120 bytes --]

oops, forgot `v2` in subject.

Added it all the time during pre-send tests, and missed when sent it for real

:facepalm:

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 358 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton
  2021-12-09 16:29     ` Vadim A. Misbakh-Soloviov
@ 2021-12-20  4:13       ` Vadim A. Misbakh-Soloviov
  0 siblings, 0 replies; 5+ messages in thread
From: Vadim A. Misbakh-Soloviov @ 2021-12-20  4:13 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 44 bytes --]

Merged to gentoo repo

-- 
Best regards,
mva

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 358 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-20  4:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-09  3:10 [gentoo-dev] [PATCH] eclass/tree-sitter-grammar: fix ABI autodetecton Vadim Misbakh-Soloviov
2021-12-09  7:26 ` Michał Górny
2021-12-09 16:27   ` Vadim Misbakh-Soloviov
2021-12-09 16:29     ` Vadim A. Misbakh-Soloviov
2021-12-20  4:13       ` Vadim A. Misbakh-Soloviov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox