From 2aae3582fec4ba6ca719eacaa61f17589b09755e Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Thu, 3 Mar 2022 13:57:03 +0000 Subject: [PATCH 1/2] gexp: Correctly handle unquoting S-exp objects. TODO before committing: fix the link to issues.guix.gnu.org in tests/gexp.scm. This fixes a false-positive in the linter: guix lint -c 'wrapper-inputs' libaio * guix/gexp.scm (gexp->approximate-sexp): Allow the 'thing' in to be a sexp, without approximation, by testing if it is a record. * tests/gexp.scm ("unquoted sexp (not a gexp!)"): Test it. --- guix/gexp.scm | 16 +++++++++------- tests/gexp.scm | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/guix/gexp.scm b/guix/gexp.scm index 01dca902f7..c358662799 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -4,7 +4,7 @@ ;;; Copyright © 2018 Jan Nieuwenhuizen ;;; Copyright © 2019, 2020 Mathieu Othacehe ;;; Copyright © 2020 Maxim Cournoyer -;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021, 2022 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -174,12 +174,14 @@ As a result, the S-expression will be approximate if GEXP has references." (map (lambda (reference) (match reference (($ thing output native) - (if (gexp-like? thing) - (gexp->approximate-sexp thing) - ;; Simply returning 'thing' won't work in some - ;; situations; see 'write-gexp' below. - '(*approximate*))) - (_ '(*approximate*)))) + (cond ((gexp-like? thing) + (gexp->approximate-sexp thing)) + ((not (record? thing)) ; a S-exp + thing) + (#true + ;; Simply returning 'thing' won't work in some + ;; situations; see 'write-gexp' below. + '(*approximate*)))))) (gexp-references gexp)))) (define (write-gexp gexp port) diff --git a/tests/gexp.scm b/tests/gexp.scm index ad8e1d57b8..5ac8a1c8ab 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014-2021 Ludovic Courtès -;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021-2022 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -120,6 +120,19 @@ (let ((inside (file-append coreutils "/bin/hello"))) (gexp->approximate-sexp #~(display '#$inside)))) +;; See . +(test-equal "unquoted sexp (not a gexp!)" + '(list #(foo) (foo) () "foo" foo #xf00) + (let ((inside/vector #(foo)) + (inside/list '(foo)) + (inside/empty '()) + (inside/string "foo") + (inside/symbol 'foo) + (inside/number #xf00)) + (gexp->approximate-sexp + #~(list #$inside/vector #$inside/list #$inside/empty #$inside/string + #$inside/symbol #$inside/number)))) + (test-equal "no refs" '(display "hello!") (let ((exp (gexp (display "hello!")))) base-commit: 877da38bd3f279d5618d6c6517f48b50541a1e4c prerequisite-patch-id: 02723e31219a206a489935610553565886035b5c prerequisite-patch-id: a459b4cdc55777caaaf388147b22bf63da979c1d prerequisite-patch-id: 05987288b4e31e7c5de40d624d4c3150d880b97b prerequisite-patch-id: e569fecf0a0045aa9b2220634d305efd0f4901d5 prerequisite-patch-id: 5edb85611913d7cd4000c9fe3f42ee06517df020 prerequisite-patch-id: 6832435e696002c76b2818f4aacb50aab287a227 prerequisite-patch-id: e5a8343cb7dd5c48b2d14a535998d0eef166cded prerequisite-patch-id: 859427824cb6e22635aee667680609c6daff316b prerequisite-patch-id: ccd7c42e84c99029ab51c08b6cf478883140a594 prerequisite-patch-id: 19e75f076ca3906e613c969241b83c5944a2528b prerequisite-patch-id: 67c6a6401d3327f59c7814db59563a54b7fb22e6 prerequisite-patch-id: 6fd0c3aabf51d85f95633e4682667653c137cfb4 prerequisite-patch-id: db78631386ade908f53f9ccfe743cd679ea85047 -- 2.30.2