From patchwork Sun Sep 19 13:50:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 33199 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 DB26A27BBE3; Sun, 19 Sep 2021 14:51:42 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5DAA327BBE1 for ; Sun, 19 Sep 2021 14:51:42 +0100 (BST) Received: from localhost ([::1]:54684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRxEL-00017C-GJ for patchwork@mira.cbaines.net; Sun, 19 Sep 2021 09:51:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRxDi-0000CZ-Bi for guix-patches@gnu.org; Sun, 19 Sep 2021 09:51:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRxDi-0004s5-3N for guix-patches@gnu.org; Sun, 19 Sep 2021 09:51:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mRxDi-0008KH-1C for guix-patches@gnu.org; Sun, 19 Sep 2021 09:51:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50614] [PATCH core-updates v2] build: utils: Add =?utf-8?b?4oCYbGlzdC13aGVu4oCZ?= macro. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 19 Sep 2021 13:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50614 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50614@debbugs.gnu.org Cc: Sarah Morgensen , Liliana Marie Prikler Received: via spool by 50614-submit@debbugs.gnu.org id=B50614.163205945331989 (code B ref 50614); Sun, 19 Sep 2021 13:51:01 +0000 Received: (at 50614) by debbugs.gnu.org; 19 Sep 2021 13:50:53 +0000 Received: from localhost ([127.0.0.1]:37704 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRxDZ-0008Jr-2E for submit@debbugs.gnu.org; Sun, 19 Sep 2021 09:50:53 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:50926 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRxDW-0008Jc-49 for 50614@debbugs.gnu.org; Sun, 19 Sep 2021 09:50:51 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1632059442; bh=OZBnOtVjQbsI8p7v3fH9L73lwroG0LiOGAlWK77nq90=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=dggjx5epdZsp/6mTI40baSHJG5tZp9n2Ip23VNDtnzJa+3Fj6h+p3fApnFxhmnBYd PhRyTmcsgIdl/CDACAbSf6u3bSp5cjld9xIx47ozHnMpPvo4vAZB7Vkv5+ShruCR+n NHJwrvFz75NVm62j6zpF7ZooiW6bpFzW1VGWNMt0= In-Reply-To: <08db559a4e24a409d332b3552d6a176de6353166.1631867018.git.public@yoctocell.xyz> References: <08db559a4e24a409d332b3552d6a176de6353166.1631867018.git.public@yoctocell.xyz> Message-Id: Date: Sun, 19 Sep 2021 15:50:41 +0200 MIME-Version: 1.0 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" X-getmail-retrieved-from-mailbox: Patches * guix/build/utils.scm (list-when): New syntax * tests/build-utils.scm ("list-when: expr1 is non-#f", list-when: expr1 is #f"): Test it. * guix.texi (Build Utilities): Document it. * .dir-locals.el: Set ‘scheme-indent-function’ to 1 for ‘list-when’. --- Changes since v1: * Add an entry for ‘list-when’ in .dir-locals.el. * Some fixes to the documentation. .dir-locals.el | 1 + doc/guix.texi | 34 ++++++++++++++++++++++++++++++++++ guix/build/utils.scm | 17 ++++++++++++++++- tests/build-utils.scm | 8 ++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) base-commit: 22f7d4bce1e694b7ac38e62410d76a6d46d96c5d diff --git a/.dir-locals.el b/.dir-locals.el index 919ed1d1c4..554044ee8c 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -56,6 +56,7 @@ ((nil (eval . (put 'lambda* 'scheme-indent-function 1)) (eval . (put 'substitute* 'scheme-indent-function 1)) (eval . (put 'match-record 'scheme-indent-function 2)) + (eval . (put 'list-when 'scheme-indent-function 1)) ;; 'modify-inputs' and its keywords. (eval . (put 'modify-inputs 'scheme-indent-function 1)) diff --git a/doc/guix.texi b/doc/guix.texi index 9a3e8ae12c..4bea366b8e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8801,6 +8801,40 @@ `("PATH" ":" prefix ,(list coreutils)))))) @end lisp +@subsection Miscellaneous + +@cindex miscellaneous build utilities +This section documents some miscellaneous utilities. + +@deffn {Scheme Syntax} list-when @var{test} @var{consequent} @dots{} +Like @code{when} (@pxref{Conditionals,,, guile, GNU Guile Reference +Manual}), but if @var{test} evaluates to true, return @code{(list +@var{consequent} @dots{})}, and if @var{test} evaluates to false, return +the empty list. This replaces the following idiom: +@end deffn + +@lisp +(if @var{test} + (list @var{consequent} @dots{}) + '()) +@end lisp + +with this: + +@lisp +(list-when @var{test} @var{consequent} @dots{}) +@end lisp + +It can be useful when certain targets require additional configure +flags, e.g., + +@lisp +(arguments + `(#:configure-flags (list "--localstatedir=/var" + "--sysconfdir=/etc" + ,@@(list-when (hurd-target?) "--with-courage")))) +@end lisp + @subsection Build Phases @cindex build phases diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 3beb7da67a..d3fb207ee5 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2020 Efraim Flashner ;;; Copyright © 2020, 2021 Maxim Cournoyer ;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -123,7 +124,9 @@ (define-module (guix build utils) make-desktop-entry-file - locale-category->string)) + locale-category->string + + list-when)) ;;; @@ -1613,6 +1616,18 @@ (define (locale-category->string category) LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME))) + +;;; +;;; Misc. +;;; + +;; If EXPR1 evaluates to a non-#f value, return '(EXPR2 ...). Otherwise, +;; return an empty list. +(define-syntax list-when + (syntax-rules () + ((_ expr1 expr2 ...) + (if expr1 (list expr2 ...) '())))) + ;;; Local Variables: ;;; eval: (put 'call-with-output-file/atomic 'scheme-indent-function 1) ;;; eval: (put 'call-with-ascii-input-file 'scheme-indent-function 1) diff --git a/tests/build-utils.scm b/tests/build-utils.scm index 6b131c0af8..b558feb47d 100644 --- a/tests/build-utils.scm +++ b/tests/build-utils.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2019 Ricardo Wurmus ;;; Copyright © 2021 Maxim Cournoyer ;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -287,5 +288,12 @@ (define-module (test build-utils) ("guile/bin" . ,(dirname (which "guile")))) "guile")))) +(test-equal "list-when: expr1 is non-#f" + (list 3 'bar) + (list-when 'foo (+ 1 2) 'bar)) + +(test-equal "list-when: expr1 is #f" + '() + (list-when #f (+ 2 3) 'bar)) (test-end)