[PATCH 0/3 rust-team] guix: cargo-build-system: Add test keys.

  • Open
  • quality assurance status badge
Details
One participant
  • Jaeme Sifat
Owner
unassigned
Submitted by
Jaeme Sifat
Severity
normal
J
J
Jaeme Sifat wrote on 21 Dec 2023 06:11
(address . guix-patches@gnu.org)(name . Jaeme Sifat)(address . jaeme@runbox.com)
cover.1703135457.git.jaeme@runbox.com
I propose adding two new keys for the 'check phase of the
cargo-build-system. One is #:cargo-skip-tests which accepts a list of
strings representing the names of the tests to be skipped and the
other is #:cargo-test-targets which accepts a list of strings
representing the test targets to be ran.

The goal of adding these two keys is to make it so that the packager
doesn't have to interface directly with #:cargo-test-flags which is
set to --release mode by default. I believe that this leads to cleaner
looking build definitions that should be easier to bind to something
say, a web-based package definition editor that exists right now.

These patches are just a draft of this feature I cooked up. Here's
what they should look like in action with the rust-alsa crate:

Toggle snippet (26 lines)
(define-public rust-alsa-0.8
(package
...
(build-system cargo-build-system)
(arguments
`(#:cargo-test-targets
(list "lib"
"bins"
"tests")
#:cargo-skip-tests
(list "pcm::drop"
"pcm::info_from_default"
"pcm::playback_to_default"
"pcm::record_from_default"
"seq::print_seqs"
"seq::seq_loopback"
"seq::seq_portsubscribeiter"
"seq::seq_subscribe")
#:cargo-inputs
(("rust-alsa-sys" ,rust-alsa-sys-0.3)
("rust-bitflags" ,rust-bitflags-2)
("rust-libc" ,rust-libc-0.2)
("rust-nix" ,rust-nix-0.26))))
...))

I would like to hear the feedback on this change and its
implementation. Of course, if this change is accepted, then there
ought to be an update to the Rust crates section of 'Contributing' in
the Guix manual that details this.

Jaeme Sifat (3):
guix: build-system: cargo: Add cargo-skip-tests.
guix: build-system: cargo: Add cargo-test-targets.
guix: Add copyright notice.

guix/build-system/cargo.scm | 9 +++++++++
guix/build/cargo-build-system.scm | 20 +++++++++++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)


base-commit: 49a7a95ba44e231e9e15a274f9a96de6fa012daf
--
2.41.0
J
J
Jaeme Sifat wrote on 21 Dec 2023 06:28
[PATCH 1/3] guix: build-system: cargo: Add cargo-skip-tests.
(address . 67947@debbugs.gnu.org)(name . Jaeme Sifat)(address . jaeme@runbox.com)
a6fe9279323eb1fac32153134c5a0bf34ce8cb17.1703135457.git.jaeme@runbox.com
The #:cargo-skip-tests key accepts a list of strings that represent the names
of tests to be skipped by passing the "--skip=<test-name>" to cargo test. This
is so that the packager doesn't have to edit #:cargo-test-flags directly when
trying to skip tests.

* guix/build-system/cargo.scm (cargo-build): Add cargo-skip-tests.
* guix/build-system/cargo.scm (builder): Add cargo-skip-tests.
* guix/build-system/cargo.scm (cargo-cross-build): Add cargo-skip-tests.
* guix/build/cargo-build-system.scm (check): Add cargo-skip-tests.

Change-Id: I2f64370cf29b9495a33a8e072ab930b8635e742d
---
guix/build-system/cargo.scm | 4 ++++
guix/build/cargo-build-system.scm | 10 +++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)

Toggle diff (63 lines)
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index c029cc1dda..d2a45f0609 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -86,6 +86,7 @@ (define* (cargo-build name inputs
(vendor-dir "guix-vendor")
(cargo-build-flags ''("--release"))
(cargo-test-flags ''("--release"))
+ (cargo-skip-tests ''())
(cargo-package-flags ''("--no-metadata" "--no-verify"))
(features ''())
(skip-build? #f)
@@ -112,6 +113,7 @@ (define* (cargo-build name inputs
#:vendor-dir #$vendor-dir
#:cargo-build-flags #$(sexp->gexp cargo-build-flags)
#:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+ #:cargo-skip-tests #$(sexp->gexp cargo-skip-tests)
#:cargo-package-flags #$(sexp->gexp cargo-package-flags)
#:features #$(sexp->gexp features)
#:skip-build? #$skip-build?
@@ -141,6 +143,7 @@ (define* (cargo-cross-build name
(vendor-dir "guix-vendor")
(cargo-build-flags ''("--release"))
(cargo-test-flags ''("--release"))
+ (cargo-skip-tests ''())
(cargo-package-flags ''("--no-metadata" "--no-verify"))
(features ''())
(skip-build? #f)
@@ -169,6 +172,7 @@ (define* (cargo-cross-build name
#:vendor-dir #$vendor-dir
#:cargo-build-flags #$(sexp->gexp cargo-build-flags)
#:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+ #:cargo-skip-tests #$(sexp->gexp cargo-skip-tests)
#:cargo-package-flags #$(sexp->gexp cargo-package-flags)
#:features #$(sexp->gexp features)
#:skip-build? #$skip-build?
diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index ffb2ec898e..7cdb2a72d3 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -258,11 +258,19 @@ (define* (build #:key
(define* (check #:key
tests?
+ cargo-skip-tests
(cargo-test-flags '("--release"))
#:allow-other-keys)
"Run tests for a given Cargo package."
(if tests?
- (apply invoke "cargo" "test" cargo-test-flags)
+ (if cargo-skip-tests
+ (let ((test-lst (map (lambda (test)
+ (string-append "--skip=" test))
+ cargo-skip-tests)))
+ (apply invoke "cargo" "test" (append
+ cargo-test-flags
+ (cons* "--" test-lst))))
+ (apply invoke "cargo" "test" cargo-test-flags))
#t))
(define* (package #:key
--
2.41.0
J
J
Jaeme Sifat wrote on 21 Dec 2023 06:28
[PATCH 2/3] guix: build-system: cargo: Add cargo-test-targets.
(address . 67947@debbugs.gnu.org)(name . Jaeme Sifat)(address . jaeme@runbox.com)
413c758092a856dae0c8e8b2e02a36dd1649e4cb.1703135457.git.jaeme@runbox.com
In addition to adding a key for skipping tests, there ought be a key for
specifying which test target(s) should be ran without having to edit
the #:cargo-test-flags key directly.

* guix/build-system/cargo.scm (cargo-build): Add cargo-test-targets.
* guix/build-system/cargo.scm (builder): Add cargo-test-targets.
* guix/build-system/cargo.scm (cargo-cross-build): Add cargo-test-targets.
* guix/build/cargo-build-system.scm (check): Add cargo-test-targets.

Change-Id: Ibdf3cffd2b0f3fdbfe269189975c739192c14f64
---
guix/build-system/cargo.scm | 4 ++++
guix/build/cargo-build-system.scm | 25 +++++++++++++++++--------
2 files changed, 21 insertions(+), 8 deletions(-)

Toggle diff (79 lines)
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index d2a45f0609..7878a3bd6d 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -86,6 +86,7 @@ (define* (cargo-build name inputs
(vendor-dir "guix-vendor")
(cargo-build-flags ''("--release"))
(cargo-test-flags ''("--release"))
+ (cargo-test-targets ''())
(cargo-skip-tests ''())
(cargo-package-flags ''("--no-metadata" "--no-verify"))
(features ''())
@@ -113,6 +114,7 @@ (define* (cargo-build name inputs
#:vendor-dir #$vendor-dir
#:cargo-build-flags #$(sexp->gexp cargo-build-flags)
#:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+ #:cargo-test-targets #$(sexp->gexp cargo-test-targets)
#:cargo-skip-tests #$(sexp->gexp cargo-skip-tests)
#:cargo-package-flags #$(sexp->gexp cargo-package-flags)
#:features #$(sexp->gexp features)
@@ -143,6 +145,7 @@ (define* (cargo-cross-build name
(vendor-dir "guix-vendor")
(cargo-build-flags ''("--release"))
(cargo-test-flags ''("--release"))
+ (cargo-test-targets ''())
(cargo-skip-tests ''())
(cargo-package-flags ''("--no-metadata" "--no-verify"))
(features ''())
@@ -172,6 +175,7 @@ (define* (cargo-cross-build name
#:vendor-dir #$vendor-dir
#:cargo-build-flags #$(sexp->gexp cargo-build-flags)
#:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+ #:cargo-test-targets #$(sexp->gexp cargo-test-targets)
#:cargo-skip-tests #$(sexp->gexp cargo-skip-tests)
#:cargo-package-flags #$(sexp->gexp cargo-package-flags)
#:features #$(sexp->gexp features)
diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index 7cdb2a72d3..5abedfc726 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -258,19 +258,28 @@ (define* (build #:key
(define* (check #:key
tests?
+ cargo-test-targets
cargo-skip-tests
(cargo-test-flags '("--release"))
#:allow-other-keys)
"Run tests for a given Cargo package."
(if tests?
- (if cargo-skip-tests
- (let ((test-lst (map (lambda (test)
- (string-append "--skip=" test))
- cargo-skip-tests)))
- (apply invoke "cargo" "test" (append
- cargo-test-flags
- (cons* "--" test-lst))))
- (apply invoke "cargo" "test" cargo-test-flags))
+ (let* ((cargo-test-targets-flags
+ (when cargo-test-targets
+ (map (lambda (section)
+ (string-append "--" section))
+ cargo-test-targets)))
+ (cargo-skip-tests-flags
+ (when cargo-skip-tests
+ (map (lambda (test)
+ (string-append "--skip=" test))
+ cargo-skip-tests)))
+ (cargo-test-flags
+ (append cargo-test-flags
+ cargo-test-targets-flags
+ '("--")
+ cargo-skip-tests-flags)))
+ (apply invoke "cargo" "test" cargo-test-flags))
#t))
(define* (package #:key
--
2.41.0
J
J
Jaeme Sifat wrote on 21 Dec 2023 06:28
[PATCH 3/3] guix: Add copyright notice.
(address . 67947@debbugs.gnu.org)(name . Jaeme Sifat)(address . jaeme@runbox.com)
bccff746827ec141eb3fc8d4399710f4bcc6cf3d.1703135457.git.jaeme@runbox.com
* guix/build-system/cargo.scm: Add copyright notice.
* guix/build/cargo-build-system.scm: Add copyright notice.

Change-Id: I1ccffda9ce10e9bbe75ba573b7de763d0c42d899
---
guix/build-system/cargo.scm | 1 +
guix/build/cargo-build-system.scm | 1 +
2 files changed, 2 insertions(+)

Toggle diff (26 lines)
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index 7878a3bd6d..ef78a18b5f 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -6,6 +6,7 @@
;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com>
;;; Copyright © 2020 Jakub K?dzio?ka <kuba@kadziolka.net>
;;; Copyright © 2021 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2023 Jaeme Sifat <jaeme@runbox.com>
;;;
;;; This file is part of GNU Guix.
;;;
diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index 5abedfc726..3c74d11911 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2019-2023 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2020 Jakub K?dzio?ka <kuba@kadziolka.net>
;;; Copyright © 2020 Marius Bakke <marius@gnu.org>
+;;; Copyright © 2023 Jaeme Sifat <jaeme@runbox.com>
;;;
;;; This file is part of GNU Guix.
;;;
--
2.41.0
?