From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uAMXLXBAR2HJSQEAgWs5BA (envelope-from ) for ; Sun, 19 Sep 2021 15:51:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id WNG8KHBAR2FdLwAAB5/wlQ (envelope-from ) for ; Sun, 19 Sep 2021 13:51:44 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E480218FB5 for ; Sun, 19 Sep 2021 15:51:43 +0200 (CEST) Received: from localhost ([::1]:54684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRxEM-00017C-D5 for larch@yhetil.org; Sun, 19 Sep 2021 09:51:42 -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?Q?=E2=80=98list-when=E2=80=99?= 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1632059504; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=zqTZCuh5BkULjQSN9w1xhzacWOgtUqSxaX9cwPucocM=; b=MgNoC01WLCq4mydkNqhBTjXA3cQWuv+DQ+Px8gnCNi446NGYb37UkxPjzumRKcE4GHpdE3 yo9XNrycwh9K1OA0lOPb9D/bDeXp69RdGE3sBkT9qDoXsTusONv0ovu/0FgdNbVPZiX8Y+ +12Gs4XS7ewfS0RVPeI41cEihTI3s9UcFdCnlc9qAzWLMRZ7E04zl/1C+AwGBlWs5jc7Iu xhTVnITF5LOOBiWGQp7amD4rfU50ynGp3aTLBfPftyRATrVbCdYNn9CuaB7nwB9Ms6LEf2 Q3A1h0aeZEg6w5jWUqVBcXOwgXkGIztZ7Z3WWFk9v71IObJB4xQ7YyyGoYgcQg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1632059504; a=rsa-sha256; cv=none; b=VpMBPidGNeToUC/yFe02519cIHSmHmt2pOkt7sgYuRU9vBqP5MoYZgcK7BfTJCrMhcBrel +KFPU45+WqNEG6mFD7orku8qF1QNQGYEjM/BDraJdA6hgHanK1FsO6aPrvAOrTjWbE7c+P Tr4Bk7VXqIGpsh9CpWypIbvAruij4/rf7m6JRLijLo3VfBbtl9PaKcVKO7bmFh9tfGsXm4 LcpnHCmx0pQ/p6j5xYOKxA5SLfuQbrKYyVUvCz6gcGQr0irbW6rsaBgWgf4er7rUeWelsK cIbD901xe8nRIXskKzcNqa96WHr+6SWKhN1RL8v4PSkXUb7mAZWQS0el2xhOTw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=dggjx5ep; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.29 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=dggjx5ep; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: E480218FB5 X-Spam-Score: -0.29 X-Migadu-Scanner: scn0.migadu.com X-TUID: 58mCctDI5cKS * 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 =E2=80=98scheme-indent-function=E2=80=99 to 1 for =E2= =80=98list-when=E2=80=99. --- Changes since v1: * Add an entry for =E2=80=98list-when=E2=80=99 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(-) 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)) =20 ;; '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 =20 +@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=3D/var" + "--sysconfdir=3D/etc" + ,@@(list-when (hurd-target?) "--with-courage"))= )) +@end lisp + @subsection Build Phases =20 @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 =C2=A9 2020 Efraim Flashner ;;; Copyright =C2=A9 2020, 2021 Maxim Cournoyer ;;; Copyright =C2=A9 2021 Maxime Devos +;;; Copyright =C2=A9 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -123,7 +124,9 @@ (define-module (guix build utils) =20 make-desktop-entry-file =20 - locale-category->string)) + locale-category->string + + list-when)) =20 ;;; @@ -1613,6 +1616,18 @@ (define (locale-category->string category) LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME))) =20 + +;;; +;;; 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 =C2=A9 2019 Ricardo Wurmus ;;; Copyright =C2=A9 2021 Maxim Cournoyer ;;; Copyright =C2=A9 2021 Maxime Devos +;;; Copyright =C2=A9 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")))) =20 +(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)) =20 (test-end) base-commit: 22f7d4bce1e694b7ac38e62410d76a6d46d96c5d --=20 2.33.0