gnu: tree-sitter-cli: Enable some tests and add node and dot.

* gnu/packages/tree-sitter.scm (tree-sitter-cli)[inputs]: Add graphviz and
node-lts.
[arguments]<#:cargo-test-flags>: Skip tests that require downloading grammars.
<#:phases>: Add 'patch-node and 'patch-dot phases.  Tweak install phase.

Signed-off-by: Andrew Tropin <andrew@trop.in>
This commit is contained in:
Pierre Langlois 2022-03-29 20:13:11 +01:00 committed by Andrew Tropin
parent 18f1a4d38a
commit 5401b5822a
No known key found for this signature in database
GPG Key ID: 2208D20958C1DEB0

View File

@ -1,6 +1,6 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Luis Henrique Gomes Higino <luishenriquegh2701@gmail.com> ;;; Copyright © 2022 Luis Henrique Gomes Higino <luishenriquegh2701@gmail.com>
;;; Copyright © 2022 Pierre Langlois <pierre.langlois@gmx.com> ;;; Copyright © 2022, 2023 Pierre Langlois <pierre.langlois@gmx.com>
;;; Copyright © 2022 muradm <mail@muradm.net> ;;; Copyright © 2022 muradm <mail@muradm.net>
;;; Copyright © 2022 Aleksandr Vityazev <avityazev@posteo.org> ;;; Copyright © 2022 Aleksandr Vityazev <avityazev@posteo.org>
;;; Copyright © 2023 Andrew Tropin <andrew@trop.in> ;;; Copyright © 2023 Andrew Tropin <andrew@trop.in>
@ -24,7 +24,9 @@
#:use-module ((guix licenses) #:prefix license:) #:use-module ((guix licenses) #:prefix license:)
#:use-module (gnu packages crates-graphics) #:use-module (gnu packages crates-graphics)
#:use-module (gnu packages crates-io) #:use-module (gnu packages crates-io)
#:use-module (gnu packages graphviz)
#:use-module (gnu packages icu4c) #:use-module (gnu packages icu4c)
#:use-module (gnu packages node)
#:use-module (guix build-system cargo) #:use-module (guix build-system cargo)
#:use-module (guix build-system gnu) #:use-module (guix build-system gnu)
#:use-module (guix gexp) #:use-module (guix gexp)
@ -63,8 +65,8 @@
(synopsis "Incremental parsing system for programming tools") (synopsis "Incremental parsing system for programming tools")
(description (description
"Tree-sitter is a parser generator tool and an incremental parsing "Tree-sitter is a parser generator tool and an incremental parsing
library. It can build a concrete syntax tree for a source file and efficiently library. It can build a concrete syntax tree for a source file and
update the syntax tree as the source file is edited. efficiently update the syntax tree as the source file is edited.
Tree-sitter aims to be: Tree-sitter aims to be:
@ -80,7 +82,8 @@ This package includes the @code{libtree-sitter} runtime library.")
(license license:expat))) (license license:expat)))
(define-public tree-sitter-cli (define-public tree-sitter-cli
(package (inherit tree-sitter) (package
(inherit tree-sitter)
(name "tree-sitter-cli") (name "tree-sitter-cli")
(source (origin (source (origin
(inherit (package-source tree-sitter)) (inherit (package-source tree-sitter))
@ -96,13 +99,30 @@ This package includes the @code{libtree-sitter} runtime library.")
println!(\"cargo:rustc-link-lib=tree-sitter\");~@ println!(\"cargo:rustc-link-lib=tree-sitter\");~@
}~%"))))))) }~%")))))))
(build-system cargo-build-system) (build-system cargo-build-system)
(inputs (list tree-sitter)) (inputs
(list tree-sitter graphviz node-lts))
(arguments (arguments
(list (list
;; Running test requires downloading fixtures, see the #:cargo-test-flags
;; script/fetch-fixtures script, which fetches grammars. Maybe it make ''("--release" "--"
;; sence to run tests in the grammar's packages? ;; Skip tests which rely on downloading grammar fixtures. It is
#:tests? #f ;; difficult to support such tests given upstream does not encode
;; which version of the grammars are expected.
;; Instead, we do run some tests for each grammar in the tree-sitter
;; build-system, by running `tree-sitter test'. This isn't as
;; complete as running all tests from tree-sitter-cli, but it's a
;; good compromise compared to maintaining two different sets of
;; grammars (Guix packages vs test fixtures).
"--skip=tests::corpus_test"
"--skip=tests::highlight_test"
"--skip=tests::node_test"
"--skip=tests::parser_test"
"--skip=tests::pathological_test"
"--skip=tests::query_test"
"--skip=tests::tags_test"
"--skip=tests::test_highlight_test"
"--skip=tests::test_tags_test"
"--skip=tests::tree_test")
;; We're only packaging the CLI program so we do not need to install ;; We're only packaging the CLI program so we do not need to install
;; sources. ;; sources.
#:install-source? #f #:install-source? #f
@ -132,8 +152,20 @@ This package includes the @code{libtree-sitter} runtime library.")
(add-after 'unpack 'delete-cargo-lock (add-after 'unpack 'delete-cargo-lock
(lambda _ (lambda _
(delete-file "Cargo.lock"))) (delete-file "Cargo.lock")))
(add-after 'unpack 'patch-node
(lambda _
(substitute* "cli/src/generate/mod.rs"
(("Command::new\\(\"node\"\\)")
(string-append
"Command::new(\"" #$node-lts "/bin/node\")")))))
(add-after 'unpack 'patch-dot
(lambda _
(substitute* "cli/src/util.rs"
(("Command::new\\(\"dot\"\\)")
(string-append
"Command::new(\"" #$graphviz "/bin/dot\")")))))
(replace 'install (replace 'install
(lambda* (#:key outputs #:allow-other-keys) (lambda _
(let ((bin (string-append #$output "/bin"))) (let ((bin (string-append #$output "/bin")))
(mkdir-p bin) (mkdir-p bin)
(install-file "target/release/tree-sitter" bin))))))) (install-file "target/release/tree-sitter" bin)))))))