From 64cf660f872fb7aaf0d2b463e45b4c756297f743 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 11 Sep 2020 12:51:36 +0200 Subject: daemon: Spawn 'guix authenticate' once for all. Previously, we'd spawn 'guix authenticate' once for each item that has to be signed (when exporting) or authenticated (when importing). Now, we spawn it once for all and then follow a request/reply protocol. This reduces the wall-clock time of: guix archive --export -r $(guix build coreutils -d) from 30s to 2s. * guix/scripts/authenticate.scm (sign-with-key): Return the signature instead of displaying it. Raise a &formatted-message instead of calling 'leave'. (validate-signature): Likewise. (read-command): New procedure. (define-enumerate-type, reply-code): New macros. (guix-authenticate)[send-reply]: New procedure. Change to read commands from current-input-port. * nix/libstore/local-store.cc (runAuthenticationProgram): Remove. (authenticationAgent, readInteger, readAuthenticateReply): New functions. (signHash, verifySignature): Rewrite in terms of the agent. * tests/store.scm ("import not signed"): Remove 'pk' call. ("import signed by unauthorized key"): Check the error message of C. * tests/guix-authenticate.sh: Rewrite using the new protocol. fixlet --- tests/guix-authenticate.sh | 45 ++++++++++++++++++++++++++------------------- tests/store.scm | 8 ++++---- 2 files changed, 30 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/guix-authenticate.sh b/tests/guix-authenticate.sh index 773443453d..f3b36ee41d 100644 --- a/tests/guix-authenticate.sh +++ b/tests/guix-authenticate.sh @@ -28,33 +28,38 @@ rm -f "$sig" "$hash" trap 'rm -f "$sig" "$hash"' EXIT +key="$abs_top_srcdir/tests/signing-key.sec" +key_len="`echo -n $key | wc -c`" + # A hexadecimal string as long as a sha256 hash. hash="2749f0ea9f26c6c7be746a9cff8fa4c2f2a02b000070dba78429e9a11f87c6eb" +hash_len="`echo -n $hash | wc -c`" -guix authenticate sign \ - "$abs_top_srcdir/tests/signing-key.sec" \ - "$hash" > "$sig" +echo "sign $key_len:$key $hash_len:$hash" | guix authenticate > "$sig" test -f "$sig" +case "$(cat $sig)" in + "0 "*) ;; + *) echo "broken signature: $(cat $sig)" + exit 42;; +esac + +# Remove the leading "0". +sed -i "$sig" -e's/^0 //g' -hash2="`guix authenticate verify "$sig"`" -test "$hash2" = "$hash" +hash2="$(echo verify $(cat "$sig") | guix authenticate)" +test "$(echo $hash2 | cut -d : -f 2)" = "$hash" # Detect corrupt signatures. -if guix authenticate verify /dev/null -then false -else true -fi +code="$(echo "verify 5:wrong" | guix authenticate | cut -f1 -d ' ')" +test "$code" -ne 0 # Detect invalid signatures. # The signature has (payload (data ... (hash sha256 #...#))). We proceed by # modifying this hash. sed -i "$sig" \ -e's|#[A-Z0-9]\{64\}#|#0000000000000000000000000000000000000000000000000000000000000000#|g' -if guix authenticate verify "$sig" -then false -else true -fi - +code="$(echo "verify $(cat $sig)" | guix authenticate | cut -f1 -d ' ')" +test "$code" -ne 0 # Test for : make sure 'guix authenticate' produces # valid signatures when run in the C locale. @@ -63,9 +68,11 @@ hash="5eff0b55c9c5f5e87b4e34cd60a2d5654ca1eb78c7b3c67c3179fed1cff07b4c" LC_ALL=C export LC_ALL -guix authenticate sign "$abs_top_srcdir/tests/signing-key.sec" "$hash" \ - > "$sig" +echo "sign $key_len:$key $hash_len:$hash" | guix authenticate > "$sig" + +# Remove the leading "0". +sed -i "$sig" -e's/^0 //g' -guix authenticate verify "$sig" -hash2="`guix authenticate verify "$sig"`" -test "$hash2" = "$hash" +echo "verify $(cat $sig)" | guix authenticate +hash2="$(echo "verify $(cat $sig)" | guix authenticate | cut -f2 -d ' ')" +test "$(echo $hash2 | cut -d : -f 2)" = "$hash" diff --git a/tests/store.scm b/tests/store.scm index 8ff76e8f98..3a2a21a250 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -990,7 +990,7 @@ (define ref-hash ;; Ensure 'import-paths' raises an exception. (guard (c ((store-protocol-error? c) - (and (not (zero? (store-protocol-error-status (pk 'C c)))) + (and (not (zero? (store-protocol-error-status c))) (string-contains (store-protocol-error-message c) "lacks a signature")))) (let* ((source (open-bytevector-input-port dump)) @@ -1030,9 +1030,9 @@ (define ref-hash ;; Ensure 'import-paths' raises an exception. (guard (c ((store-protocol-error? c) - ;; XXX: The daemon-provided error message currently doesn't - ;; mention the reason of the failure. - (not (zero? (store-protocol-error-status c))))) + (and (not (zero? (store-protocol-error-status c))) + (string-contains (store-protocol-error-message c) + "unauthorized public key")))) (let* ((source (open-bytevector-input-port dump)) (imported (import-paths %store source))) (pk 'unauthorized-imported imported) -- cgit v1.2.3 From 8eeeedcb35ac5514360a325116c188ef15f43de6 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 14 Sep 2020 14:22:59 +0200 Subject: tests: Remove one 'delete-paths' call in 'tests/store.scm'. This makes the test slightly less expensive. * tests/store.scm ("add-text-to-store vs. delete-paths") ("add-to-store vs. delete-paths"): Delete and merge into... ("add-text-to-store/add-to-store vs. delete-paths"): ... this test. --- tests/store.scm | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/store.scm b/tests/store.scm index 3a2a21a250..38051bf5e5 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -223,30 +223,22 @@ (define %shell ;;(> freed 0) (not (file-exists? p)))))) -(test-assert "add-text-to-store vs. delete-paths" - ;; Before, 'add-text-to-store' would return PATH2 without noticing that it - ;; is no longer valid. +(test-assert "add-text-to-store/add-to-store vs. delete-paths" + ;; Before, 'add-text-to-store' and 'add-to-store' would return the same + ;; store item without noticing that it is no longer valid. (with-store store (let* ((text (random-text)) - (path (add-text-to-store store "delete-me" text)) - (deleted (delete-paths store (list path))) - (path2 (add-text-to-store store "delete-me" text))) - (and (string=? path path2) - (equal? deleted (list path)) - (valid-path? store path) - (file-exists? path))))) - -(test-assert "add-to-store vs. delete-paths" - ;; Same as above. - (with-store store - (let* ((file (search-path %load-path "guix.scm")) - (path (add-to-store store "delete-me" #t "sha256" file)) - (deleted (delete-paths store (list path))) - (path2 (add-to-store store "delete-me" #t "sha256" file))) - (and (string=? path path2) - (equal? deleted (list path)) - (valid-path? store path) - (file-exists? path))))) + (file (search-path %load-path "guix.scm")) + (path1 (add-text-to-store store "delete-me" text)) + (path2 (add-to-store store "delete-me" #t "sha256" file)) + (deleted (delete-paths store (list path1 path2)))) + (and (string=? path1 (add-text-to-store store "delete-me" text)) + (string=? path2 (add-to-store store "delete-me" #t "sha256" file)) + (lset= string=? deleted (list path1 path2)) + (valid-path? store path1) + (valid-path? store path2) + (file-exists? path1) + (file-exists? path2))))) (test-equal "add-file-tree-to-store" `(42 -- cgit v1.2.3 From b911d6547444b5f8d17b224bafa5ee1b5aafaff5 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 15 Sep 2020 14:24:05 +0200 Subject: authenticate: Encode strings as ISO-8859-1. Fixes . * guix/scripts/authenticate.scm (read-command): Decode strings as ISO-8859-1, not UTF-8. (guix-authenticate)[send-reply]: Encode strings as ISO-8859-1, not UTF-8. * tests/guix-authenticate.sh: Add test. --- guix/scripts/authenticate.scm | 8 +++++--- tests/guix-authenticate.sh | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/guix/scripts/authenticate.scm b/guix/scripts/authenticate.scm index 0bac13edee..45f62f6ebc 100644 --- a/guix/scripts/authenticate.scm +++ b/guix/scripts/authenticate.scm @@ -31,6 +31,7 @@ (define-module (guix scripts authenticate) #:use-module (ice-9 rdelim) #:use-module (ice-9 match) #:use-module (ice-9 vlist) + #:use-module (ice-9 iconv) #:export (guix-authenticate)) ;;; Commentary: @@ -122,8 +123,9 @@ (define (consume-whitespace port) (reverse result)) (else (let* ((len (string->number (read-delimited ":" port))) - (str (utf8->string - (get-bytevector-n port len)))) + (str (bytevector->string + (get-bytevector-n port len) + "ISO-8859-1" 'error))) (loop (cons str result)))))))))) (define-syntax define-enumerate-type ;TODO: factorize @@ -150,7 +152,7 @@ (define-command (guix-authenticate . args) (define (send-reply code str) ;; Send CODE and STR as a reply to our client. - (let ((bv (string->utf8 str))) + (let ((bv (string->bytevector str "ISO-8859-1" 'error))) (format #t "~a ~a:" code (bytevector-length bv)) (put-bytevector (current-output-port) bv) (force-output (current-output-port)))) diff --git a/tests/guix-authenticate.sh b/tests/guix-authenticate.sh index f3b36ee41d..3a05b232c1 100644 --- a/tests/guix-authenticate.sh +++ b/tests/guix-authenticate.sh @@ -61,6 +61,15 @@ sed -i "$sig" \ code="$(echo "verify $(cat $sig)" | guix authenticate | cut -f1 -d ' ')" test "$code" -ne 0 +# Make sure byte strings are correctly encoded. The hash string below is +# "café" repeated 8 times. Libgcrypt would normally choose to write it as a +# string rather than a hex sequence. We want that string to be Latin-1 +# encoded independently of the current locale: . +hash="636166e9636166e9636166e9636166e9636166e9636166e9636166e9636166e9" +latin1_cafe="caf$(printf '\351')" +echo "sign 21:tests/signing-key.sec 64:$hash" | guix authenticate \ + | LC_ALL=C grep "hash sha256 \"$latin1_cafe" + # Test for : make sure 'guix authenticate' produces # valid signatures when run in the C locale. hash="5eff0b55c9c5f5e87b4e34cd60a2d5654ca1eb78c7b3c67c3179fed1cff07b4c" -- cgit v1.2.3 From d7f7ed39be3be926b3c46c0ea15d416c593ef61f Mon Sep 17 00:00:00 2001 From: Konrad Hinsen Date: Fri, 11 Sep 2020 13:13:26 +0200 Subject: repl: Look for script files in (getcwd). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes . * guix/scripts/repl.scm (guix-repl): Replace "." by (getcwd) * tests/guix-repl.sh: Add test. Co-authored-by: Ludovic Courtès --- guix/scripts/repl.scm | 5 ++++- tests/guix-repl.sh | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm index 3c79e89f8d..7d4e474e92 100644 --- a/guix/scripts/repl.scm +++ b/guix/scripts/repl.scm @@ -178,7 +178,10 @@ (define script (lambda () (set-program-arguments script) (set-user-module) - (load-in-vicinity "." (car script))))) + + ;; When passed a relative file name, 'load-in-vicinity' searches the + ;; file in %LOAD-PATH. Thus, pass (getcwd) instead of ".". + (load-in-vicinity (getcwd) (car script))))) (when (null? script) ;; Start REPL diff --git a/tests/guix-repl.sh b/tests/guix-repl.sh index e1c2b8241f..d4ebb5f6c6 100644 --- a/tests/guix-repl.sh +++ b/tests/guix-repl.sh @@ -45,6 +45,10 @@ EOF test "`guix repl "$tmpfile"`" = "coreutils" +# Make sure that the file can also be loaded when passed as a relative file +# name. +(cd "$(dirname "$tmpfile")"; test "$(guix repl "$(basename "$tmpfile")")" = "coreutils") + cat > "$module_dir/foo.scm"< Date: Mon, 14 Sep 2020 22:49:06 +0200 Subject: environment: '--link-profile' uses ~/.guix-profile for environment variables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, we had: $ guix environment -CP --ad-hoc coreutils [env]$ echo $PATH /gnu/store/…-profile/bin [env]$ echo $GUIX_ENVIRONMENT /gnu/store/…-profile After this patch: $ guix environment -CP --ad-hoc coreutils [env]$ echo $PATH /home/ludo/.guix-profile/bin [env]$ echo $GUIX_ENVIRONMENT /home/ludo/.guix-profile * guix/scripts/environment.scm (launch-environment/container): When LINK-PROFILE? is true, pass ~/.guix-profile as the second argument to 'launch-environment'. * tests/guix-environment-container.sh: Adjust test accordingly. * doc/guix.texi (Invoking guix environment): Update accordingly. --- doc/guix.texi | 5 +++-- guix/scripts/environment.scm | 6 +++++- tests/guix-environment-container.sh | 10 +++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/doc/guix.texi b/doc/guix.texi index f7e2204b53..949551a163 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5420,8 +5420,9 @@ device. @item --link-profile @itemx -P For containers, link the environment profile to @file{~/.guix-profile} -within the container. This is equivalent to running the command -@samp{ln -s $GUIX_ENVIRONMENT ~/.guix-profile} within the container. +within the container and set @code{GUIX_ENVIRONMENT} to that. +This is equivalent to making @file{~/.guix-profile} a symlink to the +actual profile within the container. Linking will fail and abort the environment if the directory already exists, which will certainly be the case if @command{guix environment} was invoked in the user's home directory. diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index ad50281eb2..e2e481dd02 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -564,7 +564,11 @@ (define (optional-mapping->fs mapping) (primitive-exit/status ;; A container's environment is already purified, so no need to ;; request it be purified again. - (launch-environment command profile manifest #:pure? #f))) + (launch-environment command + (if link-profile? + (string-append home-dir "/.guix-profile") + profile) + manifest #:pure? #f))) #:guest-uid uid #:guest-gid gid #:namespaces (if network? diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index 45264d4978..040f32cce9 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh @@ -127,11 +127,15 @@ grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash rm $tmpdir/mounts -# Make sure 'GUIX_ENVIRONMENT' is linked to '~/.guix-profile' when requested +# Make sure 'GUIX_ENVIRONMENT' is set to '~/.guix-profile' when requested # within a container. ( - linktest='(exit (string=? (getenv "GUIX_ENVIRONMENT") -(readlink (string-append (getenv "HOME") "/.guix-profile"))))' + linktest=' +(exit (and (string=? (getenv "GUIX_ENVIRONMENT") + (string-append (getenv "HOME") "/.guix-profile")) + (string-prefix? "'"$NIX_STORE_DIR"'" + (readlink (string-append (getenv "HOME") + "/.guix-profile")))))' cd "$tmpdir" \ && guix environment --bootstrap --container --link-profile \ -- cgit v1.2.3 From f458cfbcc54ed87b1a87dd9e150ea276f17eab74 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 23 Sep 2020 22:29:17 +0200 Subject: guix build: Add '--without-tests'. * 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(-) (limited to 'tests') diff --git a/doc/guix.texi b/doc/guix.texi index 538e7cceab..8384eee6c3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9271,6 +9271,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 @@ (define rewrite (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 @@ (define %transformations (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 @@ (define %transformation-options (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 @@ (define (show-transformation-options-help) 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 @@ (define-module (test-scripts-build) ((("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) -- cgit v1.2.3 From ff39361c80dfc67a9afe35f315a774140d8cf99b Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 21 Sep 2020 17:44:29 +0200 Subject: packages: 'package-mapping' can recurse on implicit inputs. * guix/packages.scm (build-system-with-package-mapping): New procedure. (package-mapping): Add #:deep? and honor it. * tests/packages.scm ("package-mapping"): Compare the direct inputs of the bag of P0 and that of P1. ("package-mapping, deep"): New test. --- doc/guix.texi | 5 +++-- guix/packages.scm | 65 +++++++++++++++++++++++++++++++++++++++++------------- tests/packages.scm | 36 +++++++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/doc/guix.texi b/doc/guix.texi index 8384eee6c3..054449d8d6 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6296,10 +6296,11 @@ A more generic procedure to rewrite a package dependency graph is @code{package-mapping}: it supports arbitrary changes to nodes in the graph. -@deffn {Scheme Procedure} package-mapping @var{proc} [@var{cut?}] +@deffn {Scheme Procedure} package-mapping @var{proc} [@var{cut?}] [#:deep? #f] Return a procedure that, given a package, applies @var{proc} to all the packages depended on and returns the resulting package. The procedure stops recursion -when @var{cut?} returns true for a given package. +when @var{cut?} returns true for a given package. When @var{deep?} is true, @var{proc} is +applied to implicit inputs as well. @end deffn @menu diff --git a/guix/packages.scm b/guix/packages.scm index 6598bd3149..171fd048ef 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -968,10 +968,31 @@ (define* (package-closure packages #:key (system (%current-system))) (vhash-consq package #t visited) (fold set-insert closure dependencies)))))))) -(define* (package-mapping proc #:optional (cut? (const #f))) +(define (build-system-with-package-mapping bs rewrite) + "Return a variant of BS, a build system, that rewrites a bag's inputs by +passing them through REWRITE, a procedure that takes an input tuplet and +returns a \"rewritten\" input tuplet." + (define lower + (build-system-lower bs)) + + (define (lower* . args) + (let ((lowered (apply lower args))) + (bag + (inherit lowered) + (build-inputs (map rewrite (bag-build-inputs lowered))) + (host-inputs (map rewrite (bag-host-inputs lowered))) + (target-inputs (map rewrite (bag-target-inputs lowered)))))) + + (build-system + (inherit bs) + (lower lower*))) + +(define* (package-mapping proc #:optional (cut? (const #f)) + #:key deep?) "Return a procedure that, given a package, applies PROC to all the packages depended on and returns the resulting package. The procedure stops recursion -when CUT? returns true for a given package." +when CUT? returns true for a given package. When DEEP? is true, PROC is +applied to implicit inputs as well." (define (rewrite input) (match input ((label (? package? package) outputs ...) @@ -980,21 +1001,35 @@ (define (rewrite input) (_ input))) + (define mapping-property + ;; Property indicating whether the package has already been processed. + (gensym " package-mapping-done")) + (define replace (mlambdaq (p) - ;; Return a variant of P with PROC applied to P and its explicit - ;; dependencies, recursively. Memoize the transformations. Failing to - ;; do that, we would build a huge object graph with lots of duplicates, - ;; which in turns prevents us from benefiting from memoization in - ;; 'package-derivation'. - (let ((p (proc p))) - (package - (inherit p) - (location (package-location p)) - (inputs (map rewrite (package-inputs p))) - (native-inputs (map rewrite (package-native-inputs p))) - (propagated-inputs (map rewrite (package-propagated-inputs p))) - (replacement (and=> (package-replacement p) proc)))))) + ;; If P is the result of a previous call, return it. + (if (assq-ref (package-properties p) mapping-property) + p + + ;; Return a variant of P with PROC applied to P and its explicit + ;; dependencies, recursively. Memoize the transformations. Failing + ;; to do that, we would build a huge object graph with lots of + ;; duplicates, which in turns prevents us from benefiting from + ;; memoization in 'package-derivation'. + (let ((p (proc p))) + (package + (inherit p) + (location (package-location p)) + (build-system (if deep? + (build-system-with-package-mapping + (package-build-system p) rewrite) + (package-build-system p))) + (inputs (map rewrite (package-inputs p))) + (native-inputs (map rewrite (package-native-inputs p))) + (propagated-inputs (map rewrite (package-propagated-inputs p))) + (replacement (and=> (package-replacement p) proc)) + (properties `((,mapping-property . #t) + ,@(package-properties p)))))))) replace) diff --git a/tests/packages.scm b/tests/packages.scm index cbd0503733..f33332a461 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -1172,15 +1172,24 @@ (define read-at (let* ((dep (dummy-package "chbouib" (native-inputs `(("x" ,grep))))) (p0 (dummy-package "example" + (source 77) (inputs `(("foo" ,coreutils) ("bar" ,grep) ("baz" ,dep))))) (transform (lambda (p) (package (inherit p) (source 42)))) (rewrite (package-mapping transform)) - (p1 (rewrite p0))) + (p1 (rewrite p0)) + (bag0 (package->bag p0)) + (bag1 (package->bag p1))) (and (eq? p1 (rewrite p0)) (eqv? 42 (package-source p1)) + + ;; Implicit inputs should be left unchanged (skip "source", "foo", + ;; "bar", and "baz" in this comparison). + (equal? (drop (bag-direct-inputs bag0) 4) + (drop (bag-direct-inputs bag1) 4)) + (match (package-inputs p1) ((("foo" dep1) ("bar" dep2) ("baz" dep3)) (and (eq? dep1 (rewrite coreutils)) ;memoization @@ -1194,6 +1203,31 @@ (define read-at (and (eq? dep (rewrite grep)) (package-source dep)))))))))) +(test-equal "package-mapping, deep" + '(42) + (let* ((p0 (dummy-package "example" + (inputs `(("foo" ,coreutils) + ("bar" ,grep))))) + (transform (lambda (p) + (package (inherit p) (source 42)))) + (rewrite (package-mapping transform #:deep? #t)) + (p1 (rewrite p0)) + (bag (package->bag p1))) + (and (eq? p1 (rewrite p0)) + (match (bag-direct-inputs bag) + ((("source" 42) ("foo" dep1) ("bar" dep2) rest ..1) + (and (eq? dep1 (rewrite coreutils)) ;memoization + (eq? dep2 (rewrite grep)) + (= 42 (package-source dep1)) + (= 42 (package-source dep2)) + + ;; Check that implicit inputs of P0 also got rewritten. + (delete-duplicates + (map (match-lambda + ((_ package . _) + (package-source package))) + rest)))))))) + (test-assert "package-input-rewriting" (let* ((dep (dummy-package "chbouib" (native-inputs `(("x" ,grep))))) -- cgit v1.2.3 From 2bf6f962b91123b0474c0f7123cd17efe7f09a66 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 23 Sep 2020 10:29:09 +0200 Subject: packages: 'package-input-rewriting/spec' can rewrite implicit dependencies. With this change, '--with-input', '--with-graft', etc. also apply to implicit dependencies. Thus, it's now possible to do: guix build python-itsdangerous --with-input=python-wrapper=python@2 or: guix build hello --with-graft=glibc=glibc@2.29 Additionally, before, implicit inputs were not rewritten, which could lead to duplicates in the output of 'bag-transitive-inputs' (packages that are not 'eq?' but lead to the same derivation). This in turn would lead to unnecessary rebuilds when using '--with-input' & co. This change fixes it by ensuring even implicit inputs are rewritten. Fixes . * guix/packages.scm (package-input-rewriting/spec): Add #:deep? defaulting to #true, and pass it to 'package-mapping'. [replacement-property]: New variable. [rewrite]: Check that property and set it on the result of PROC. [cut?]: New procedure. * tests/packages.scm ("package-input-rewriting/spec"): Ensure implicit inputs were unchanged. ("package-input-rewriting/spec, partial match"): Pass #:deep? #f. ("package-input-rewriting/spec, deep") ("package-input-rewriting/spec, no duplicates"): New tests. (package/inherit): Move before use. * tests/guix-build.sh: Add tests. * tests/scripts-build.scm ("options->transformation, with-graft"): Compare dependencies by package name or derivation file name. * doc/guix.texi (Defining Packages): Adjust accordingly. --- doc/guix.texi | 13 +++++----- guix/packages.scm | 55 ++++++++++++++++++++++++++--------------- tests/guix-build.sh | 11 +++++++++ tests/packages.scm | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- tests/scripts-build.scm | 12 ++++++--- 5 files changed, 125 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/doc/guix.texi b/doc/guix.texi index 054449d8d6..e72e1ec130 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6272,12 +6272,13 @@ This is exactly what the @option{--with-input} command-line option does The following variant of @code{package-input-rewriting} can match packages to be replaced by name rather than by identity. -@deffn {Scheme Procedure} package-input-rewriting/spec @var{replacements} -Return a procedure that, given a package, applies the given @var{replacements} to -all the package graph (excluding implicit inputs). @var{replacements} is a list of -spec/procedures pair; each spec is a package specification such as @code{"gcc"} or -@code{"guile@@2"}, and each procedure takes a matching package and returns a -replacement for that package. +@deffn {Scheme Procedure} package-input-rewriting/spec @var{replacements} [#:deep? #t] +Return a procedure that, given a package, applies the given +@var{replacements} to all the package graph, including implicit inputs +unless @var{deep?} is false. @var{replacements} is a list of +spec/procedures pair; each spec is a package specification such as +@code{"gcc"} or @code{"guile@@2"}, and each procedure takes a matching +package and returns a replacement for that package. @end deffn The example above could be rewritten this way: diff --git a/guix/packages.scm b/guix/packages.scm index 171fd048ef..f696945e30 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -422,6 +422,16 @@ (define-record-type* package) 16))))) +(define-syntax-rule (package/inherit p overrides ...) + "Like (package (inherit P) OVERRIDES ...), except that the same +transformation is done to the package replacement, if any. P must be a bare +identifier, and will be bound to either P or its replacement when evaluating +OVERRIDES." + (let loop ((p p)) + (package (inherit p) + overrides ... + (replacement (and=> (package-replacement p) loop))))) + (define (package-upstream-name package) "Return the upstream name of PACKAGE, which could be different from the name it has in Guix." @@ -1051,12 +1061,12 @@ (define (rewrite p) (package-mapping rewrite (cut assq <> replacements))) -(define (package-input-rewriting/spec replacements) +(define* (package-input-rewriting/spec replacements #:key (deep? #t)) "Return a procedure that, given a package, applies the given REPLACEMENTS to -all the package graph (excluding implicit inputs). REPLACEMENTS is a list of -spec/procedures pair; each spec is a package specification such as \"gcc\" or -\"guile@2\", and each procedure takes a matching package and returns a -replacement for that package." +all the package graph, including implicit inputs unless DEEP? is false. +REPLACEMENTS is a list of spec/procedures pair; each spec is a package +specification such as \"gcc\" or \"guile@2\", and each procedure takes a +matching package and returns a replacement for that package." (define table (fold (lambda (replacement table) (match replacement @@ -1081,22 +1091,27 @@ (define (find-replacement package) (package-name package) table)) - (define (rewrite package) - (match (find-replacement package) - (#f package) - (proc (proc package)))) - - (package-mapping rewrite find-replacement)) + (define replacement-property + (gensym " package-replacement")) -(define-syntax-rule (package/inherit p overrides ...) - "Like (package (inherit P) OVERRIDES ...), except that the same -transformation is done to the package replacement, if any. P must be a bare -identifier, and will be bound to either P or its replacement when evaluating -OVERRIDES." - (let loop ((p p)) - (package (inherit p) - overrides ... - (replacement (and=> (package-replacement p) loop))))) + (define (rewrite p) + (if (assq-ref (package-properties p) replacement-property) + p + (match (find-replacement p) + (#f p) + (proc + (let ((new (proc p))) + ;; Mark NEW as already processed. + (package/inherit new + (properties `((,replacement-property . #t) + ,@(package-properties new))))))))) + + (define (cut? p) + (or (assq-ref (package-properties p) replacement-property) + (find-replacement p))) + + (package-mapping rewrite cut? + #:deep? deep?)) ;;; diff --git a/tests/guix-build.sh b/tests/guix-build.sh index 6c08857358..ec2f736ccb 100644 --- a/tests/guix-build.sh +++ b/tests/guix-build.sh @@ -259,6 +259,17 @@ drv1=`guix build guile -d` drv2=`guix build guile --with-input=gimp=ruby -d` test "$drv1" = "$drv2" +# See . +drv1=`guix build glib -d` +drv2=`guix build glib -d --with-input=libreoffice=inkscape` +test "$drv1" = "$drv2" + +# Rewriting implicit inputs. +drv1=`guix build hello -d` +drv2=`guix build hello -d --with-input=gcc=gcc-toolchain` +test "$drv1" != "$drv2" +guix gc -R "$drv2" | grep `guix build -d gcc-toolchain` + if guix build guile --with-input=libunistring=something-really-silly then false; else true; fi diff --git a/tests/packages.scm b/tests/packages.scm index f33332a461..6fa4ad2f1b 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -38,6 +38,7 @@ (define-module (test-packages) #:use-module (guix build-system) #:use-module (guix build-system trivial) #:use-module (guix build-system gnu) + #:use-module (guix build-system python) #:use-module (guix memoization) #:use-module (guix profiles) #:use-module (guix scripts package) @@ -45,6 +46,7 @@ (define-module (test-packages) #:use-module (gnu packages base) #:use-module (gnu packages guile) #:use-module (gnu packages bootstrap) + #:use-module (gnu packages python) #:use-module (gnu packages version-control) #:use-module (gnu packages xml) #:use-module (srfi srfi-1) @@ -1262,7 +1264,8 @@ (define read-at ("baz" ,dep))))) (rewrite (package-input-rewriting/spec `(("coreutils" . ,(const sed)) - ("grep" . ,(const findutils))))) + ("grep" . ,(const findutils))) + #:deep? #f)) (p1 (rewrite p0)) (p2 (rewrite p0))) (and (not (eq? p1 p0)) @@ -1279,7 +1282,11 @@ (define read-at (match (package-native-inputs dep3) ((("x" dep)) (string=? (package-full-name dep) - (package-full-name findutils)))))))))) + (package-full-name findutils))))))) + + ;; Make sure implicit inputs were left unchanged. + (equal? (drop (bag-direct-inputs (package->bag p1)) 3) + (drop (bag-direct-inputs (package->bag p0)) 3))))) (test-assert "package-input-rewriting/spec, partial match" (let* ((dep (dummy-package "chbouib" @@ -1290,7 +1297,8 @@ (define read-at ("bar" ,dep))))) (rewrite (package-input-rewriting/spec `(("chbouib@123" . ,(const sed)) ;not matched - ("grep" . ,(const findutils))))) + ("grep" . ,(const findutils))) + #:deep? #f)) (p1 (rewrite p0))) (and (not (eq? p1 p0)) (string=? "example" (package-name p1)) @@ -1304,6 +1312,58 @@ (define read-at (string=? (package-full-name dep) (package-full-name findutils)))))))))) +(test-assert "package-input-rewriting/spec, deep" + (let* ((dep (dummy-package "chbouib")) + (p0 (dummy-package "example" + (build-system gnu-build-system) + (inputs `(("dep" ,dep))))) + (rewrite (package-input-rewriting/spec + `(("tar" . ,(const sed)) + ("gzip" . ,(const findutils))))) + (p1 (rewrite p0)) + (p2 (rewrite p0))) + (and (not (eq? p1 p0)) + (eq? p1 p2) ;memoization + (string=? "example" (package-name p1)) + (match (package-inputs p1) + ((("dep" dep1)) + (and (string=? (package-full-name dep1) + (package-full-name dep)) + (eq? dep1 (rewrite dep))))) ;memoization + + ;; Make sure implicit inputs were replaced. + (match (bag-direct-inputs (package->bag p1)) + ((("dep" dep1) ("tar" tar) ("gzip" gzip) _ ...) + (and (eq? dep1 (rewrite dep)) + (string=? (package-full-name tar) + (package-full-name sed)) + (string=? (package-full-name gzip) + (package-full-name findutils)))))))) + +(test-assert "package-input-rewriting/spec, no duplicates" + ;; Ensure that deep input rewriting does not forget implicit inputs. Doing + ;; so could lead to duplicates in a package's inputs: in the example below, + ;; P0's transitive inputs would contain one rewritten "python" and one + ;; original "python". These two "python" packages are thus not 'eq?' but + ;; they lower to the same derivation. See , + ;; which can be reproduced by passing #:deep? #f. + (let* ((dep0 (dummy-package "dep0" + (build-system trivial-build-system) + (propagated-inputs `(("python" ,python))))) + (p0 (dummy-package "chbouib" + (build-system python-build-system) + (arguments `(#:python ,python)) + (inputs `(("dep0" ,dep0))))) + (rewrite (package-input-rewriting/spec '() #:deep? #t)) + (p1 (rewrite p0)) + (bag1 (package->bag p1)) + (pythons (filter-map (match-lambda + (("python" python) python) + (_ #f)) + (bag-transitive-inputs bag1)))) + (match (delete-duplicates pythons eq?) + ((p) (eq? p (rewrite python)))))) + (test-equal "package-patched-vulnerabilities" '(("CVE-2015-1234") ("CVE-2016-1234" "CVE-2018-4567") diff --git a/tests/scripts-build.scm b/tests/scripts-build.scm index 12114fc8f5..5f91360953 100644 --- a/tests/scripts-build.scm +++ b/tests/scripts-build.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2016, 2017, 2019 Ludovic Courtès +;;; Copyright © 2016, 2017, 2019, 2020 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -19,6 +19,7 @@ (define-module (test-scripts-build) #:use-module (guix tests) #:use-module (guix store) + #:use-module (guix derivations) #:use-module (guix packages) #:use-module (guix git-download) #:use-module (guix scripts build) @@ -163,11 +164,16 @@ (define-module (test-scripts-build) ((("foo" dep1) ("bar" dep2)) (and (string=? (package-full-name dep1) (package-full-name grep)) - (eq? (package-replacement dep1) findutils) + (string=? (package-full-name (package-replacement dep1)) + (package-full-name findutils)) (string=? (package-name dep2) "chbouib") (match (package-native-inputs dep2) ((("x" dep)) - (eq? (package-replacement dep) findutils))))))))))) + (with-store store + (string=? (derivation-file-name + (package-derivation store findutils)) + (derivation-file-name + (package-derivation store dep)))))))))))))) (test-equal "options->transformation, with-branch" (git-checkout (url "https://example.org") -- cgit v1.2.3 From b3fc03ee266a5f6d810d780582d458e561efccf3 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 23 Sep 2020 14:40:15 +0200 Subject: packages: 'package-mapping' correctly recurses into 'replacement'. Previously, something like: guix build glib --with-graft=glibc=glibc@2.29 would produce a result showing that rewriting rules were not applied to libx11@1.6.A (a replacement). * guix/packages.scm (package-mapping): Call REPLACE instead of PROC to 'replacement'. * tests/packages.scm ("package-input-rewriting/spec, graft"): New test. --- guix/packages.scm | 2 +- tests/packages.scm | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/guix/packages.scm b/guix/packages.scm index f696945e30..0d0d7492b6 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1037,7 +1037,7 @@ (define replace (inputs (map rewrite (package-inputs p))) (native-inputs (map rewrite (package-native-inputs p))) (propagated-inputs (map rewrite (package-propagated-inputs p))) - (replacement (and=> (package-replacement p) proc)) + (replacement (and=> (package-replacement p) replace)) (properties `((,mapping-property . #t) ,@(package-properties p)))))))) diff --git a/tests/packages.scm b/tests/packages.scm index 6fa4ad2f1b..e31dea6f72 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -1364,6 +1364,33 @@ (define read-at (match (delete-duplicates pythons eq?) ((p) (eq? p (rewrite python)))))) +(test-equal "package-input-rewriting/spec, graft" + (derivation-file-name (package-derivation %store sed)) + + ;; Make sure replacements are rewritten. + (let* ((dep0 (dummy-package "dep" + (version "1") + (build-system trivial-build-system) + (inputs `(("coreutils" ,coreutils))))) + (dep1 (dummy-package "dep" + (version "0") + (build-system trivial-build-system) + (replacement dep0))) + (p0 (dummy-package "p" + (build-system trivial-build-system) + (inputs `(("dep" ,dep1))))) + (rewrite (package-input-rewriting/spec + `(("coreutils" . ,(const sed))))) + (p1 (rewrite p0))) + (match (package-inputs p1) + ((("dep" dep)) + (match (package-inputs (package-replacement dep)) + ((("coreutils" coreutils)) + ;; COREUTILS is not 'eq?' to SED, so the most reliable way to check + ;; for equality is to lower to a derivation. + (derivation-file-name + (package-derivation %store coreutils)))))))) + (test-equal "package-patched-vulnerabilities" '(("CVE-2015-1234") ("CVE-2016-1234" "CVE-2018-4567") -- cgit v1.2.3 From 8819551c8d2a12cd4e84e09b51e434d05a012c9d Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 23 Sep 2020 14:56:38 +0200 Subject: packages: 'package-input-rewriting' has a #:deep? parameter. * guix/packages.scm (package-input-rewriting): Add #:deep? and pass it to 'package-mapping'. [replacement-property]: New variable. [rewrite]: Check it. [cut?]: New procedure. * tests/packages.scm ("package-input-rewriting"): Pass #:deep? #f and ensure implicit inputs were not rewritten. Avoid 'eq?' comparisons. ("package-input-rewriting, deep"): New test. * gnu/packages/guile.scm (package-for-guile-2.0, package-for-guile-3.0): Pass #:deep? #f. --- doc/guix.texi | 10 +++++----- gnu/packages/guile.scm | 6 ++++-- guix/packages.scm | 35 +++++++++++++++++++++++++---------- tests/packages.scm | 20 ++++++++++++++++++-- 4 files changed, 52 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/doc/guix.texi b/doc/guix.texi index e72e1ec130..0805e2d508 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6238,12 +6238,12 @@ transformation is @dfn{input rewriting}, whereby the dependency tree of a package is rewritten by replacing specific inputs by others: @deffn {Scheme Procedure} package-input-rewriting @var{replacements} @ - [@var{rewrite-name}] + [@var{rewrite-name}] [#:deep? #t] Return a procedure that, when passed a package, replaces its direct and -indirect dependencies (but not its implicit inputs) according to -@var{replacements}. @var{replacements} is a list of package pairs; the -first element of each pair is the package to replace, and the second one -is the replacement. +indirect dependencies, including implicit inputs when @var{deep?} is +true, according to @var{replacements}. @var{replacements} is a list of +package pairs; the first element of each pair is the package to replace, +and the second one is the replacement. Optionally, @var{rewrite-name} is a one-argument procedure that takes the name of a package and returns its new name after rewrite. diff --git a/gnu/packages/guile.scm b/gnu/packages/guile.scm index c59daeebe2..280053bf06 100644 --- a/gnu/packages/guile.scm +++ b/gnu/packages/guile.scm @@ -420,11 +420,13 @@ (define package-for-guile-2.0 ;; A procedure that rewrites the dependency tree of the given package to use ;; GUILE-2.0 instead of GUILE-3.0. (package-input-rewriting `((,guile-3.0 . ,guile-2.0)) - (guile-variant-package-name "guile2.0"))) + (guile-variant-package-name "guile2.0") + #:deep? #f)) (define package-for-guile-2.2 (package-input-rewriting `((,guile-3.0 . ,guile-2.2)) - (guile-variant-package-name "guile2.2"))) + (guile-variant-package-name "guile2.2") + #:deep? #f)) (define-syntax define-deprecated-guile3.0-package (lambda (s) diff --git a/guix/packages.scm b/guix/packages.scm index 0d0d7492b6..4f2bb432be 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1044,22 +1044,37 @@ (define replace replace) (define* (package-input-rewriting replacements - #:optional (rewrite-name identity)) + #:optional (rewrite-name identity) + #:key (deep? #t)) "Return a procedure that, when passed a package, replaces its direct and -indirect dependencies (but not its implicit inputs) according to REPLACEMENTS. -REPLACEMENTS is a list of package pairs; the first element of each pair is the -package to replace, and the second one is the replacement. +indirect dependencies, including implicit inputs when DEEP? is true, according +to REPLACEMENTS. REPLACEMENTS is a list of package pairs; the first element +of each pair is the package to replace, and the second one is the replacement. Optionally, REWRITE-NAME is a one-argument procedure that takes the name of a package and returns its new name after rewrite." + (define replacement-property + ;; Property to tag right-hand sides in REPLACEMENTS. + (gensym " package-replacement")) + (define (rewrite p) - (match (assq-ref replacements p) - (#f (package - (inherit p) - (name (rewrite-name (package-name p))))) - (new new))) + (if (assq-ref (package-properties p) replacement-property) + p + (match (assq-ref replacements p) + (#f (package/inherit p + (name (rewrite-name (package-name p))))) + (new (if deep? + (package/inherit new + (properties `((,replacement-property . #t) + ,@(package-properties new)))) + new))))) - (package-mapping rewrite (cut assq <> replacements))) + (define (cut? p) + (or (assq-ref (package-properties p) replacement-property) + (assq-ref replacements p))) + + (package-mapping rewrite cut? + #:deep? deep?)) (define* (package-input-rewriting/spec replacements #:key (deep? #t)) "Return a procedure that, given a package, applies the given REPLACEMENTS to diff --git a/tests/packages.scm b/tests/packages.scm index e31dea6f72..af8941c2e2 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -1239,7 +1239,8 @@ (define read-at ("baz" ,dep))))) (rewrite (package-input-rewriting `((,coreutils . ,sed) (,grep . ,findutils)) - (cut string-append "r-" <>))) + (cut string-append "r-" <>) + #:deep? #f)) (p1 (rewrite p0)) (p2 (rewrite p0))) (and (not (eq? p1 p0)) @@ -1253,7 +1254,22 @@ (define read-at (eq? dep3 (rewrite dep)) ;memoization (match (package-native-inputs dep3) ((("x" dep)) - (eq? dep findutils))))))))) + (eq? dep findutils)))))) + + ;; Make sure implicit inputs were left unchanged. + (equal? (drop (bag-direct-inputs (package->bag p1)) 3) + (drop (bag-direct-inputs (package->bag p0)) 3))))) + +(test-eq "package-input-rewriting, deep" + (derivation-file-name (package-derivation %store sed)) + (let* ((p0 (dummy-package "chbouib" + (build-system python-build-system) + (arguments `(#:python ,python)))) + (rewrite (package-input-rewriting `((,python . ,sed)))) + (p1 (rewrite p0))) + (match (bag-direct-inputs (package->bag p1)) + ((("python" python) _ ...) + (derivation-file-name (package-derivation %store python)))))) (test-assert "package-input-rewriting/spec" (let* ((dep (dummy-package "chbouib" -- cgit v1.2.3 From d8934360d2453a403b5433e71d09188e4ed23b57 Mon Sep 17 00:00:00 2001 From: Eric Bavier Date: Fri, 25 Sep 2020 11:00:11 -0500 Subject: tests: Simplify shell exit status negation; * tests/guix-archive.sh, tests/guix-build-branch.sh, tests/guix-build.sh, tests/guix-daemon.sh, tests/guix-download.sh, tests/guix-environment.sh, tests/guix-gc.sh, tests/guix-git-authenticate.sh, tests/guix-graph.sh, tests/guix-hash.sh, tests/guix-lint.sh, tests/guix-pack-relocatable.sh, tests/guix-pack.sh, tests/guix-package-aliases.sh, tests/guix-package-net.sh, tests/guix-package.sh: Use the shell '!' keyword to negate command exit status in place of 'if ...; then false; else true; fi' --- tests/guix-archive.sh | 9 +++------ tests/guix-build-branch.sh | 3 +-- tests/guix-build.sh | 22 ++++++++------------- tests/guix-daemon.sh | 2 +- tests/guix-download.sh | 12 ++++------- tests/guix-environment.sh | 8 +++----- tests/guix-gc.sh | 13 +++++------- tests/guix-git-authenticate.sh | 5 ++--- tests/guix-graph.sh | 7 +++---- tests/guix-hash.sh | 12 ++++------- tests/guix-lint.sh | 18 ++++++----------- tests/guix-pack-relocatable.sh | 3 +-- tests/guix-pack.sh | 3 +-- tests/guix-package-aliases.sh | 14 +++++-------- tests/guix-package-net.sh | 9 +++------ tests/guix-package.sh | 45 ++++++++++++++++-------------------------- 16 files changed, 67 insertions(+), 118 deletions(-) (limited to 'tests') diff --git a/tests/guix-archive.sh b/tests/guix-archive.sh index 4c5eea05cf..e796c62f9a 100644 --- a/tests/guix-archive.sh +++ b/tests/guix-archive.sh @@ -44,8 +44,7 @@ cmp "$archive" "$archive_alt" # Check the exit value upon import. guix archive --import < "$archive" -if guix archive something-that-does-not-exist -then false; else true; fi +! guix archive something-that-does-not-exist # This one must not be listed as missing. guix build guile-bootstrap > "$archive" @@ -62,8 +61,7 @@ cmp "$archive" "$archive_alt" # This is not a valid store file name, so an error. echo something invalid > "$archive" -if guix archive --missing < "$archive" -then false; else true; fi +! guix archive --missing < "$archive" # Check '--extract'. guile -c "(use-modules (guix serialization)) @@ -79,5 +77,4 @@ guix archive -t < "$archive" | grep "^D /share/guile" guix archive -t < "$archive" | grep "^x /bin/guile" guix archive -t < "$archive" | grep "^r /share/guile.*/boot-9\.scm" -if echo foo | guix archive --authorize -then false; else true; fi +! echo foo | guix archive --authorize diff --git a/tests/guix-build-branch.sh b/tests/guix-build-branch.sh index c5b07e07c6..79aa06a58f 100644 --- a/tests/guix-build-branch.sh +++ b/tests/guix-build-branch.sh @@ -58,5 +58,4 @@ guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-8fe64e8 # this is the tag ID test "$v0_1_0_drv" != "$latest_drv" test "$v0_1_0_drv" != "$orig_drv" -if guix build guix --with-commit=guile-gcrypt=000 -d -then false; else true; fi +! guix build guix --with-commit=guile-gcrypt=000 -d diff --git a/tests/guix-build.sh b/tests/guix-build.sh index ec2f736ccb..6dbb53206e 100644 --- a/tests/guix-build.sh +++ b/tests/guix-build.sh @@ -24,8 +24,7 @@ guix build --version # Should fail. -if guix build -e +; -then false; else true; fi +! guix build -e + # Source-less packages are accepted; they just return nothing. guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S @@ -178,7 +177,7 @@ cat > "$module_dir/foo.scm" < "$module_dir/err" || true grep "unbound" "$module_dir/err" # actual error grep "forget.*(gnu packages base)" "$module_dir/err" # hint @@ -222,7 +221,7 @@ test "`guix build --log-file guile-bootstrap`" = "$log" test "`guix build --log-file $out`" = "$log" # Should fail because the name/version combination could not be found. -if guix build hello-0.0.1 -n; then false; else true; fi +! guix build hello-0.0.1 -n # Keep a symlink to the result, registered as a root. result="t-result-$$" @@ -231,8 +230,7 @@ guix build -r "$result" \ test -x "$result/bin/guile" # Should fail, because $result already exists. -if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -then false; else true; fi +! guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' rm -f "$result" @@ -270,8 +268,7 @@ drv2=`guix build hello -d --with-input=gcc=gcc-toolchain` test "$drv1" != "$drv2" guix gc -R "$drv2" | grep `guix build -d gcc-toolchain` -if guix build guile --with-input=libunistring=something-really-silly -then false; else true; fi +! guix build guile --with-input=libunistring=something-really-silly # Deprecated/superseded packages. test "`guix build superseded -d`" = "`guix build bar -d`" @@ -279,10 +276,8 @@ test "`guix build superseded -d`" = "`guix build bar -d`" # Parsing package names and versions. guix build -n time # PASS guix build -n time@1.9 # PASS, version found -if guix build -n time@3.2; # FAIL, version not found -then false; else true; fi -if guix build -n something-that-will-never-exist; # FAIL -then false; else true; fi +! guix build -n time@3.2 # FAIL, version not found +! guix build -n something-that-will-never-exist # FAIL # Invoking a monadic procedure. guix build -e "(begin @@ -354,5 +349,4 @@ export GUIX_BUILD_OPTIONS guix build emacs GUIX_BUILD_OPTIONS="--something-completely-crazy" -if guix build emacs; -then false; else true; fi +! guix build emacs diff --git a/tests/guix-daemon.sh b/tests/guix-daemon.sh index b58500966b..330ad68835 100644 --- a/tests/guix-daemon.sh +++ b/tests/guix-daemon.sh @@ -224,7 +224,7 @@ daemon_pid=$! GUIX_DAEMON_SOCKET="guix://$tcp_socket" export GUIX_DAEMON_SOCKET -if guix gc; then false; else true; fi +! guix gc unset GUIX_DAEMON_SOCKET kill "$daemon_pid" diff --git a/tests/guix-download.sh b/tests/guix-download.sh index 30f55fbe2b..5475d43e60 100644 --- a/tests/guix-download.sh +++ b/tests/guix-download.sh @@ -23,14 +23,11 @@ guix download --version # Make sure it fails here. -if guix download http://does.not/exist -then false; else true; fi +! guix download http://does.not/exist -if guix download unknown://some/where; -then false; else true; fi +! guix download unknown://some/where; -if guix download /does-not-exist -then false; else true; fi +! guix download /does-not-exist # This one should succeed. guix download "file://$abs_top_srcdir/README" @@ -46,5 +43,4 @@ GUIX_DAEMON_SOCKET="/nowhere" guix download -o "$output" \ cmp "$output" "$abs_top_srcdir/README" # This one should fail. -if guix download "file:///does-not-exist" "file://$abs_top_srcdir/README" -then false; else true; fi +! guix download "file:///does-not-exist" "file://$abs_top_srcdir/README" diff --git a/tests/guix-environment.sh b/tests/guix-environment.sh index 2faf38df06..f8be48f0c0 100644 --- a/tests/guix-environment.sh +++ b/tests/guix-environment.sh @@ -60,7 +60,7 @@ guix environment --bootstrap --ad-hoc guile-bootstrap --pure \ grep '^PATH=' "$tmpdir/a" grep '^GUIX_TEST_ABC=' "$tmpdir/a" grep '^GUIX_TEST_DEF=' "$tmpdir/a" -if grep '^GUIX_TEST_XYZ=' "$tmpdir/a"; then false; else true; fi +! grep '^GUIX_TEST_XYZ=' "$tmpdir/a" # Make sure the exit value is preserved. if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \ @@ -194,8 +194,7 @@ then done # 'make-boot0' itself must not be listed. - if guix gc --references "$profile" | grep make-boot0 - then false; else true; fi + ! guix gc --references "$profile" | grep make-boot0 # Make sure that the shell spawned with '--exec' sees the same environment # as returned by '--search-paths'. @@ -212,8 +211,7 @@ then test "x$make_boot0_debug" != "x" # Make sure the "debug" output is not listed. - if guix gc --references "$profile" | grep "$make_boot0_debug" - then false; else true; fi + ! guix gc --references "$profile" | grep "$make_boot0_debug" # Compute the build environment for the initial GNU Make, but add in the # bootstrap Guile as an ad-hoc addition. diff --git a/tests/guix-gc.sh b/tests/guix-gc.sh index 8284287730..f40619876d 100644 --- a/tests/guix-gc.sh +++ b/tests/guix-gc.sh @@ -36,11 +36,11 @@ unset out # For some operations, passing extra arguments is an error. for option in "" "-C 500M" "--verify" "--optimize" "--list-roots" do - if guix gc $option whatever; then false; else true; fi + ! guix gc $option whatever done # This should fail. -if guix gc --verify=foo; then false; else true; fi +! guix gc --verify=foo # Check the references of a .drv. drv="`guix build guile-bootstrap -d`" @@ -51,8 +51,7 @@ guix gc --references "$drv" | grep -e -bash guix gc --references "$out" guix gc --references "$out/bin/guile" -if guix gc --references /dev/null; -then false; else true; fi +! guix gc --references /dev/null; # Check derivers. guix gc --derivers "$out" | grep "$drv" @@ -72,8 +71,7 @@ test -f "$drv" && test -L guix-gc-root guix gc --list-roots | grep "$PWD/guix-gc-root" guix gc --list-live | grep "$drv" -if guix gc --delete "$drv"; -then false; else true; fi +! guix gc --delete "$drv"; rm guix-gc-root guix gc --list-dead | grep "$drv" @@ -84,8 +82,7 @@ guix gc --delete "$drv" guix gc -C 1KiB # Check trivial error cases. -if guix gc --delete /dev/null; -then false; else true; fi +! guix gc --delete /dev/null; # Bug #19757 out="`guix build guile-bootstrap`" diff --git a/tests/guix-git-authenticate.sh b/tests/guix-git-authenticate.sh index 1c76e240b5..8ebbea398b 100644 --- a/tests/guix-git-authenticate.sh +++ b/tests/guix-git-authenticate.sh @@ -46,9 +46,8 @@ v1_0_0_signer="3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5" # civodul v1_0_1_commit="d68de958b60426798ed62797ff7c96c327a672ac" # This should fail because these commits lack '.guix-authorizations'. -if guix git authenticate "$v1_0_0_commit" "$v1_0_0_signer" \ - --cache-key="$cache_key" --end="$v1_0_1_commit"; -then false; else true; fi +! guix git authenticate "$v1_0_0_commit" "$v1_0_0_signer" \ + --cache-key="$cache_key" --end="$v1_0_1_commit" # This should work thanks to '--historical-authorizations'. guix git authenticate "$v1_0_0_commit" "$v1_0_0_signer" \ diff --git a/tests/guix-graph.sh b/tests/guix-graph.sh index ccb4933c88..666660ab4b 100644 --- a/tests/guix-graph.sh +++ b/tests/guix-graph.sh @@ -60,7 +60,7 @@ guix graph -t references guile-bootstrap | grep guile-bootstrap guix graph -e '(@ (gnu packages bootstrap) %bootstrap-guile)' \ | grep guile-bootstrap -if guix graph -e +; then false; else true; fi +! guix graph -e + # Try passing store file names. @@ -77,14 +77,13 @@ cmp "$tmpfile1" "$tmpfile2" # Try package transformation options. guix graph git | grep 'label = "openssl' guix graph git --with-input=openssl=libressl | grep 'label = "libressl' -if guix graph git --with-input=openssl=libressl | grep 'label = "openssl' -then false; else true; fi +! guix graph git --with-input=openssl=libressl | grep 'label = "openssl' # Try --load-path guix graph -L $module_dir dummy | grep 'label = "dummy' # Displaying shortest paths (or lack thereof). -if guix graph --path emacs vim; then false; else true; fi +! guix graph --path emacs vim path="\ emacs diff --git a/tests/guix-hash.sh b/tests/guix-hash.sh index 3538b9aeda..346355539f 100644 --- a/tests/guix-hash.sh +++ b/tests/guix-hash.sh @@ -34,8 +34,7 @@ test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfes test `guix hash -H sha512 -f hex /dev/null` = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e test `guix hash -H sha1 -f base64 /dev/null` = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" -if guix hash -H abcd1234 /dev/null; -then false; else true; fi +! guix hash -H abcd1234 /dev/null mkdir "$tmpdir" echo -n executable > "$tmpdir/exe" @@ -46,13 +45,11 @@ mkdir "$tmpdir/subdir" test `guix hash -r "$tmpdir"` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p # Without '-r', this should fail. -if guix hash "$tmpdir" -then false; else true; fi +! guix hash "$tmpdir" # This should fail because /dev/null is a character device, which # the archive format doesn't support. -if guix hash -r /dev/null -then false; else true; fi +! guix hash -r /dev/null # Adding a .git directory mkdir "$tmpdir/.git" @@ -65,6 +62,5 @@ test `guix hash -r $tmpdir` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m test `guix hash -r $tmpdir -x` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p # Without '-r', this should fail. -if guix hash "$tmpdir" -then false; else true; fi +! guix hash "$tmpdir" diff --git a/tests/guix-lint.sh b/tests/guix-lint.sh index ebe79efb84..fdf548fbf1 100644 --- a/tests/guix-lint.sh +++ b/tests/guix-lint.sh @@ -58,24 +58,19 @@ grep_warning () # 3) the description has a single space following the end-of-sentence period. out=`guix lint -c synopsis,description dummy 2>&1` -if [ `grep_warning "$out"` -ne 3 ] -then false; else true; fi +test `grep_warning "$out"` -eq 3 out=`guix lint -c synopsis dummy 2>&1` -if [ `grep_warning "$out"` -ne 2 ] -then false; else true; fi +test `grep_warning "$out"` -eq 2 out=`guix lint -c description dummy 2>&1` -if [ `grep_warning "$out"` -ne 1 ] -then false; else true; fi +test `grep_warning "$out"` -eq 1 out=`guix lint -c description,synopsis dummy 2>&1` -if [ `grep_warning "$out"` -ne 3 ] -then false; else true; fi +test `grep_warning "$out"` -eq 3 -if guix lint -c synopsis,invalid-checker dummy 2>&1 | \ +guix lint -c synopsis,invalid-checker dummy 2>&1 | \ grep -q 'invalid-checker: invalid checker' -then true; else false; fi # Make sure specifying multiple packages works. guix lint -c inputs-should-be-native dummy dummy@42 dummy @@ -85,8 +80,7 @@ guix lint -c inputs-should-be-native dummy dummy@42 dummy unset GUIX_PACKAGE_PATH out=`guix lint -L $module_dir -c synopsis,description dummy 2>&1` -if [ `grep_warning "$out"` -ne 3 ] -then false; else true; fi +test `grep_warning "$out"` -eq 3 # Make sure specifying multiple packages works. guix lint -L $module_dir -c inputs-should-be-native dummy dummy@42 dummy diff --git a/tests/guix-pack-relocatable.sh b/tests/guix-pack-relocatable.sh index b8d36a02c6..a960ecd209 100644 --- a/tests/guix-pack-relocatable.sh +++ b/tests/guix-pack-relocatable.sh @@ -77,8 +77,7 @@ then grep 'GNU sed' "$test_directory/output" # Check whether the exit code is preserved. - if run_without_store "$test_directory/Bin/sed" --does-not-exist; - then false; else true; fi + ! run_without_store "$test_directory/Bin/sed" --does-not-exist chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/* else diff --git a/tests/guix-pack.sh b/tests/guix-pack.sh index 39b64791e2..0339221ac2 100644 --- a/tests/guix-pack.sh +++ b/tests/guix-pack.sh @@ -45,8 +45,7 @@ guix gc -R "$drv" | grep "`guix build coreutils -d --no-grafts`" drv="`guix pack idutils -d --no-grafts --target=arm-linux-gnueabihf`" guix gc -R "$drv" | \ grep "`guix build idutils --target=arm-linux-gnueabihf -d --no-grafts`" -if guix gc -R "$drv" | grep "`guix build idutils -d --no-grafts`"; -then false; else true; fi +! guix gc -R "$drv" | grep "`guix build idutils -d --no-grafts`" # Build a tarball with no compression. guix pack --compression=none --bootstrap guile-bootstrap diff --git a/tests/guix-package-aliases.sh b/tests/guix-package-aliases.sh index e24bff3a56..e4ddace057 100644 --- a/tests/guix-package-aliases.sh +++ b/tests/guix-package-aliases.sh @@ -36,26 +36,22 @@ guix install --bootstrap guile-bootstrap -p "$profile" test -x "$profile/bin/guile" # Make sure '-r' isn't passed as-is to 'guix package'. -if guix install -r guile-bootstrap -p "$profile" --bootstrap -then false; else true; fi +! guix install -r guile-bootstrap -p "$profile" --bootstrap test -x "$profile/bin/guile" guix upgrade --version guix upgrade -n guix upgrade gui.e -n -if guix upgrade foo bar -n; -then false; else true; fi +! guix upgrade foo bar -n; guix remove --version guix remove --bootstrap guile-bootstrap -p "$profile" ! test -x "$profile/bin/guile" test `guix package -p "$profile" -I | wc -l` -eq 0 -if guix remove -p "$profile" this-is-not-installed --bootstrap -then false; else true; fi +! guix remove -p "$profile" this-is-not-installed --bootstrap -if guix remove -i guile-bootstrap -p "$profile" --bootstrap -then false; else true; fi +! guix remove -i guile-bootstrap -p "$profile" --bootstrap guix search '\' game | grep '^name: gnubg' @@ -64,7 +60,7 @@ guix show guile guix show python@3 | grep "^name: python" # "python@2" exists but is deprecated; make sure it doesn't show up. -if guix show python@2; then false; else true; fi +! guix show python@2 # Specifying multiple packages. output="`guix show sed grep | grep ^name:`" diff --git a/tests/guix-package-net.sh b/tests/guix-package-net.sh index 3876701fa2..6d21c6cff6 100644 --- a/tests/guix-package-net.sh +++ b/tests/guix-package-net.sh @@ -95,10 +95,8 @@ test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \ = " guile-bootstrap" # Exit with 1 when a generation does not exist. -if guix package -p "$profile" --list-generations=42; -then false; else true; fi -if guix package -p "$profile" --switch-generation=99; -then false; else true; fi +! guix package -p "$profile" --list-generations=42 +! guix package -p "$profile" --switch-generation=99 # Remove a package. guix package --bootstrap -p "$profile" -r "guile-bootstrap" @@ -174,8 +172,7 @@ test -z "`guix package -p "$profile" -l 3`" rm "$profile" guix package --bootstrap -p "$profile" -i guile-bootstrap guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap -if guix package -p "$profile" --search-paths | grep LIBRARY_PATH -then false; fi +! guix package -p "$profile" --search-paths | grep LIBRARY_PATH guix package -p "$profile" -p "$profile_alt" --search-paths \ | grep "LIBRARY_PATH.*$profile/lib.$profile_alt/lib" diff --git a/tests/guix-package.sh b/tests/guix-package.sh index 1f955257be..1a95b8e9a4 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -36,8 +36,7 @@ rm -f "$profile" "$tmpfile" trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT # Use `-e' with a non-package expression. -if guix package --bootstrap -e +; -then false; else true; fi +! guix package --bootstrap -e + # Install a store item and make sure the version and output in the manifest # are correct. @@ -62,8 +61,7 @@ test -f "$profile/bin/guile" # Collisions are properly flagged (in this case, 'g-wrap' propagates # guile@2.2, which conflicts with guile@2.0.) -if guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 -then false; else true; fi +! guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \ --allow-collisions @@ -78,8 +76,7 @@ test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH type -P rm ) # Exit with 1 when a generation does not exist. -if guix package -p "$profile" --delete-generations=42; -then false; else true; fi +! guix package -p "$profile" --delete-generations=42 # Exit with 0 when trying to delete the zeroth generation. guix package -p "$profile" --delete-generations=0 @@ -92,15 +89,12 @@ guix package --bootstrap -i "glibc:debug" -p "$profile" -n # Make sure nonexistent outputs are reported. guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n -if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n; -then false; else true; fi -if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile"; -then false; else true; fi +! guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n +! guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" # Make sure we get an error when trying to remove something that's not # installed. -if guix package --bootstrap -r something-not-installed -p "$profile"; -then false; else true; fi +! guix package --bootstrap -r something-not-installed -p "$profile" # Check whether `--list-available' returns something sensible. guix package -p "$profile" -A 'gui.*e' | grep guile @@ -112,8 +106,8 @@ guix package --show=guile | grep "^name: guile" guix package --show=texlive # Fail for non-existent packages or package/version pairs. -if guix package --show=does-not-exist; then false; else true; fi -if guix package --show=emacs@42; then false; else true; fi +! guix package --show=does-not-exist +! guix package --show=emacs@42 # Search. LC_MESSAGES=C @@ -157,22 +151,19 @@ guix package --search="" > /dev/null # There's no generation older than 12 months, so the following command should # have no effect. generation="`readlink_base "$profile"`" -if guix package -p "$profile" --delete-generations=12m; -then false; else true; fi +! guix package -p "$profile" --delete-generations=12m test "`readlink_base "$profile"`" = "$generation" # The following command should not delete the current generation, even though # it matches the given pattern (see .) And since # there's nothing else to delete, it should just fail. guix package --list-generations -p "$profile" -if guix package --bootstrap -p "$profile" --delete-generations=1.. -then false; else true; fi +! guix package --bootstrap -p "$profile" --delete-generations=1.. test "`readlink_base "$profile"`" = "$generation" # Make sure $profile is a GC root at this point. real_profile="`readlink -f "$profile"`" -if guix gc -d "$real_profile" -then false; else true; fi +! guix gc -d "$real_profile" test -d "$real_profile" # Now, let's remove all the symlinks to $real_profile, and make sure @@ -238,16 +229,15 @@ done # Check whether '-p ~/.guix-profile' makes any difference. # See . -if test -e "$HOME/.guix-profile-0-link"; then false; fi -if test -e "$HOME/.guix-profile-1-link"; then false; fi +! test -e "$HOME/.guix-profile-0-link" +! test -e "$HOME/.guix-profile-1-link" guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap -if test -e "$HOME/.guix-profile-1-link"; then false; fi +! test -e "$HOME/.guix-profile-1-link" guix package --bootstrap --roll-back -p "$HOME/.guix-profile" -if test -e "$HOME/.guix-profile-0-link"; then false; fi +! test -e "$HOME/.guix-profile-0-link" # Extraneous argument. -if guix package install foo-bar; -then false; else true; fi +! guix package install foo-bar # Make sure the "broken pipe" doesn't yield an error. # Note: 'pipefail' is a Bash-specific option. @@ -336,8 +326,7 @@ cat > "$module_dir/package.scm"< Date: Tue, 29 Sep 2020 10:29:23 +0200 Subject: openpgp: Fix argument order of 'fxbit-set?'. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/openpgp.scm (fxbit-set?): Change to swap arguments compared to 'bit-set?'. * tests/openpgp.scm (%binary-sample): New test vector. ("port-ascii-armored?, #t"): Add test. ("port-ascii-armored?, #f"): Add another test. Co-authored-by: Ludovic Courtès --- guix/openpgp.scm | 2 +- tests/openpgp.scm | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/guix/openpgp.scm b/guix/openpgp.scm index 33c851255b..153752ee73 100644 --- a/guix/openpgp.scm +++ b/guix/openpgp.scm @@ -110,7 +110,7 @@ (define-alias fx* *) (define-alias fx/ /) (define-alias fxdiv quotient) (define-alias fxand logand) -(define-alias fxbit-set? bit-set?) +(define-inlinable (fxbit-set? n index) (bit-set? index n)) (define-alias fxbit-field bit-field) (define-alias bitwise-bit-field bit-field) (define-alias fxarithmetic-shift-left ash) diff --git a/tests/openpgp.scm b/tests/openpgp.scm index 0beab6f88b..c2be26fa49 100644 --- a/tests/openpgp.scm +++ b/tests/openpgp.scm @@ -50,6 +50,12 @@ (define %radix-64-sample/crc-mismatch =AAAA -----END PGP MESSAGE-----\n") +(define %binary-sample + ;; Same message as %radix-64-sample, decoded into bytevector. + (base16-string->bytevector + "c838013b6d96c411efecef17ecefe3ca0004ce8979ea250a897995f979a9\ +0ad9a9a9050a890ac5a9c945a940c1a2fcd2bc14858cd4a2547b2e00")) + (define %civodul-fingerprint "3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5") @@ -155,6 +161,12 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1 read-radix-64)) list)) +(test-assert "port-ascii-armored?, #t" + (call-with-input-string %radix-64-sample port-ascii-armored?)) + +(test-assert "port-ascii-armored?, #f" + (not (port-ascii-armored? (open-bytevector-input-port %binary-sample)))) + (test-assert "get-openpgp-keyring" (let* ((key (search-path %load-path "tests/civodul.key")) (keyring (get-openpgp-keyring -- cgit v1.2.3 From 313f492657f1d0863c641fa5ee7f5b7028e27c94 Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Fri, 31 Jul 2020 16:49:29 +0200 Subject: scripts: system: Add support for image-type. * guix/scripts/system.scm (list-image-types): New procedure, (%options): add "image-type" and "list-image-types" options, remove "file-system-type" option, (show-help): adapt accordingly, (%default-options): also adapt, and set the default "image-type" to "raw", (perform-action): add image-type argument and remove file-system-type argument, (process-action): adapt perform-action call, (system-derivation-for-action): remove base-image argument, add image-type argument, and use it to create the image passed to "system-image". * tests/guix-system.sh: Adapt accordingly and add a test for "--list-image-types" command. * doc/guix.texi (Building the Installation Image, Invoking guix system): Adapt accordingly. Signed-off-by: Mathieu Othacehe --- Makefile.am | 5 ++-- doc/guix.texi | 43 ++++++++++++++++-------------- guix/scripts/system.scm | 70 +++++++++++++++++++++++++++++++------------------ tests/guix-system.sh | 9 ++++--- 4 files changed, 75 insertions(+), 52 deletions(-) (limited to 'tests') diff --git a/Makefile.am b/Makefile.am index 8e91e1e558..9c3ff4420f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -833,9 +833,8 @@ release: dist-with-updated-version -v1 --no-grafts --fallback for system in $(GUIX_SYSTEM_SUPPORTED_SYSTEMS) ; do \ image=`$(top_builddir)/pre-inst-env \ - guix system disk-image \ - --file-system-type=iso9660 \ - --label="GUIX_$${system}_$(VERSION)" \ + guix system disk-image -t iso9660 \ + --label="GUIX_$${system}_$(VERSION)" \ --system=$$system --fallback \ gnu/system/install.scm` ; \ if [ ! -f "$$image" ] ; then \ diff --git a/doc/guix.texi b/doc/guix.texi index ff2e582347..e8458ad8d8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -40,7 +40,7 @@ Copyright @copyright{} 2016, 2017, 2018, 2019, 2020 Julien Lepiller@* Copyright @copyright{} 2016 Alex ter Weele@* Copyright @copyright{} 2016, 2017, 2018, 2019 Christopher Baines@* Copyright @copyright{} 2017, 2018, 2019 Clément Lassieur@* -Copyright @copyright{} 2017, 2018 Mathieu Othacehe@* +Copyright @copyright{} 2017, 2018, 2020 Mathieu Othacehe@* Copyright @copyright{} 2017 Federico Beffa@* Copyright @copyright{} 2017, 2018 Carlo Zancanaro@* Copyright @copyright{} 2017 Thomas Danckaert@* @@ -2568,8 +2568,7 @@ The installation image described above was built using the @command{guix system} command, specifically: @example -guix system disk-image --file-system-type=iso9660 \ - gnu/system/install.scm +guix system disk-image -t iso9660 gnu/system/install.scm @end example Have a look at @file{gnu/system/install.scm} in the source tree, @@ -29375,24 +29374,28 @@ a value. Docker images are built to contain exactly what they need, so the @option{--image-size} option is ignored in the case of @code{docker-image}. -You can specify the root file system type by using the -@option{--file-system-type} option. It defaults to @code{ext4}. When its -value is @code{iso9660}, the @option{--label} option can be used to specify -a volume ID with @code{disk-image}. +The @code{disk-image} command can produce various image types. The +image type can be selected using the @command{--image-type} option. It +defaults to @code{raw}. When its value is @code{iso9660}, the +@option{--label} option can be used to specify a volume ID with +@code{disk-image}. -When using @code{vm-image}, the returned image is in qcow2 format, which -the QEMU emulator can efficiently use. @xref{Running Guix in a VM}, -for more information on how to run the image in a virtual machine. - -When using @code{disk-image}, a raw disk image is produced; it can be -copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is -the device corresponding to a USB stick, one can copy the image to it -using the following command: +When using the @code{raw} image type, a raw disk image is produced; it +can be copied as is to a USB stick, for instance. Assuming +@code{/dev/sdc} is the device corresponding to a USB stick, one can copy +the image to it using the following command: @example # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc status=progress @end example +The @code{--list-image-types} command lists all the available image +types. + +When using @code{vm-image}, the returned image is in qcow2 format, which +the QEMU emulator can efficiently use. @xref{Running Guix in a VM}, +for more information on how to run the image in a virtual machine. + When using @code{docker-image}, a Docker image is produced. Guix builds the image from scratch, not from a pre-existing Docker base image. As a result, it contains @emph{exactly} what you define in the operating @@ -29494,17 +29497,17 @@ information, one can rebuild the image to make sure it really contains what it pretends to contain; or they could use that to derive a variant of the image. -@item --file-system-type=@var{type} +@item --image-type=@var{type} @itemx -t @var{type} -For the @code{disk-image} action, create a file system of the given -@var{type} on the image. +For the @code{disk-image} action, create an image with given @var{type}. -When this option is omitted, @command{guix system} uses @code{ext4}. +When this option is omitted, @command{guix system} uses the @code{raw} +image type. @cindex ISO-9660 format @cindex CD image format @cindex DVD image format -@option{--file-system-type=iso9660} produces an ISO-9660 image, suitable +@option{--image-type=iso9660} produces an ISO-9660 image, suitable for burning on CDs and DVDs. @item --image-size=@var{size} diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index bd5f84fc5b..7b3eacf2e1 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -666,8 +666,8 @@ (define file-systems ;;; Action. ;;; -(define* (system-derivation-for-action os base-image action - #:key image-size file-system-type +(define* (system-derivation-for-action os action + #:key image-size image-type full-boot? container-shared-network? mappings label) "Return as a monadic value the derivation for OS according to ACTION." @@ -690,12 +690,15 @@ (define* (system-derivation-for-action os base-image action (* 70 (expt 2 20))) #:mappings mappings)) ((disk-image) - (lower-object - (system-image - (image - (inherit (if label (image-with-label base-image label) base-image)) - (size image-size) - (operating-system os))))) + (let ((base-image (os->image os #:type image-type))) + (lower-object + (system-image + (image + (inherit (if label + (image-with-label base-image label) + base-image)) + (size image-size) + (operating-system os)))))) ((docker-image) (system-docker-image os #:shared-network? container-shared-network?)))) @@ -748,18 +751,19 @@ (define* (perform-action action os install-bootloader? dry-run? derivations-only? use-substitutes? bootloader-target target - image-size file-system-type full-boot? label - container-shared-network? + image-size image-type + full-boot? label container-shared-network? (mappings '()) (gc-root #f)) "Perform ACTION for OS. INSTALL-BOOTLOADER? specifies whether to install bootloader; BOOTLOADER-TAGET is the target for the bootloader; TARGET is the target root directory; IMAGE-SIZE is the size of the image to be built, for -the 'vm-image' and 'disk-image' actions. The root file system is created as a -FILE-SYSTEM-TYPE file system. FULL-BOOT? is used for the 'vm' action; it -determines whether to boot directly to the kernel or to the bootloader. -CONTAINER-SHARED-NETWORK? determines if the container will use a separate -network namespace. +the 'vm-image' and 'disk-image' actions. IMAGE-TYPE is the type of image to +be built. + +FULL-BOOT? is used for the 'vm' action; it determines whether to +boot directly to the kernel or to the bootloader. CONTAINER-SHARED-NETWORK? +determines if the container will use a separate network namespace. When DERIVATIONS-ONLY? is true, print the derivation file name(s) without building anything. @@ -799,11 +803,9 @@ (define bootcfg (check-initrd-modules os))) (mlet* %store-monad - ((target* (current-target-system)) - (image -> (find-image file-system-type target*)) - (sys (system-derivation-for-action os image action + ((sys (system-derivation-for-action os action #:label label - #:file-system-type file-system-type + #:image-type image-type #:image-size image-size #:full-boot? full-boot? #:container-shared-network? container-shared-network? @@ -886,6 +888,17 @@ (define (export-shepherd-graph os port) #:node-type (shepherd-service-node-type shepherds) #:reverse-edges? #t))) + +;;; +;;; Images. +;;; + +(define (list-image-types) + "Print the available image types." + (display (G_ "The available image types are:\n")) + (newline) + (format #t "~{ - ~a ~%~}" (map image-type-name (force %image-types)))) + ;;; ;;; Options. @@ -945,9 +958,9 @@ (define (show-help) apply STRATEGY (one of nothing-special, backtrace, or debug) when an error occurs while reading FILE")) (display (G_ " - --file-system-type=TYPE - for 'disk-image', produce a root file system of TYPE - (one of 'ext4', 'iso9660')")) + --list-image-types list available image types")) + (display (G_ " + -t, --image-type=TYPE for 'disk-image', produce an image of TYPE")) (display (G_ " --image-size=SIZE for 'vm-image', produce an image of SIZE")) (display (G_ " @@ -1008,10 +1021,14 @@ (define %options (lambda (opt name arg result) (alist-cons 'on-error (string->symbol arg) result))) - (option '(#\t "file-system-type") #t #f + (option '(#\t "image-type") #t #f (lambda (opt name arg result) - (alist-cons 'file-system-type arg + (alist-cons 'image-type (string->symbol arg) result))) + (option '("list-image-types") #f #f + (lambda (opt name arg result) + (list-image-types) + (exit 0))) (option '("image-size") #t #f (lambda (opt name arg result) (alist-cons 'image-size (size->number arg) @@ -1080,7 +1097,7 @@ (define %default-options (debug . 0) (verbosity . #f) ;default (validate-reconfigure . ,ensure-forward-reconfigure) - (file-system-type . "ext4") + (image-type . raw) (image-size . guess) (install-bootloader? . #t) (label . #f))) @@ -1177,7 +1194,8 @@ (define save-provenance? (assoc-ref opts 'skip-safety-checks?) #:validate-reconfigure (assoc-ref opts 'validate-reconfigure) - #:file-system-type (assoc-ref opts 'file-system-type) + #:image-type (lookup-image-type-by-name + (assoc-ref opts 'image-type)) #:image-size (assoc-ref opts 'image-size) #:full-boot? (assoc-ref opts 'full-boot?) #:container-shared-network? diff --git a/tests/guix-system.sh b/tests/guix-system.sh index 0e22686a34..667e084fcf 100644 --- a/tests/guix-system.sh +++ b/tests/guix-system.sh @@ -261,8 +261,8 @@ guix system vm "$tmpfile" -d | grep '\.drv$' drv1="`guix system vm "$tmpfile" -d`" drv2="`guix system vm "$tmpfile" -d`" test "$drv1" = "$drv2" -drv1="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`" -drv2="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`" +drv1="`guix system disk-image -t iso9660 "$tmpfile" -d`" +drv2="`guix system disk-image -t iso9660 "$tmpfile" -d`" test "$drv1" = "$drv2" make_user_config "group-that-does-not-exist" "users" @@ -320,5 +320,8 @@ guix system -n vm gnu/system/examples/vm-image.tmpl guix system -n vm-image gnu/system/examples/vm-image.tmpl # This invocation was taken care of in the loop above: # guix system -n disk-image gnu/system/examples/bare-bones.tmpl -guix system -n disk-image --file-system-type=iso9660 gnu/system/examples/bare-bones.tmpl +guix system -n disk-image -t iso9660 gnu/system/examples/bare-bones.tmpl guix system -n docker-image gnu/system/examples/docker-image.tmpl + +# Verify that at least the raw image type is available. +guix system --list-image-types | grep "raw" -- cgit v1.2.3 From e74818353882f187e5971b5a3a481f17df883dbe Mon Sep 17 00:00:00 2001 From: Jelle Licht Date: Tue, 29 Sep 2020 23:25:13 +0200 Subject: linux-container: Reset jailed root permissions. * gnu/build/linux-container.scm (mount-file-systems): Add 'chmod' call. * tests/containers.scm ("call-with-container, mnt namespace, root permissions"): New test. --- gnu/build/linux-container.scm | 3 ++- tests/containers.scm | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index 2d4de788df..4a8bed5a9a 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm @@ -170,7 +170,8 @@ (define* (mount* source target type #:optional (flags 0) options (pivot-root root put-old) (chdir "/") (umount "real-root" MNT_DETACH) - (rmdir "real-root"))) + (rmdir "real-root") + (chmod "/" #o755))) (define* (initialize-user-namespace pid host-uids #:key (guest-uid 0) (guest-gid 0)) diff --git a/tests/containers.scm b/tests/containers.scm index 7b63e5c108..608902c41a 100644 --- a/tests/containers.scm +++ b/tests/containers.scm @@ -133,6 +133,14 @@ (define (skip-if-unsupported) (lambda () (primitive-exit 0))))) +(skip-if-unsupported) +(test-assert "call-with-container, mnt namespace, root permissions" + (zero? + (call-with-container '() + (lambda () + (assert-exit (= #o755 (stat:perms (lstat "/"))))) + #:namespaces '(user mnt)))) + (skip-if-unsupported) (test-assert "container-excursion" (call-with-temporary-directory -- cgit v1.2.3 From ad05537e32173403d034a0d552092f566abd05a5 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Fri, 2 Oct 2020 00:16:10 +0200 Subject: tests: opam: Factorize tests. * tests/opam.scm: Remove duplicate code. --- tests/opam.scm | 130 +++++++++++++++++++++++++-------------------------------- 1 file changed, 58 insertions(+), 72 deletions(-) (limited to 'tests') diff --git a/tests/opam.scm b/tests/opam.scm index 68b5908e3f..ef61fbb5cc 100644 --- a/tests/opam.scm +++ b/tests/opam.scm @@ -116,81 +116,67 @@ (define test-repo ;; Test the opam file parser ;; We fold over some test cases. Each case is a pair of the string to parse and the ;; expected result. -(test-assert "parse-strings" - (fold (lambda (test acc) - (display test) (newline) - (and acc - (let ((result (peg:tree (match-pattern string-pat (car test))))) - (if (equal? result (cdr test)) - #t - (pk 'fail (list (car test) result (cdr test)) #f))))) - #t '(("" . #f) - ("\"hello\"" . (string-pat "hello")) - ("\"hello world\"" . (string-pat "hello world")) - ("\"The dreaded \\\"é\\\"\"" . (string-pat "The dreaded \"é\"")) - ("\"Have some \\\\\\\\ :)\"" . (string-pat "Have some \\\\ :)")) - ("\"今日は\"" . (string-pat "今日は"))))) +(define (test-opam-syntax name pattern test-cases) + (test-assert name + (fold (lambda (test acc) + (display test) (newline) + (match test + ((str . expected) + (and acc + (let ((result (peg:tree (match-pattern pattern str)))) + (if (equal? result expected) + #t + (pk 'fail (list str result expected) #f))))))) + #t test-cases))) -(test-assert "parse-multiline-strings" - (fold (lambda (test acc) - (display test) (newline) - (and acc - (let ((result (peg:tree (match-pattern multiline-string (car test))))) - (if (equal? result (cdr test)) - #t - (pk 'fail (list (car test) result (cdr test)) #f))))) - #t '(("" . #f) - ("\"\"\"hello\"\"\"" . (multiline-string "hello")) - ("\"\"\"hello \"world\"!\"\"\"" . (multiline-string "hello \"world\"!")) - ("\"\"\"hello \"\"world\"\"!\"\"\"" . (multiline-string "hello \"\"world\"\"!"))))) +(test-opam-syntax + "parse-strings" string-pat + '(("" . #f) + ("\"hello\"" . (string-pat "hello")) + ("\"hello world\"" . (string-pat "hello world")) + ("\"The dreaded \\\"é\\\"\"" . (string-pat "The dreaded \"é\"")) + ("\"Have some \\\\\\\\ :)\"" . (string-pat "Have some \\\\ :)")) + ("\"今日は\"" . (string-pat "今日は")))) -(test-assert "parse-lists" - (fold (lambda (test acc) - (and acc - (let ((result (peg:tree (match-pattern list-pat (car test))))) - (if (equal? result (cdr test)) - #t - (pk 'fail (list (car test) result (cdr test)) #f))))) - #t '(("" . #f) - ("[]" . list-pat) - ("[make]" . (list-pat (var "make"))) - ("[\"make\"]" . (list-pat (string-pat "make"))) - ("[\n a\n b\n c]" . (list-pat (var "a") (var "b") (var "c"))) - ("[a b \"c\"]" . (list-pat (var "a") (var "b") (string-pat "c")))))) +(test-opam-syntax + "parse-multiline-strings" multiline-string + '(("" . #f) + ("\"\"\"hello\"\"\"" . (multiline-string "hello")) + ("\"\"\"hello \"world\"!\"\"\"" . (multiline-string "hello \"world\"!")) + ("\"\"\"hello \"\"world\"\"!\"\"\"" . (multiline-string "hello \"\"world\"\"!")))) -(test-assert "parse-dicts" - (fold (lambda (test acc) - (and acc - (let ((result (peg:tree (match-pattern dict (car test))))) - (if (equal? result (cdr test)) - #t - (pk 'fail (list (car test) result (cdr test)) #f))))) - #t '(("" . #f) - ("{}" . dict) - ("{a: \"b\"}" . (dict (record "a" (string-pat "b")))) - ("{a: \"b\"\nc: \"d\"}" . (dict (record "a" (string-pat "b")) (record "c" (string-pat "d"))))))) +(test-opam-syntax + "parse-lists" list-pat + '(("" . #f) + ("[]" . list-pat) + ("[make]" . (list-pat (var "make"))) + ("[\"make\"]" . (list-pat (string-pat "make"))) + ("[\n a\n b\n c]" . (list-pat (var "a") (var "b") (var "c"))) + ("[a b \"c\"]" . (list-pat (var "a") (var "b") (string-pat "c"))))) -(test-assert "parse-conditions" - (fold (lambda (test acc) - (and acc - (let ((result (peg:tree (match-pattern condition (car test))))) - (if (equal? result (cdr test)) - #t - (pk 'fail (list (car test) result (cdr test)) #f))))) - #t '(("" . #f) - ("{}" . #f) - ("{build}" . (condition-var "build")) - ("{>= \"0.2.0\"}" . (condition-greater-or-equal - (condition-string "0.2.0"))) - ("{>= \"0.2.0\" & test}" . (condition-and - (condition-greater-or-equal - (condition-string "0.2.0")) - (condition-var "test"))) - ("{>= \"0.2.0\" | build}" . (condition-or - (condition-greater-or-equal - (condition-string "0.2.0")) - (condition-var "build"))) - ("{ = \"1.0+beta19\" }" . (condition-eq - (condition-string "1.0+beta19")))))) +(test-opam-syntax + "parse-dicts" dict + '(("" . #f) + ("{}" . dict) + ("{a: \"b\"}" . (dict (record "a" (string-pat "b")))) + ("{a: \"b\"\nc: \"d\"}" . (dict (record "a" (string-pat "b")) (record "c" (string-pat "d")))))) + +(test-opam-syntax + "parse-conditions" condition + '(("" . #f) + ("{}" . #f) + ("{build}" . (condition-var "build")) + ("{>= \"0.2.0\"}" . (condition-greater-or-equal + (condition-string "0.2.0"))) + ("{>= \"0.2.0\" & test}" . (condition-and + (condition-greater-or-equal + (condition-string "0.2.0")) + (condition-var "test"))) + ("{>= \"0.2.0\" | build}" . (condition-or + (condition-greater-or-equal + (condition-string "0.2.0")) + (condition-var "build"))) + ("{ = \"1.0+beta19\" }" . (condition-eq + (condition-string "1.0+beta19"))))) (test-end "opam") -- cgit v1.2.3 From 23dc21f05b54ef63daaea9eb301cfddbc4c82ddb Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Fri, 2 Oct 2020 00:28:30 +0200 Subject: tests: opam: Test additional syntax. * tests/opam.scm (test-comment): New test. (test-lists): Add more tests for complex list patterns. --- tests/opam.scm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/opam.scm b/tests/opam.scm index ef61fbb5cc..ec2a668307 100644 --- a/tests/opam.scm +++ b/tests/opam.scm @@ -152,7 +152,11 @@ (define (test-opam-syntax name pattern test-cases) ("[make]" . (list-pat (var "make"))) ("[\"make\"]" . (list-pat (string-pat "make"))) ("[\n a\n b\n c]" . (list-pat (var "a") (var "b") (var "c"))) - ("[a b \"c\"]" . (list-pat (var "a") (var "b") (string-pat "c"))))) + ("[a b \"c\"]" . (list-pat (var "a") (var "b") (string-pat "c"))) + ;; complex lists + ("[(a & b)]" . (list-pat (choice-pat (group-pat (var "a") (var "b"))))) + ("[(a | b & c)]" . (list-pat (choice-pat (var "a") (group-pat (var "b") (var "c"))))) + ("[a (b | c) d]" . (list-pat (var "a") (choice-pat (var "b") (var "c")) (var "d"))))) (test-opam-syntax "parse-dicts" dict @@ -179,4 +183,9 @@ (define (test-opam-syntax name pattern test-cases) ("{ = \"1.0+beta19\" }" . (condition-eq (condition-string "1.0+beta19"))))) +(test-opam-syntax + "parse-comment" list-pat + '(("" . #f) + ("[#comment\n]" . list-pat))) + (test-end "opam") -- cgit v1.2.3 From f43ffee90882c2d61b46d69728daa7432be297e4 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 1 Oct 2020 22:09:58 +0200 Subject: gexp: 'local-file' warns when passed a non-literal relative file name. Fixes . Reported by Vitaliy Shatrov . * guix/gexp.scm (%local-file): Add #:literal? and #:location. Emit a warning when LITERAL? is false and FILE is not absolute. (local-file): In the non-literal case, pass #:location and #:literal?. * po/guix/POTFILES.in: Add guix/gexp.scm. * tests/guix-system.sh: Add test for the warning. --- guix/gexp.scm | 19 +++++++++++++++---- po/guix/POTFILES.in | 1 + tests/guix-system.sh | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/guix/gexp.scm b/guix/gexp.scm index 9d3c52e783..40346b61e1 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -26,6 +26,8 @@ (define-module (guix gexp) #:use-module (guix derivations) #:use-module (guix grafts) #:use-module (guix utils) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (rnrs bytevectors) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) @@ -401,9 +403,15 @@ (define-record-type (define (true file stat) #t) (define* (%local-file file promise #:optional (name (basename file)) - #:key recursive? (select? true)) + #:key + (literal? #t) location + recursive? (select? true)) ;; This intermediate procedure is part of our ABI, but the underlying ;; %%LOCAL-FILE is not. + (when (and (not literal?) (not (string-prefix? "/" file))) + (warning (and=> location source-properties->location) + (G_ "resolving '~a' relative to current directory~%") + file)) (%%local-file file promise name recursive? select?)) (define (absolute-file-name file directory) @@ -443,9 +451,12 @@ (define-syntax local-file rest ...)) ((_ file rest ...) ;; Resolve FILE relative to the current directory. - #'(%local-file file - (delay (absolute-file-name file (getcwd))) - rest ...)) + (with-syntax ((location (datum->syntax s (syntax-source s)))) + #`(%local-file file + (delay (absolute-file-name file (getcwd))) + #:location 'location + #:literal? #f + rest ...))) ((_) #'(syntax-error "missing file name")) (id diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index f4d020782c..b877fac9df 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -76,6 +76,7 @@ guix/scripts/weather.scm guix/scripts/describe.scm guix/scripts/processes.scm guix/scripts/deploy.scm +guix/gexp.scm guix/gnu-maintenance.scm guix/scripts/container.scm guix/scripts/container/exec.scm diff --git a/tests/guix-system.sh b/tests/guix-system.sh index 667e084fcf..957479ede0 100644 --- a/tests/guix-system.sh +++ b/tests/guix-system.sh @@ -297,6 +297,20 @@ EOF guix system build "$tmpdir/config.scm" -n (cd "$tmpdir"; guix system build "config.scm" -n) +# Check that we get a warning when passing 'local-file' a non-literal relative +# file name. +cat > "$tmpdir/config.scm" <&1 | \ + grep "config\.scm:4:2: warning:.*whatever.*relative to current directory" + # Searching. guix system search tor | grep "^name: tor" guix system search tor | grep "^shepherdnames: tor" -- cgit v1.2.3 From cc346931523a7235a8093ec96f05412d5f2f468d Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 2 Oct 2020 09:38:46 +0200 Subject: tests: Adjust to recent changes to the 'emacs' package. Test regression introduced in f88fea0eaa5796303790450ee4543a6d7e61a06e. * tests/guix-package.sh: Add minor and patch levels in the version numbers of 'emacs-foo-bar' and 'emacs-foo-bar-patched'. --- tests/guix-package.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/guix-package.sh b/tests/guix-package.sh index 1a95b8e9a4..a43496699b 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès +# Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès # Copyright © 2013 Nikita Karetnikov # # This file is part of GNU Guix. @@ -257,7 +257,7 @@ cat > "$module_dir/foo.scm"< "$module_dir/foo.scm"< Date: Thu, 24 Sep 2020 22:13:06 +0200 Subject: guix build: Record package transformations in manifest entries. With this change, package transformation options used while building a manifest are saved in the metadata of the manifest entries. * guix/scripts/build.scm (transformation-procedure): New procedure. (options->transformation)[applicable]: Use it. Change to a list of key/value/proc tuples instead of key/proc pairs. [package-with-transformation-properties, tagged-object]: New procedures. Use them. (package-transformations, manifest-entry-with-transformations): New procedures. * guix/scripts/pack.scm (guix-pack)[with-transformations]: New procedure. Use it. * guix/scripts/package.scm (process-actions)[transform-entry]: Use it. * tests/guix-package-aliases.sh: Add test. --- guix/scripts/build.scm | 80 ++++++++++++++++++++++++++++++++++--------- guix/scripts/pack.scm | 29 +++++++++------- guix/scripts/package.scm | 13 +++---- tests/guix-package-aliases.sh | 6 ++++ 4 files changed, 93 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index 476e556618..72a5d46347 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -63,6 +63,7 @@ (define-module (guix scripts build) %transformation-options options->transformation + manifest-entry-with-transformations show-transformation-options-help guix-build @@ -427,6 +428,14 @@ (define %transformations (with-git-url . ,transform-package-source-git-url) (without-tests . ,transform-package-tests))) +(define (transformation-procedure key) + "Return the transformation procedure associated with KEY, a symbol such as +'with-source', or #f if there is none." + (any (match-lambda + ((k . proc) + (and (eq? k key) proc))) + %transformations)) + (define %transformation-options ;; The command-line interface to the above transformations. (let ((parser (lambda (symbol) @@ -481,32 +490,69 @@ (define applicable ;; order in which they appear on the command line. (filter-map (match-lambda ((key . value) - (match (any (match-lambda - ((k . proc) - (and (eq? k key) proc))) - %transformations) + (match (transformation-procedure key) (#f #f) (transform ;; XXX: We used to pass TRANSFORM a list of several ;; arguments, but we now pass only one, assuming that ;; transform composes well. - (cons key (transform (list value))))))) + (list key value (transform (list value))))))) (reverse opts))) + (define (package-with-transformation-properties p) + (package/inherit p + (properties `((transformations + . ,(map (match-lambda + ((key value _) + (cons key value))) + applicable)) + ,@(package-properties p))))) + (lambda (store obj) - (fold (match-lambda* - (((name . transform) obj) - (let ((new (transform store obj))) - (when (eq? new obj) - (warning (G_ "transformation '~a' had no effect on ~a~%") - name - (if (package? obj) - (package-full-name obj) - obj))) - new))) - obj - applicable))) + (define (tagged-object new) + (if (and (not (eq? obj new)) + (package? new) (not (null? applicable))) + (package-with-transformation-properties new) + new)) + + (tagged-object + (fold (match-lambda* + (((name value transform) obj) + (let ((new (transform store obj))) + (when (eq? new obj) + (warning (G_ "transformation '~a' had no effect on ~a~%") + name + (if (package? obj) + (package-full-name obj) + obj))) + new))) + obj + applicable)))) + +(define (package-transformations package) + "Return the transformations applied to PACKAGE according to its properties." + (match (assq-ref (package-properties package) 'transformations) + (#f '()) + (transformations transformations))) + +(define (manifest-entry-with-transformations entry) + "Return ENTRY with an additional 'transformations' property if it's not +already there." + (let ((properties (manifest-entry-properties entry))) + (if (assq 'transformations properties) + entry + (let ((item (manifest-entry-item entry))) + (manifest-entry + (inherit entry) + (properties + (match (and (package? item) + (package-transformations item)) + ((or #f '()) + properties) + (transformations + `((transformations . ,transformations) + ,@properties))))))))) ;;; diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index bab3a3e2e4..0b66da01f9 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -1140,19 +1140,24 @@ (define with-provenance manifest)) identity)) + (define (with-transformations manifest) + (map-manifest-entries manifest-entry-with-transformations + manifest)) + (with-provenance - (cond - ((and (not (null? manifests)) (not (null? packages))) - (leave (G_ "both a manifest and a package list were given~%"))) - ((not (null? manifests)) - (concatenate-manifests - (map (lambda (file) - (let ((user-module (make-user-module - '((guix profiles) (gnu))))) - (load* file user-module))) - manifests))) - (else - (packages->manifest packages)))))) + (with-transformations + (cond + ((and (not (null? manifests)) (not (null? packages))) + (leave (G_ "both a manifest and a package list were given~%"))) + ((not (null? manifests)) + (concatenate-manifests + (map (lambda (file) + (let ((user-module (make-user-module + '((guix profiles) (gnu))))) + (load* file user-module))) + manifests))) + (else + (packages->manifest packages))))))) (with-error-handling (with-store store diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 7e7c37eac4..83f8c123d9 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -864,12 +864,13 @@ (define transform (options->transformation opts)) (define (transform-entry entry) (let ((item (transform store (manifest-entry-item entry)))) - (manifest-entry - (inherit entry) - (item item) - (version (if (package? item) - (package-version item) - (manifest-entry-version entry)))))) + (manifest-entry-with-transformations + (manifest-entry + (inherit entry) + (item item) + (version (if (package? item) + (package-version item) + (manifest-entry-version entry))))))) (when (equal? profile %current-profile) ;; Normally the daemon created %CURRENT-PROFILE when we connected, unless diff --git a/tests/guix-package-aliases.sh b/tests/guix-package-aliases.sh index e4ddace057..311838b768 100644 --- a/tests/guix-package-aliases.sh +++ b/tests/guix-package-aliases.sh @@ -39,6 +39,12 @@ test -x "$profile/bin/guile" ! guix install -r guile-bootstrap -p "$profile" --bootstrap test -x "$profile/bin/guile" +# Use a package transformation option and make sure it's recorded. +guix install --bootstrap guile-bootstrap -p "$profile" \ + --with-input=libreoffice=inkscape +test -x "$profile/bin/guile" +grep "libreoffice=inkscape" "$profile/manifest" + guix upgrade --version guix upgrade -n guix upgrade gui.e -n -- cgit v1.2.3 From 8e1907a72430aa989125b053573ef0897c480697 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 25 Sep 2020 17:16:34 +0200 Subject: guix package: Re-apply package transformation when upgrading. * guix/scripts/package.scm (transaction-upgrade-entry)[upgrade]: Add 'transform' parameter. Pass PKG through it. Use 'manifest-entry-with-transformations'. Call 'options->transformation' to get the transformation procedure. * tests/guix-package.sh: Add 'guix package -u' test. * tests/packages.scm ("transaction-upgrade-entry, transformation options preserved"): New test. * doc/guix.texi (Invoking guix package): Mention that transformations are preserved across upgrades. (Package Transformation Options): Likewise. --- doc/guix.texi | 27 +++++++++++++++++++++++++++ guix/scripts/package.scm | 20 +++++++++++++++----- tests/guix-package.sh | 15 +++++++++++++++ tests/packages.scm | 23 +++++++++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/doc/guix.texi b/doc/guix.texi index da48c8a72d..a6260a12aa 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -3101,6 +3101,29 @@ in the distribution currently installed. To update your distribution, you should regularly run @command{guix pull} (@pxref{Invoking guix pull}). +@cindex package transformations, upgrades +When upgrading, package transformations that were originally applied +when creating the profile are automatically re-applied (@pxref{Package +Transformation Options}). For example, assume you first installed Emacs +from the tip of its development branch with: + +@example +guix install emacs-next --with-branch=emacs-next=master +@end example + +Next time you run @command{guix upgrade}, Guix will again pull the tip +of the Emacs development branch and build @code{emacs-next} from that +checkout. + +Note that transformation options such as @option{--with-branch} and +@option{--with-source} depend on external state; it is up to you to +ensure that they work as expected. You can also discard a +transformations that apply to a package by running: + +@example +guix install @var{package} +@end example + @item --do-not-upgrade[=@var{regexp} @dots{}] When used together with the @option{--upgrade} option, do @emph{not} upgrade any packages whose name matches a @var{regexp}. For example, to @@ -9193,6 +9216,10 @@ This is a convenient way to create customized packages on the fly without having to type in the definitions of package variants (@pxref{Defining Packages}). +Package transformation options are preserved across upgrades: +@command{guix upgrade} attempts to apply transformation options +initially used when creating the profile to the upgraded packages. + @table @code @item --with-source=@var{source} diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 83f8c123d9..2f04652634 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -218,12 +218,13 @@ (define (supersede old new) (output (manifest-entry-output old))) transaction))) - (define (upgrade entry) + (define (upgrade entry transform) (match entry (($ name version output (? string? path)) (match (find-best-packages-by-name name #f) ((pkg . rest) - (let ((candidate-version (package-version pkg))) + (let* ((pkg (transform store pkg)) + (candidate-version (package-version pkg))) (match (package-superseded pkg) ((? package? new) (supersede entry new)) @@ -231,12 +232,14 @@ (define (upgrade entry) (case (version-compare candidate-version version) ((>) (manifest-transaction-install-entry - (package->manifest-entry* pkg output) + (manifest-entry-with-transformations + (package->manifest-entry* pkg output)) transaction)) ((<) transaction) ((=) - (let* ((new (package->manifest-entry* pkg output))) + (let* ((new (manifest-entry-with-transformations + (package->manifest-entry* pkg output)))) ;; Here we want to determine whether the NEW actually ;; differs from ENTRY, but we need to intercept ;; 'build-things' calls because they would prevent us from @@ -255,7 +258,14 @@ (define (upgrade entry) (if (manifest-transaction-removal-candidate? entry transaction) transaction - (upgrade entry))) + + ;; Upgrade ENTRY, preserving transformation options listed in its + ;; properties. + (let ((transform (options->transformation + (or (assq-ref (manifest-entry-properties entry) + 'transformations) + '())))) + (upgrade entry transform)))) ;;; diff --git a/tests/guix-package.sh b/tests/guix-package.sh index a43496699b..3e5fa71d20 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -184,6 +184,21 @@ grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile" rm "$emacs_tarball" "$tmpfile" rmdir "$module_dir" +# Install with package transformations. +guix install --bootstrap -p "$profile" sed --with-input=sed=guile-bootstrap +grep "sed=guile-bootstrap" "$profile/manifest" +test "$(readlink -f "$profile/bin/guile")" \ + = "$(guix build guile-bootstrap)/bin/guile" +test ! -f "$profile/bin/sed" + +# Make sure the package transformation is preserved. +guix package --bootstrap -p "$profile" -u +grep "sed=guile-bootstrap" "$profile/manifest" +test "$(readlink -f "$profile/bin/guile")" \ + = "$(guix build guile-bootstrap)/bin/guile" +test ! -f "$profile/bin/sed" +rm "$profile" "$profile"-[0-9]-link + # Profiles with a relative file name. Make sure we don't create dangling # symlinks--see bug report at # . diff --git a/tests/packages.scm b/tests/packages.scm index af8941c2e2..5d5abcbd76 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -187,6 +187,29 @@ (define %store (string=? (manifest-pattern-version pattern) "1") (string=? (manifest-pattern-output pattern) "out"))))))) +(test-equal "transaction-upgrade-entry, transformation options preserved" + (derivation-file-name (package-derivation %store grep)) + + (let* ((old (dummy-package "emacs" (version "1"))) + (props '((transformations . ((with-input . "emacs=grep"))))) + (tx (transaction-upgrade-entry + %store + (manifest-entry + (inherit (package->manifest-entry old)) + (properties props) + (item (string-append (%store-prefix) "/" + (make-string 32 #\e) "-foo-1"))) + (manifest-transaction)))) + (match (manifest-transaction-install tx) + (((? manifest-entry? entry)) + (and (string=? (manifest-entry-version entry) + (package-version grep)) + (string=? (manifest-entry-name entry) + (package-name grep)) + (equal? (manifest-entry-properties entry) props) + (derivation-file-name + (package-derivation %store (manifest-entry-item entry)))))))) + (test-assert "transaction-upgrade-entry, grafts" ;; Ensure that, when grafts are enabled, 'transaction-upgrade-entry' doesn't ;; try to build stuff. -- cgit v1.2.3 From 0f53c801b91919380a924b402d1ff822bb1dc6ea Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 2 Oct 2020 23:17:40 +0200 Subject: environment: Provide /etc/hosts in containers without '--network'. Fixes . * guix/scripts/environment.scm (launch-environment/container): Create /etc/hosts when NETWORK? is false. * tests/guix-environment-container.sh: Add "localhost" resolution test. --- guix/scripts/environment.scm | 7 +++++++ tests/guix-environment-container.sh | 4 ++++ 2 files changed, 11 insertions(+) (limited to 'tests') diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index e2e481dd02..9698111cd2 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -549,6 +549,13 @@ (define (optional-mapping->fs mapping) (write-passwd (list passwd)) (write-group groups) + (unless network? + ;; When isolated from the network, provide a minimal /etc/hosts + ;; to resolve "localhost". + (call-with-output-file "/etc/hosts" + (lambda (port) + (display "127.0.0.1 localhost\n" port)))) + ;; For convenience, start in the user's current working ;; directory or, if unmapped, the home directory. (chdir (if map-cwd? diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index 040f32cce9..3674aa6026 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh @@ -44,6 +44,10 @@ else test $? = 42 fi +# Make sure "localhost" resolves. +guix environment --container --ad-hoc --bootstrap guile-bootstrap \ + -- guile -c '(exit (pair? (getaddrinfo "localhost" "80")))' + # Make sure '--preserve' is honored. result="`FOOBAR=42; export FOOBAR; guix environment -C --ad-hoc --bootstrap \ guile-bootstrap -E ^FOO -- guile -c '(display (getenv \"FOOBAR\"))'`" -- cgit v1.2.3 From b68d4106518abed20ba308831b65dcc69bf120a5 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 4 Oct 2020 22:40:26 +0200 Subject: environment: Turn "lo" up in network-less containers. This is a followup to 0f53c801b91919380a924b402d1ff822bb1dc6ea. * guix/scripts/environment.scm (launch-environment/container): Add call to 'set-network-interface-up'. * tests/guix-environment-container.sh: Add test. --- guix/scripts/environment.scm | 6 +++++- tests/guix-environment-container.sh | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 9698111cd2..085f11a9d4 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -34,6 +34,7 @@ (define-module (guix scripts environment) #:use-module (guix scripts build) #:use-module (gnu build linux-container) #:use-module (gnu build accounts) + #:use-module ((guix build syscalls) #:select (set-network-interface-up)) #:use-module (gnu system linux-container) #:use-module (gnu system file-systems) #:use-module (gnu packages) @@ -554,7 +555,10 @@ (define (optional-mapping->fs mapping) ;; to resolve "localhost". (call-with-output-file "/etc/hosts" (lambda (port) - (display "127.0.0.1 localhost\n" port)))) + (display "127.0.0.1 localhost\n" port))) + + ;; Allow local AF_INET communications. + (set-network-interface-up "lo")) ;; For convenience, start in the user's current working ;; directory or, if unmapped, the home directory. diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index 3674aa6026..f2d15c8d0c 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh @@ -48,6 +48,17 @@ fi guix environment --container --ad-hoc --bootstrap guile-bootstrap \ -- guile -c '(exit (pair? (getaddrinfo "localhost" "80")))' +# We should get ECONNREFUSED, not ENETUNREACH, which would indicate that "lo" +# is down. +guix environment --container --ad-hoc --bootstrap guile-bootstrap \ + -- guile -c "(exit (= ECONNREFUSED + (catch 'system-error + (lambda () + (let ((sock (socket AF_INET SOCK_STREAM 0))) + (connect sock AF_INET INADDR_LOOPBACK 12345))) + (lambda args + (pk 'errno (system-error-errno args))))))" + # Make sure '--preserve' is honored. result="`FOOBAR=42; export FOOBAR; guix environment -C --ad-hoc --bootstrap \ guile-bootstrap -E ^FOO -- guile -c '(display (getenv \"FOOBAR\"))'`" -- cgit v1.2.3