From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id CPv+DGVRRGH8nQAAgWs5BA (envelope-from ) for ; Fri, 17 Sep 2021 10:27:17 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id sLyKCGVRRGFjVwAAbx9fmQ (envelope-from ) for ; Fri, 17 Sep 2021 08:27:17 +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 470B2A07C for ; Fri, 17 Sep 2021 10:27:16 +0200 (CEST) Received: from localhost ([::1]:41772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR9DG-0005Sn-U3 for larch@yhetil.org; Fri, 17 Sep 2021 04:27:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR9D4-0005Kr-5a for guix-patches@gnu.org; Fri, 17 Sep 2021 04:27:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mR9D3-00013w-TK for guix-patches@gnu.org; Fri, 17 Sep 2021 04:27:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mR9D3-0001st-IN for guix-patches@gnu.org; Fri, 17 Sep 2021 04:27:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50614] [PATCH] 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: Fri, 17 Sep 2021 08:27: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.16318672167232 (code B ref 50614); Fri, 17 Sep 2021 08:27:01 +0000 Received: (at 50614) by debbugs.gnu.org; 17 Sep 2021 08:26:56 +0000 Received: from localhost ([127.0.0.1]:58443 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mR9Cx-0001sZ-Pq for submit@debbugs.gnu.org; Fri, 17 Sep 2021 04:26:56 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:33300 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mR9Cw-0001sL-2L for 50614@debbugs.gnu.org; Fri, 17 Sep 2021 04:26:55 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1631867204; bh=kf65h+k4wrgAm6eIOeqOs33UDqKrUmq0pRMkl2GKBzE=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=jDNQGHx/wuXtQ4GJZ7obXeGyxXRduj45cWzDbErysec+Qb8LQNf0qScGnT+dU8+AG biAjVTkAE6fxzOjZfY5uS9kFHbD35jSmBWuD+mGJtRmGetboq80JRIxYmhct55yscy ctg7ayXIK5T/NSCm6Ra6L95StjC2p1WULBsTS+kg= In-Reply-To: References: Message-Id: <08db559a4e24a409d332b3552d6a176de6353166.1631867018.git.public@yoctocell.xyz> Date: Fri, 17 Sep 2021 10:26: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=1631867236; 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=oZ9OynYbeCd3+LnM6KapeBlMvTInuvWh5AYvBuL7QKk=; b=qQ49Ix2X+04YZQF0TxNVv/ZXpJjIrSJKa5d8keDnki5NNh39t7OvcyJVTeqIKPN1/GzBsI cOJG3VEMPnBUtrryY1YbIcMpeA6Asdt24hCqadK6VZL/ZCMXBBgGoB1CrSE0+4ajkwS6BU wG3BBwCqxAEi9gziAf4RBpcxN/vrnmGF+Va4sunGG94VHkDwbLJrRIqmmcc2suQdHA6zRG T9ek2Zz84VpHwKH4YHGX/VNYciu6JusF2SUl4d+0F3Z+DEyBjBBvXxEorfZ8HON72LKf8q F/OW++zATbqsoEiY2/77eoVZpFmzLD3teGWdfigwkzJNDs6q+kX0BqPgcFmHGw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1631867236; a=rsa-sha256; cv=none; b=J+9m103pjCRhrIcrtJ+pcbScfVQx/nYqi+zQyPxWfspeSefo1PYSEd1rpjRyHafG8h4aN1 fIWI7B3ZqzEFB3KYSSSRnYKlxAn3Ie8tRE5oH74dnhxTUoQlYc5XJ92870kVu6OTZEmLGR ovJ3nbU+LMpf7P7OVAx79DH48VcUXqi7BYs4vlch6aRLO0NuEaK+DzWGAknIqrcuPYIm5p cNqPRjWTI6ja71bp1UvUzLFBukjyNmfPkXhAZ4aFPQ6BPP5/IeMuhyb+JHrpZT5mv1zrxr 9t2J4V4b8qbSm0U9ae2OJmFy87LbvRmY896xKLeN8seSoho+wzLCWaw4j/JGkg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b="jDNQGHx/"; 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="jDNQGHx/"; 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: 470B2A07C X-Spam-Score: -0.29 X-Migadu-Scanner: scn1.migadu.com X-TUID: X3bc4q8z1exv * 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. --- Changes since v1: * Rename =E2=80=98optional=E2=80=99 to =E2=80=98list-when=E2=80=99. * Make (list-when test consequent ...) equivalent to (if tests (list consequent ...) '()) doc/guix.texi | 35 +++++++++++++++++++++++++++++++++++ guix/build/utils.scm | 17 ++++++++++++++++- tests/build-utils.scm | 8 ++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 9a3e8ae12c..3b469c04c9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8801,6 +8801,41 @@ in a build phase of the @code{wireguard-tools} packa= ge: `("PATH" ":" prefix ,(list coreutils)))))) @end lisp =20 +@subsection Miscellaneous + +@cindex miscellaneous build utilities +This section documents some miscellaneous utilities that are useful to +have. + +@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 is 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 an 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 @@ =20 make-desktop-entry-file =20 - locale-category->string)) + locale-category->string + + list-when)) =20 ;;; @@ -1613,6 +1616,18 @@ returned." 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 @@ print('hello world')")) ("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