From patchwork Thu May 4 11:24:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 49792 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5F0E027BBEC; Thu, 4 May 2023 12:26:24 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9734F27BBE2 for ; Thu, 4 May 2023 12:26:23 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puX67-00021P-G5; Thu, 04 May 2023 07:26:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puX63-00020w-Q6 for guix-patches@gnu.org; Thu, 04 May 2023 07:26:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1puX63-0006em-Hl for guix-patches@gnu.org; Thu, 04 May 2023 07:26:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1puX63-0006FN-Ca for guix-patches@gnu.org; Thu, 04 May 2023 07:26:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63263] [PATCH] gexp: Stop generating unreadable builder scripts. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 04 May 2023 11:26:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63263 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63263@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.168319953123949 (code B ref -1); Thu, 04 May 2023 11:26:03 +0000 Received: (at submit) by debbugs.gnu.org; 4 May 2023 11:25:31 +0000 Received: from localhost ([127.0.0.1]:48730 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puX5X-0006EC-5W for submit@debbugs.gnu.org; Thu, 04 May 2023 07:25:31 -0400 Received: from lists.gnu.org ([209.51.188.17]:42212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puX5T-0006Dq-7j for submit@debbugs.gnu.org; Thu, 04 May 2023 07:25:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puX5J-00018S-Lq for guix-patches@gnu.org; Thu, 04 May 2023 07:25:23 -0400 Received: from mira.cbaines.net ([2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puX5F-0006Dq-HG for guix-patches@gnu.org; Thu, 04 May 2023 07:25:15 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:54d1:d5d4:280e:f699]) by mira.cbaines.net (Postfix) with ESMTPSA id 81B8527BBE2 for ; Thu, 4 May 2023 12:24:49 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 4f989652 for ; Thu, 4 May 2023 11:24:48 +0000 (UTC) From: Christopher Baines Date: Thu, 4 May 2023 12:24:48 +0100 Message-Id: <20230504112448.22462-1-mail@cbaines.net> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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