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 kGESC0V0Q2EQigAAgWs5BA (envelope-from ) for ; Thu, 16 Sep 2021 18:43:49 +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 GHrBBkV0Q2FwRwAAbx9fmQ (envelope-from ) for ; Thu, 16 Sep 2021 16:43:49 +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 77F7C1D99D for ; Thu, 16 Sep 2021 18:43:48 +0200 (CEST) Received: from localhost ([::1]:36410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQuUF-0002oj-Hr for larch@yhetil.org; Thu, 16 Sep 2021 12:43:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQuAC-0005Dc-3V for guix-patches@gnu.org; Thu, 16 Sep 2021 12:23:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQuAB-0003eS-Rv for guix-patches@gnu.org; Thu, 16 Sep 2021 12:23:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mQuAB-0007Au-Ou for guix-patches@gnu.org; Thu, 16 Sep 2021 12:23:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50614] [PATCH core-updates] build: utils: Add =?UTF-8?Q?=E2=80=98optional=E2=80=99?= macro. Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 16 Sep 2021 16:23:03 +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: Xinglu Chen , 50614@debbugs.gnu.org Received: via spool by 50614-submit@debbugs.gnu.org id=B50614.163180932527373 (code B ref 50614); Thu, 16 Sep 2021 16:23:03 +0000 Received: (at 50614) by debbugs.gnu.org; 16 Sep 2021 16:22:05 +0000 Received: from localhost ([127.0.0.1]:56317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQu9E-00077R-UR for submit@debbugs.gnu.org; Thu, 16 Sep 2021 12:22:05 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39818) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQu9C-00076l-0g for 50614@debbugs.gnu.org; Thu, 16 Sep 2021 12:22:03 -0400 Received: by mail-wr1-f66.google.com with SMTP id u15so10410423wru.6 for <50614@debbugs.gnu.org>; Thu, 16 Sep 2021 09:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=oAoJPFIBOAzw954Rrn9Q8rqGEIQHgf/TicNZDNCCP6M=; b=ddHbP3JNB9wSPcSzYix6+WiLKzk6MMIzx0fOYph2JoThUUp+YlpZjrJ3sF8GAGmoMu X0+Iqjvc/CT5UMylKc+pvnkq8KMYGn00rjUvov9d7tAK7jiKYnC4WQ6vt+MWlGO3v/n8 cgQo2mTSMcZiDfQjHLLG+qX//sZGRzX12WrTMuFif3ti2TG8mPLOy2wUnYXUcP5W6Uc9 Jk4vuMZDk9SknUPiWVYUJDQ0PIFXZYVMsw1/ydYNT2S4UE6wnPyLBZbFeWY4reRqLGCj 6WEnnAg30gX3QNiZ37zlO+4ALaXFxuB9XVDufv1/q3G20zhA3/CQoJwqrO1KG4rJ4EIq FClQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=oAoJPFIBOAzw954Rrn9Q8rqGEIQHgf/TicNZDNCCP6M=; b=uN5XGuErP74qs0STgnLpDjGgJUXYNxZxcJlvhvbtsF6toMfUsdQhICfGU2FECLaf2I RM6uXDmd4lcLDfRDGYWqbMhLwVhZErxU98FkLVck4j/j02djPk0VEkuZGiiRGcvooA8q wfu+qvaA8Vs9uJgGF4QNaoV4E/UksC5NnhpKiVUqBVRcZnLsGG3FyCsAA/utHM2PxgcN kkBJg4wetXVV1pljjS1bu2AEBqycQk/5PGlWOAE/R9BekjPk9Eo9gnqC7zcyVftG7JFp bG0WC/qcjsrHB/UH70YNT5m/0cQ5p4OPPuTaC/BsBk5pMCmomQIclnP6oZLjZHBN67R+ YS+g== X-Gm-Message-State: AOAM530OkAuY2qLXAGTrYleGvWFHVK2GrcHWKmhGdSZA9ES/Hb3iw+FA M2uCa/moKLFsDrWmWBeIu0wUt+5zR9Y= X-Google-Smtp-Source: ABdhPJwAZ7vybSx5u2+7cdorj06E9sqhngWMNv/BcTdY76qBGqVbFBc9yqaONxPudV1h6grt7qE81A== X-Received: by 2002:a05:6000:18a4:: with SMTP id b4mr1106490wri.96.1631809315883; Thu, 16 Sep 2021 09:21:55 -0700 (PDT) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id e2sm4000318wra.40.2021.09.16.09.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 09:21:55 -0700 (PDT) Message-ID: From: Liliana Marie Prikler Date: Thu, 16 Sep 2021 18:21:54 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=1631810628; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=oAoJPFIBOAzw954Rrn9Q8rqGEIQHgf/TicNZDNCCP6M=; b=XJOdNFUDM1pfH0KHRCbH+lwqS8nsmlFv/rldlmkfYrDIKCJdKWY6k/5XqySuVoVuDw9diX EFpi1UkvEEAAZk3A1HWs7dlUsOxn5Z1FYbiK5o8sPva3Ep7wvwagOQWYpfrr1HGZxEjcMJ r4Wo71F15lewDJ8eS3cWe0FhI2vKmZr1dqRflATJmgnuFpiqUa/FwtftFcvS7auBKwXwXH P3xMrgVya1xr5aYnIv0X3uLf2jKLCfD3HocIzpdr518xN+GPzU0XGD2xXPv3y/dmTD7pxf 24DfjZ0QJuxEWa87A6CWwo7Jl4yVdEFgUOcGul/0CbqmG5ifnYmk1Sfvb31NfA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1631810628; a=rsa-sha256; cv=none; b=LWAVQJxs+DOrz3XB9N2b5s2xoyrzbofBpkdFHyRg+9uaNfKAEkHl0ig3JyihL4Dn0tCNq6 xD2wy1n5UEMN9EMjRvD70QlRanBhyMep18b79IK+7fgnf+MPLNVQD4FfaZpIdV1m7VwgHM 8IU+ku8oR3TNdoQCDWuSs5YJckMfM8MgMVfT5iIaqDbqGREblBBqODXzKih0F0JUP/S4SM gNO4YJ6MchwA1kT7F4itP0FsjxbPZLaPcpU5DtUpN2p+8tWpxt1gpASgRaxnMmBJ8EtOoR PSEZzGsNLzLN49iEO4nIMJEohNTc43fPcir4ozDjD1gmKLHTWp1KeCGUyzrYTg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=ddHbP3JN; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (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.20 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=ddHbP3JN; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (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: 77F7C1D99D X-Spam-Score: 0.20 X-Migadu-Scanner: scn1.migadu.com X-TUID: /jcXuA4Iz8Ch Hi, Am Donnerstag, den 16.09.2021, 09:11 +0200 schrieb Xinglu Chen: > * guix/build/utils.scm (optional): New syntax > * tests/build-utils.scm ("optional: expr1 is non-#f", optional: expr1 > is #f"): > Test it. > * guix.texi (Build Utilities): Document it. > --- > A common idiom I have seen is > > (if EXPR1 > EXPR2 > '()) > > with the ‘optional’ macro, one can just write > > (optional EXPR1 > EXPR2) > > I am not sure if ‘optional’ is the best name (it was inspired by > ‘lib.optional’ in Nixpkgs), feedback welcome! > > 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..1bb9ddb397 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -8801,6 +8801,41 @@ in a build phase of the @code{wireguard-tools} > package: > `("PATH" ":" prefix ,(list coreutils)))))) > @end lisp > > +@subsection Miscellaneous build utilities > + > +@cindex miscellaneous build utilities > +This section documents some miscellaneous utilities that are useful > to +have. > + > +@deffn {Scheme Syntax} optional @var{test} @var{consequent} > +Like @code{when} (@pxref{Conditionals,,, guile, GNU Guile Reference > +Manual}), but if @var{test} evaluates to false, return the empty > list. > +This is replaces the following idiom: > +@end deffn > + > +@lisp > +(if @var{test} > + @var{consequent} > + '()) > +@end lisp > + > +with this: > + > +@lisp > +(optional @var{test} > + @var{consequent}) > +@end lisp > + > +It can be useful when certain targets require an additional > configure > +flags, e.g., > + > +@lisp > +(arguments > + `(#:configure-flags (list "--localstatedir=/var" > + "--sysconfdir=/etc" > + ,@@(optional (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..ecf834461f 100644 > --- a/guix/build/utils.scm > +++ b/guix/build/utils.scm > @@ -8,6 +8,7 @@ > ;;; Copyright © 2020 Efraim Flashner > ;;; Copyright © 2020, 2021 Maxim Cournoyer < > maxim.cournoyer@gmail.com> > ;;; Copyright © 2021 Maxime Devos > +;;; Copyright © 2021 Xinglu Chen > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -123,7 +124,9 @@ > > make-desktop-entry-file > > - locale-category->string)) > + locale-category->string > + > + optional)) > > > ;;; > @@ -1613,6 +1616,18 @@ returned." > 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 optional > + (syntax-rules () > + ((_ expr1 expr2) > + (if expr1 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..44ad9bafc0 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 @@ print('hello world')")) > ("guile/bin" . ,(dirname (which "guile")))) > "guile")))) > > +(test-equal "optional: expr1 is non-#f" > + 'bar > + (optional 'foo 'bar)) > + > +(test-equal "optional: expr1 is #f" > + '() > + (optional #f 'bar)) > > (test-end) > > base-commit: 22f7d4bce1e694b7ac38e62410d76a6d46d96c5d Naming choice aside, I don't think I like the asymmetry behind having a plain symbol on the one side vs. an empty list. What about (list-if condition . rest), which evaluates to rest if condition is true and otherwise nil?