From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id oBtdBVHahGT4kQAASxT56A (envelope-from ) for ; Sat, 10 Jun 2023 22:17:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id KJtLBVHahGTkMQAAauVa8A (envelope-from ) for ; Sat, 10 Jun 2023 22:17:21 +0200 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 B853446E4C for ; Sat, 10 Jun 2023 22:17:20 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q851E-0000VY-TG; Sat, 10 Jun 2023 16:17:04 -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 1q851D-0000VL-8o for guix-patches@gnu.org; Sat, 10 Jun 2023 16:17: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 1q851D-0005vy-0g for guix-patches@gnu.org; Sat, 10 Jun 2023 16:17:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q851C-0006xl-S5 for guix-patches@gnu.org; Sat, 10 Jun 2023 16:17:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63985] [PATCH RFC v2 2/5] services: configuration: Use transducers within serialize-configuration. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 10 Jun 2023 20:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63985 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63985@debbugs.gnu.org Cc: Bruno Victal Received: via spool by 63985-submit@debbugs.gnu.org id=B63985.168642822226757 (code B ref 63985); Sat, 10 Jun 2023 20:17:02 +0000 Received: (at 63985) by debbugs.gnu.org; 10 Jun 2023 20:17:02 +0000 Received: from localhost ([127.0.0.1]:36378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q851B-0006xR-Bc for submit@debbugs.gnu.org; Sat, 10 Jun 2023 16:17:01 -0400 Received: from smtpm1.myservices.hosting ([185.26.105.232]:58258) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q8519-0006xA-5V for 63985@debbugs.gnu.org; Sat, 10 Jun 2023 16:16:59 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpm1.myservices.hosting (Postfix) with ESMTP id B3D1220A4A for <63985@debbugs.gnu.org>; Sat, 10 Jun 2023 22:16:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 0111480097; Sat, 10 Jun 2023 22:11:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-2.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id z3ZtGnCiAB1i; Sat, 10 Jun 2023 22:11:17 +0200 (CEST) Received: from guix-nuc.home.arpa (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 7839780060; Sat, 10 Jun 2023 22:11:17 +0200 (CEST) From: Bruno Victal Date: Sat, 10 Jun 2023 21:10:53 +0100 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1686428240; a=rsa-sha256; cv=none; b=fcwzv5+WZzAtK1WNYrlqFvFnTOw2Xc9jV2/FVpnUCC89wYiUhqLzdSKJ9bZg/CGy1slmwE t1Zn1jjSkW22UKsdfqO5qy77Sl62mcS8L6QoW0qZbUPi1YaKERm3rPLvpLUGgUXAeLSJmx jfhi9uGJgC+MW9OFJAxia3yDkLTUbC/aTcEuvuUgkOW9faUGk83VfKLIv/xCD8vknscfEl G1zDJW4tHTmVCzNUJogbewuLWOOdM1yhdqqlWFg0uVCXNZonmcRwihyxYNFTFd2wQFf4Je YXhMT2MKTVmk31tkU/bQDAW276og0w5iOUqa/uELtoXWnMg2V5JOfwedajfRCg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1686428240; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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; bh=hpeaMZbSSUB09ObR1W8cO09FQcr8Db6g1LfLIk2zdgU=; b=T+gNMfX2AnRujC+5Q6bIGY2Taf1p8FEppOTwyh5W4p1g9zLz4kZLUX3+gbFGINcdF0fZIo pzcTQQnXA+zRPdfwN51+WZrNM7VRCuLXIwbGuzVz9Is+A8KQRPhnnd/rW1RfPDJq7R6K0U cpxhfIVtAzKAFF0EV+4Eo9tZIbyyc8c2cKukZ4qPSui4eWTpKpI8X5Qme7APVaqZpweyTP 1ygqF+64MtjZkNKHKqUd1wLUjg2oBsST8z+wsoeYRy2YpEiF9B6CqnZCDz7UzmUG7ldntg xShN3SJHa8uOl9AzwI+PTqYmzy4qQwV1hK0a/+vC1pBvsj2pmuGTanIMQwRGiA== Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -2.21 X-Spam-Score: -2.21 X-Migadu-Queue-Id: B853446E4C X-TUID: VFKzjgSViKTM Introduces 'base-transducer', a SRFI-171 based transducer that can be used as a starting point for writing custom configuration record serializing procedures. This also fixes the symbol maybe-value serialization test case. * gnu/services/configuration.scm (empty-serializer?): New predicate. (base-transducer, tfilter-maybe-value): New procedure. (serialize-configuration): Adapt to use base-transducer. * gnu/services/telephony.scm (jami-account->alist): Use transducers to skip fields that are unserializable or whose field maybe-value is unset. * tests/services/configuration.scm: Remove test-expect-fail. --- gnu/services/configuration.scm | 29 ++++++++++++++++++++++++----- gnu/services/telephony.scm | 27 +++++++++++++-------------- tests/services/configuration.scm | 4 ---- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index dafe72f4fe..cd2cb8318b 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -42,6 +42,7 @@ (define-module (gnu services configuration) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:use-module (srfi srfi-171) #:export (configuration-field configuration-field-name configuration-field-type @@ -59,6 +60,10 @@ (define-module (gnu services configuration) define-configuration/no-serialization no-serialization + empty-serializer? + tfilter-maybe-value + base-transducer + serialize-configuration define-maybe define-maybe/no-serialization @@ -125,13 +130,27 @@ (define-record-type* (default-value-thunk configuration-field-default-value-thunk) (documentation configuration-field-documentation)) +(define (empty-serializer? field) + (eq? empty-serializer + (configuration-field-serializer field))) + +(define (tfilter-maybe-value config) + (tfilter (lambda (field) + (let ((field-value ((configuration-field-getter field) config))) + (maybe-value-set? field-value))))) + +(define (base-transducer config) + (compose (tremove empty-serializer?) + ;; Only serialize fields whose value isn't '%unset-marker%. + (tfilter-maybe-value config) + (tmap (lambda (field) + ((configuration-field-serializer field) + (configuration-field-name field) + ((configuration-field-getter field) config)))))) + (define (serialize-configuration config fields) #~(string-append - #$@(map (lambda (field) - ((configuration-field-serializer field) - (configuration-field-name field) - ((configuration-field-getter field) config))) - fields))) + #$@(list-transduce (base-transducer config) rcons fields))) (define-syntax-rule (id ctx parts ...) "Assemble PARTS into a raw (unhygienic) identifier." diff --git a/gnu/services/telephony.scm b/gnu/services/telephony.scm index 23ccb8d403..56b7772f58 100644 --- a/gnu/services/telephony.scm +++ b/gnu/services/telephony.scm @@ -37,6 +37,7 @@ (define-module (gnu services telephony) #:use-module (srfi srfi-1) #:use-module (srfi srfi-2) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-171) #:use-module (ice-9 format) #:use-module (ice-9 match) #:export (jami-account @@ -204,22 +205,20 @@ (define (jami-account->alist jami-account-object) ('rendezvous-point? "Account.rendezVous") ('peer-discovery? "Account.peerDiscovery") ('bootstrap-hostnames "Account.hostname") - ('name-server-uri "RingNS.uri") - (_ #f))) + ('name-server-uri "RingNS.uri"))) - (filter-map (lambda (field) - (and-let* ((name (field-name->account-detail + (define jami-account-transducer + (compose (tremove empty-serializer?) + (tfilter-maybe-value jami-account-object) + (tmap (lambda (field) + (let* ((name (field-name->account-detail (configuration-field-name field))) - (value ((configuration-field-serializer field) - name ((configuration-field-getter field) - jami-account-object))) - ;; The define-maybe default serializer produces an - ;; empty string for unspecified values. - (value* (if (string-null? value) - #f - value))) - (cons name value*))) - jami-account-fields)) + (value ((configuration-field-serializer field) + name ((configuration-field-getter field) + jami-account-object)))) + (cons name value)))))) + + (list-transduce jami-account-transducer rcons jami-account-fields)) (define (jami-account-list? val) (and (list? val) diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm index 8ad5907f37..1db83bb273 100644 --- a/tests/services/configuration.scm +++ b/tests/services/configuration.scm @@ -337,10 +337,6 @@ (define-maybe symbol) (define-configuration config-with-maybe-symbol (protocol maybe-symbol "")) -;;; Maybe symbol values are currently seen as serializable, because the -;;; unspecified value is '%unset-marker%, which is a symbol itself. -;;; TODO: Remove expected fail marker after resolution. -(test-expect-fail 1) (test-equal "symbol maybe value serialization, unspecified" "" (gexp->approximate-sexp -- 2.39.2