unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#43581] [PATCH] guix build: Add '--without-tests'.
@ 2020-09-23 20:42 Ludovic Courtès
  2020-09-23 21:05 ` Jan Nieuwenhuizen
  2020-09-23 21:37 ` [bug#43581] " Ricardo Wurmus
  0 siblings, 2 replies; 4+ messages in thread
From: Ludovic Courtès @ 2020-09-23 20:42 UTC (permalink / raw)
  To: 43581; +Cc: Ludovic Courtès

* guix/scripts/build.scm (transform-package-tests): New procedure.
(%transformations, %transformation-options)
show-transformation-options-help): Add it.
* tests/scripts-build.scm ("options->transformation, without-tests"):
New test.
* doc/guix.texi (Package Transformation Options): Document it.
---
 doc/guix.texi           | 22 ++++++++++++++++++++++
 guix/scripts/build.scm  | 31 ++++++++++++++++++++++++++++---
 tests/scripts-build.scm | 14 ++++++++++++++
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 949551a163..67d0a70ae0 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -9270,6 +9270,28 @@ guix build --with-branch=guile-sqlite3=master cuirass
 This is similar to @option{--with-branch}, except that it builds from
 @var{commit} rather than the tip of a branch.  @var{commit} must be a valid
 Git commit SHA1 identifier or a tag.
+
+@cindex test suite, skipping
+@item --without-tests=@var{package}
+Build @var{package} without running its tests.  This can be useful in
+situations where you want to skip the lengthy test suite of a
+intermediate package, or if a package's test suite fails in a
+non-deterministic fashion.  It should be used with care because running
+the test suite is a good way to ensure a package is working as intended.
+
+Turning off tests leads to a different store item.  Consequently, when
+using this option, anything that depends on @var{package} must be
+rebuilt, as in this example:
+
+@example
+guix install --without-tests=python python-notebook
+@end example
+
+The command above installs @code{python-notebook} on top of
+@code{python} built without running its test suite.  To do so, it also
+rebuilds everything that depends on @code{python}, including
+@code{python-notebook} itself.
+
 @end table
 
 @node Additional Build Options
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 38e0516c95..f238e9b876 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -393,6 +393,25 @@ a checkout of the Git repository at the given URL."
         (rewrite obj)
         obj)))
 
+(define (transform-package-tests specs)
+  "Return a procedure that, when passed a package, sets #:tests? #f in its
+'arguments' field."
+  (define (package-without-tests p)
+    (package/inherit p
+      (arguments
+       (substitute-keyword-arguments (package-arguments p)
+         ((#:tests? _ #f) #f)))))
+
+  (define rewrite
+    (package-input-rewriting/spec (map (lambda (spec)
+                                         (cons spec package-without-tests))
+                                       specs)))
+
+  (lambda (store obj)
+    (if (package? obj)
+        (rewrite obj)
+        obj)))
+
 (define %transformations
   ;; Transformations that can be applied to things to build.  The car is the
   ;; key used in the option alist, and the cdr is the transformation
@@ -403,7 +422,8 @@ a checkout of the Git repository at the given URL."
     (with-graft  . ,transform-package-inputs/graft)
     (with-branch . ,transform-package-source-branch)
     (with-commit . ,transform-package-source-commit)
-    (with-git-url . ,transform-package-source-git-url)))
+    (with-git-url . ,transform-package-source-git-url)
+    (without-tests . ,transform-package-tests)))
 
 (define %transformation-options
   ;; The command-line interface to the above transformations.
@@ -423,7 +443,9 @@ a checkout of the Git repository at the given URL."
           (option '("with-commit") #t #f
                   (parser 'with-commit))
           (option '("with-git-url") #t #f
-                  (parser 'with-git-url)))))
+                  (parser 'with-git-url))
+          (option '("without-tests") #t #f
+                  (parser 'without-tests)))))
 
 (define (show-transformation-options-help)
   (display (G_ "
@@ -443,7 +465,10 @@ a checkout of the Git repository at the given URL."
                          build PACKAGE from COMMIT"))
   (display (G_ "
       --with-git-url=PACKAGE=URL
-                         build PACKAGE from the repository at URL")))
+                         build PACKAGE from the repository at URL"))
+  (display (G_ "
+      --without-tests=PACKAGE
+                         build PACKAGE without running its tests")))
 
 
 (define (options->transformation opts)
diff --git a/tests/scripts-build.scm b/tests/scripts-build.scm
index 32876e956a..12114fc8f5 100644
--- a/tests/scripts-build.scm
+++ b/tests/scripts-build.scm
@@ -264,5 +264,19 @@
                        ((("x" dep3))
                         (map package-source (list dep1 dep3))))))))))))
 
+(test-assert "options->transformation, without-tests"
+  (let* ((dep (dummy-package "dep"))
+         (p   (dummy-package "foo"
+                (inputs `(("dep" ,dep)))))
+         (t   (options->transformation '((without-tests . "dep")
+                                         (without-tests . "tar")))))
+    (with-store store
+      (let ((new (t store p)))
+        (match (bag-direct-inputs (package->bag new))
+          ((("dep" dep) ("tar" tar) _ ...)
+           ;; TODO: Check whether TAR has #:tests? #f when transformations
+           ;; apply to implicit inputs.
+           (equal? (package-arguments dep)
+                   '(#:tests? #f))))))))
 
 (test-end)
-- 
2.28.0





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

end of thread, other threads:[~2020-09-27 20:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 20:42 [bug#43581] [PATCH] guix build: Add '--without-tests' Ludovic Courtès
2020-09-23 21:05 ` Jan Nieuwenhuizen
2020-09-27 20:58   ` bug#43581: " Ludovic Courtès
2020-09-23 21:37 ` [bug#43581] " Ricardo Wurmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).