unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#63263] [PATCH] gexp: Stop generating unreadable builder scripts.
@ 2023-05-04 11:24 Christopher Baines
  2023-05-04 12:47 ` Ludovic Courtès
  0 siblings, 1 reply; 12+ messages in thread
From: Christopher Baines @ 2023-05-04 11:24 UTC (permalink / raw)
  To: 63263

In Guile, it's possible to produce output from write that can't be read, and
this applies to the code staged through g-expressions for derivations.  This
commit detects this early when the derivation is being created, rather than
leaving the error to happen when the derivation is built.

This is important as it means that tools like guix lint will indicate that
there's a problem, hopefully reducing the number of broken derivations in
Guix.

* guix/gexp.scm (gexp->derivation): Check that the builder script can be read.
---
 guix/gexp.scm | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 0fe4f1c98a..7af9302ccf 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -1215,9 +1215,18 @@ (define (add-modules exp modules)
                                                          #:target target)
                                        (return #f)))
                        (guile -> (lowered-gexp-guile lowered))
-                       (builder  (text-file script-name
-                                            (sexp->string
-                                             (lowered-gexp-sexp lowered)))))
+                       (builder  (text-file
+                                  script-name
+                                  (let ((builder-string
+                                         (sexp->string
+                                          (lowered-gexp-sexp lowered))))
+                                    (catch 'read-error
+                                      (lambda ()
+                                        (call-with-input-string builder-string
+                                          read)
+                                        builder-string)
+                                      (lambda (key . args)
+                                        (error "invalid gexp" name exp  args)))))))
     (mbegin %store-monad
       (set-grafting graft?)                       ;restore the initial setting
       (raw-derivation name
-- 
2.39.1





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

end of thread, other threads:[~2023-09-03 17:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-04 11:24 [bug#63263] [PATCH] gexp: Stop generating unreadable builder scripts Christopher Baines
2023-05-04 12:47 ` Ludovic Courtès
2023-05-04 12:57   ` Christopher Baines
2023-05-04 19:14     ` Josselin Poiret via Guix-patches via
2023-05-06  8:05       ` Christopher Baines
2023-05-05 21:45     ` Ludovic Courtès
2023-05-06  7:39       ` Christopher Baines
2023-05-10 15:22         ` Ludovic Courtès
2023-05-10 16:02           ` Christopher Baines
2023-09-01 14:16             ` Maxim Cournoyer
2023-09-02 10:36               ` bug#63263: " Christopher Baines
2023-09-03 14:54                 ` [bug#63263] " Maxim Cournoyer

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

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

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