aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludovic.courtes@inria.fr>2020-09-28 18:56:00 +0200
committerLudovic Courtès <ludo@gnu.org>2020-10-12 18:23:47 +0200
commitabd7a474615353149a44f4504f0b4b248dcc0716 (patch)
tree65552219618748955e15cd1154f51a9b2642dfa3 /tests
parent46135ce4cefab9e164d75697d7ea0c8359b842e4 (diff)
downloadguix-abd7a474615353149a44f4504f0b4b248dcc0716.tar
guix-abd7a474615353149a44f4504f0b4b248dcc0716.tar.gz
guix build: Add '--with-c-toolchain'.
* guix/scripts/build.scm (package-dependents/spec) (package-toolchain-rewriting, transform-package-toolchain): New procedures. (%transformations): Add it. (%transformation-options, show-transformation-options-help): Add '--with-c-toolchain'. * tests/scripts-build.scm (depends-on-toolchain?): New procedure. ("options->transformation, with-c-toolchain") ("options->transformation, with-c-toolchain twice") New test. ("options->transformation, with-c-toolchain, no effect"): New tests. * doc/guix.texi (Package Transformation Options): Document it.
Diffstat (limited to 'tests')
-rw-r--r--tests/scripts-build.scm82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/scripts-build.scm b/tests/scripts-build.scm
index 5f91360953..6925374baa 100644
--- a/tests/scripts-build.scm
+++ b/tests/scripts-build.scm
@@ -22,6 +22,8 @@
#:use-module (guix derivations)
#:use-module (guix packages)
#:use-module (guix git-download)
+ #:use-module (guix build-system)
+ #:use-module (guix build-system gnu)
#:use-module (guix scripts build)
#:use-module (guix ui)
#:use-module (guix utils)
@@ -30,6 +32,8 @@
#:use-module (gnu packages base)
#:use-module (gnu packages busybox)
#:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
#:use-module (srfi srfi-64))
@@ -270,6 +274,80 @@
((("x" dep3))
(map package-source (list dep1 dep3))))))))))))
+(define* (depends-on-toolchain? p #:optional (toolchain "gcc-toolchain"))
+ "Return true if P depends on TOOLCHAIN instead of the default tool chain."
+ (define toolchain-packages
+ '("gcc" "binutils" "glibc" "ld-wrapper"))
+
+ (define (package-name* obj)
+ (and (package? obj) (package-name obj)))
+
+ (match (bag-build-inputs (package->bag p))
+ (((_ (= package-name* packages) . _) ...)
+ (and (not (any (cut member <> packages) toolchain-packages))
+ (member toolchain packages)))))
+
+(test-assert "options->transformation, with-c-toolchain"
+ (let* ((dep0 (dummy-package "chbouib"
+ (build-system gnu-build-system)
+ (native-inputs `(("y" ,grep)))))
+ (dep1 (dummy-package "stuff"
+ (native-inputs `(("x" ,dep0)))))
+ (p (dummy-package "thingie"
+ (build-system gnu-build-system)
+ (inputs `(("foo" ,grep)
+ ("bar" ,dep1)))))
+ (t (options->transformation
+ '((with-c-toolchain . "chbouib=gcc-toolchain")))))
+ ;; Here we check that the transformation applies to DEP0 and all its
+ ;; dependents: DEP0 must use GCC-TOOLCHAIN, DEP1 must use GCC-TOOLCHAIN
+ ;; and the DEP0 that uses GCC-TOOLCHAIN, and so on.
+ (with-store store
+ (let ((new (t store p)))
+ (and (depends-on-toolchain? new "gcc-toolchain")
+ (match (bag-build-inputs (package->bag new))
+ ((("foo" dep0) ("bar" dep1) _ ...)
+ (and (depends-on-toolchain? dep1 "gcc-toolchain")
+ (not (depends-on-toolchain? dep0 "gcc-toolchain"))
+ (string=? (package-full-name dep0)
+ (package-full-name grep))
+ (match (bag-build-inputs (package->bag dep1))
+ ((("x" dep) _ ...)
+ (and (depends-on-toolchain? dep "gcc-toolchain")
+ (match (bag-build-inputs (package->bag dep))
+ ((("y" dep) _ ...) ;this one is unchanged
+ (eq? dep grep))))))))))))))
+
+(test-equal "options->transformation, with-c-toolchain twice"
+ (package-full-name grep)
+ (let* ((dep0 (dummy-package "chbouib"))
+ (dep1 (dummy-package "stuff"))
+ (p (dummy-package "thingie"
+ (build-system gnu-build-system)
+ (inputs `(("foo" ,dep0)
+ ("bar" ,dep1)
+ ("baz" ,grep)))))
+ (t (options->transformation
+ '((with-c-toolchain . "chbouib=clang-toolchain")
+ (with-c-toolchain . "stuff=clang-toolchain")))))
+ (with-store store
+ (let ((new (t store p)))
+ (and (depends-on-toolchain? new "clang-toolchain")
+ (match (bag-build-inputs (package->bag new))
+ ((("foo" dep0) ("bar" dep1) ("baz" dep2) _ ...)
+ (and (depends-on-toolchain? dep0 "clang-toolchain")
+ (depends-on-toolchain? dep1 "clang-toolchain")
+ (not (depends-on-toolchain? dep2 "clang-toolchain"))
+ (package-full-name dep2)))))))))
+
+(test-assert "options->transformation, with-c-toolchain, no effect"
+ (let ((p (dummy-package "thingie"))
+ (t (options->transformation
+ '((with-c-toolchain . "does-not-exist=gcc-toolchain")))))
+ ;; When it has no effect, '--with-c-toolchain' returns P.
+ (with-store store
+ (eq? (t store p) p))))
+
(test-assert "options->transformation, without-tests"
(let* ((dep (dummy-package "dep"))
(p (dummy-package "foo"
@@ -286,3 +364,7 @@
'(#:tests? #f))))))))
(test-end)
+
+;;; Local Variables:
+;;; eval: (put 'dummy-package 'scheme-indent-function 1)
+;;; End: