From 645b9df858683dc05ffa04c9eb2fdc45ccef4a65 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 17 Oct 2016 23:40:03 +0200 Subject: guix build: Add '--with-graft'. * guix/scripts/build.scm (transform-package-inputs/graft): New procedure. (%transformations): Add 'with-graft'. (%transformation-options): Likewise. (show-transformation-options-help): Document it. * tests/scripts-build.scm ("options->transformation, with-graft"): New test. * doc/guix.texi (Package Transformation Options): Document it. --- tests/scripts-build.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/scripts-build.scm b/tests/scripts-build.scm index e48c8da264..e2610904e2 100644 --- a/tests/scripts-build.scm +++ b/tests/scripts-build.scm @@ -102,4 +102,23 @@ ((("x" dep)) (eq? dep findutils))))))))))) +(test-assert "options->transformation, with-graft" + (let* ((p (dummy-package "guix.scm" + (inputs `(("foo" ,grep) + ("bar" ,(dummy-package "chbouib" + (native-inputs `(("x" ,grep))))))))) + (t (options->transformation '((with-input . "grep=findutils"))))) + (with-store store + (let ((new (t store p))) + (and (not (eq? new p)) + (match (package-inputs new) + ((("foo" dep1) ("bar" dep2)) + (and (string=? (package-full-name dep1) + (package-full-name grep)) + (eq? (package-replacement dep1) findutils) + (string=? (package-name dep2) "chbouib") + (match (package-native-inputs dep2) + ((("x" dep)) + (eq? (package-replacement dep) findutils))))))))))) + (test-end) -- cgit v1.2.3 From 3d47aa81ba4c19b45ce9a9ff0ece0252777ea8ed Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 17 Oct 2016 23:43:33 +0200 Subject: grafts: Apply the right grafts in the presence of multiple outputs. Fixes . * guix/grafts.scm (cumulative-grafts): Add grafts for all the outputs of DRV. * tests/grafts.scm ("graft-derivation, replaced derivation has multiple outputs"): New test. --- guix/grafts.scm | 15 +++++++++++++-- tests/grafts.scm | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/guix/grafts.scm b/guix/grafts.scm index 80ae27e9b0..dda7c1d235 100644 --- a/guix/grafts.scm +++ b/guix/grafts.scm @@ -280,8 +280,19 @@ derivations to the corresponding set of grafts." (let* ((new (graft-derivation/shallow store drv applicable #:guile guile #:system system)) - (grafts (cons (graft (origin drv) (replacement new)) - grafts))) + + ;; Replace references to any of the outputs of DRV, + ;; even if that's more than needed. This is so that + ;; the result refers only to the outputs of NEW and + ;; not to those of DRV. + (grafts (append (map (lambda (output) + (graft + (origin drv) + (origin-output output) + (replacement new) + (replacement-output output))) + (derivation-output-names drv)) + grafts))) (return/cache cache grafts)))))))))))) (define* (graft-derivation store drv grafts diff --git a/tests/grafts.scm b/tests/grafts.scm index 4eff06b4b3..6454a03b1f 100644 --- a/tests/grafts.scm +++ b/tests/grafts.scm @@ -201,6 +201,54 @@ (and (string=? (readlink one) repl) (string=? (readlink two) one)))))) +(test-assert "graft-derivation, replaced derivation has multiple outputs" + ;; Here we have a replacement just for output "one" of P1 and not for the + ;; other output. Make sure the graft for P1:one correctly applies to the + ;; dependents of P1. See . + (let* ((p1 (build-expression->derivation + %store "p1" + `(let ((one (assoc-ref %outputs "one")) + (two (assoc-ref %outputs "two"))) + (mkdir one) + (mkdir two)) + #:outputs '("one" "two"))) + (p1r (build-expression->derivation + %store "P1" + `(let ((other (assoc-ref %outputs "ONE"))) + (mkdir other) + (call-with-output-file (string-append other "/replacement") + (const #t))) + #:outputs '("ONE"))) + (p2 (build-expression->derivation + %store "p2" + `(let ((out (assoc-ref %outputs "aaa"))) + (mkdir (assoc-ref %outputs "zzz")) + (mkdir out) (chdir out) + (symlink (assoc-ref %build-inputs "p1:one") "one") + (symlink (assoc-ref %build-inputs "p1:two") "two")) + #:outputs '("aaa" "zzz") + #:inputs `(("p1:one" ,p1 "one") + ("p1:two" ,p1 "two")))) + (p3 (build-expression->derivation + %store "p3" + `(symlink (assoc-ref %build-inputs "p2:aaa") + (assoc-ref %outputs "out")) + #:inputs `(("p2:aaa" ,p2 "aaa") + ("p2:zzz" ,p2 "zzz")))) + (p1g (graft + (origin p1) + (origin-output "one") + (replacement p1r) + (replacement-output "ONE"))) + (p3d (graft-derivation %store p3 (list p1g)))) + (and (build-derivations %store (list p3d)) + (let ((out (derivation->output-path (pk 'p2d p3d)))) + (and (not (string=? (readlink out) + (derivation->output-path p2 "aaa"))) + (string=? (derivation->output-path p1 "two") + (readlink (string-append out "/two"))) + (file-exists? (string-append out "/one/replacement"))))))) + (test-assert "graft-derivation, renaming" ; (let* ((build `(begin (use-modules (guix build utils)) -- cgit v1.2.3 From 7fee5b53973fb4fe049aa0bc5db58093727bdf30 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 18 Oct 2016 23:22:03 +0200 Subject: container: Allow 'container-excursion' to the same namespaces. Before that, 'container-excursion' would call 'setns' even when the target namespace is the one the caller is already in, which would fail. * gnu/build/linux-container.scm (container-excursion): Introduce 'source' and 'target'. Compare the result of 'readlink' on these instead of comparing file descriptors to decide whether to call 'setns'. * tests/containers.scm ("container-excursion, same namespace"): New test. --- gnu/build/linux-container.scm | 20 +++++++++++--------- tests/containers.scm | 9 +++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index 91996d06ca..3fccc9addb 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm @@ -291,15 +291,17 @@ return the exit status." (call-with-clean-exit (lambda () (for-each (lambda (ns) - (call-with-input-file (namespace-file (getpid) ns) - (lambda (current-ns-port) - (call-with-input-file (namespace-file pid ns) - (lambda (new-ns-port) - ;; Joining the namespace that the process - ;; already belongs to would throw an error. - (unless (= (port->fdes current-ns-port) - (port->fdes new-ns-port)) - (setns (port->fdes new-ns-port) 0))))))) + (let ((source (namespace-file (getpid) ns)) + (target (namespace-file pid ns))) + ;; Joining the namespace that the process already + ;; belongs to would throw an error so avoid that. + ;; XXX: This /proc interface leads to TOCTTOU. + (unless (string=? (readlink source) (readlink target)) + (call-with-input-file source + (lambda (current-ns-port) + (call-with-input-file target + (lambda (new-ns-port) + (setns (fileno new-ns-port) 0)))))))) ;; It's important that the user namespace is joined first, ;; so that the user will have the privileges to join the ;; other namespaces. Furthermore, it's important that the diff --git a/tests/containers.scm b/tests/containers.scm index bbcff3f51f..698bef3e47 100644 --- a/tests/containers.scm +++ b/tests/containers.scm @@ -162,4 +162,13 @@ (waitpid pid) (zero? result))))))) +(skip-if-unsupported) +(test-equal "container-excursion, same namespaces" + 42 + ;; The parent and child are in the same namespaces. 'container-excursion' + ;; should notice that and avoid calling 'setns' since that would fail. + (container-excursion (getpid) + (lambda () + (primitive-exit 42)))) + (test-end) -- cgit v1.2.3 From 4bb54cc42ff5653fe59f5a8ebf39515ba1840a6d Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 19 Oct 2016 13:55:25 +0200 Subject: lint: Suggest @code instead of quotes. * guix/scripts/lint.scm (%quoted-identifier-rx): New variable. (check-description-style)[check-quotes]: New procedure. Use it. * tests/lint.scm ("description: suggest ornament instead of quotes"): New test. --- guix/scripts/lint.scm | 15 +++++++++++++++ tests/lint.scm | 8 ++++++++ 2 files changed, 23 insertions(+) (limited to 'tests') diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm index b3ec6d628e..d6281eae64 100644 --- a/guix/scripts/lint.scm +++ b/guix/scripts/lint.scm @@ -142,6 +142,10 @@ monad." "Return #t if S starts with what looks like an abbreviation or acronym." (string-match "^[A-Z][A-Z0-9]+\\>" s)) +(define %quoted-identifier-rx + ;; A quoted identifier, like 'this'. + (make-regexp "['`][[:graph:]]+'")) + (define (check-description-style package) ;; Emit a warning if stylistic issues are found in the description of PACKAGE. (define (check-not-empty description) @@ -173,6 +177,16 @@ trademark sign '~a' at ~d") 'description)) (else #t))) + (define (check-quotes description) + "Check whether DESCRIPTION contains single quotes and suggest @code." + (when (regexp-exec %quoted-identifier-rx description) + (emit-warning package + + ;; TRANSLATORS: '@code' is Texinfo markup and must be kept + ;; as is. + (_ "use @code or similar ornament instead of quotes") + 'description))) + (define (check-proper-start description) (unless (or (properly-starts-sentence? description) (string-prefix-ci? (package-name package) description)) @@ -203,6 +217,7 @@ by two spaces; possible infraction~p at ~{~a~^, ~}") (if (string? description) (begin (check-not-empty description) + (check-quotes description) (check-trademarks description) ;; Use raw description for this because Texinfo rendering ;; automatically fixes end of sentence space. diff --git a/tests/lint.scm b/tests/lint.scm index d692b42f93..fa2d19b2a6 100644 --- a/tests/lint.scm +++ b/tests/lint.scm @@ -218,6 +218,14 @@ string) on HTTP requests." (check-description-style pkg))) "should not contain trademark sign")))) +(test-assert "description: suggest ornament instead of quotes" + (->bool + (string-contains (with-warnings + (let ((pkg (dummy-package "x" + (description "This is a 'quoted' thing.")))) + (check-description-style pkg))) + "use @code"))) + (test-assert "synopsis: not a string" (->bool (string-contains (with-warnings -- cgit v1.2.3 From 0d7034ca4fa287f792a934dd3ac17905db683f4f Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 19 Oct 2016 15:17:06 +0200 Subject: tests: Fix typo in 'with-graft' transformation test. This is a followup to 645b9df858683dc05ffa04c9eb2fdc45ccef4a65. * tests/scripts-build.scm ("options->transformation, with-graft"): Use 'with-graft', not 'with-input'. --- tests/scripts-build.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/scripts-build.scm b/tests/scripts-build.scm index e2610904e2..b324012806 100644 --- a/tests/scripts-build.scm +++ b/tests/scripts-build.scm @@ -107,7 +107,7 @@ (inputs `(("foo" ,grep) ("bar" ,(dummy-package "chbouib" (native-inputs `(("x" ,grep))))))))) - (t (options->transformation '((with-input . "grep=findutils"))))) + (t (options->transformation '((with-graft . "grep=findutils"))))) (with-store store (let ((new (t store p))) (and (not (eq? new p)) -- cgit v1.2.3 From fe9bdb581e6c4a62795f4ced6f4a5a8eab1a34e4 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 19 Oct 2016 15:30:29 +0200 Subject: tests: Make sure child process of 'pivot-root' test exits. * tests/syscalls.scm ("pivot-root"): Use 'test-equal'. Wrap child body in 'dynamic-wind'. --- tests/syscalls.scm | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/syscalls.scm b/tests/syscalls.scm index 73fa8a7acf..1b31d87f23 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -148,25 +148,30 @@ (unless perform-container-tests? (test-skip 1)) -(test-assert "pivot-root" +(test-equal "pivot-root" + #t (match (pipe) ((in . out) (match (clone (logior CLONE_NEWUSER CLONE_NEWNS SIGCHLD)) (0 - (close in) - (call-with-temporary-directory - (lambda (root) - (let ((put-old (string-append root "/real-root"))) - (mount "none" root "tmpfs") - (mkdir put-old) - (call-with-output-file (string-append root "/test") - (lambda (port) - (display "testing\n" port))) - (pivot-root root put-old) - ;; The test file should now be located inside the root directory. - (write (file-exists? "/test") out) - (close out)))) - (primitive-exit 0)) + (dynamic-wind + (const #t) + (lambda () + (close in) + (call-with-temporary-directory + (lambda (root) + (let ((put-old (string-append root "/real-root"))) + (mount "none" root "tmpfs") + (mkdir put-old) + (call-with-output-file (string-append root "/test") + (lambda (port) + (display "testing\n" port))) + (pivot-root root put-old) + ;; The test file should now be located inside the root directory. + (write (file-exists? "/test") out) + (close out))))) + (lambda () + (primitive-exit 0)))) (pid (close out) (let ((result (read in))) -- cgit v1.2.3