all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Herman Rimm via Guix-patches via <guix-patches@gnu.org>
To: 70923@debbugs.gnu.org
Subject: [bug#70923] [PATCH v2 02/12] import: utils: Emit new-style inputs from maybe-*inputs procedures.
Date: Wed,  4 Sep 2024 22:32:56 +0200	[thread overview]
Message-ID: <20240904203309.23715-2-herman@rimm.ee> (raw)
In-Reply-To: <20240904203309.23715-1-herman@rimm.ee>

* guix/import/utils.scm (package-names->package-inputs)[make-input]:
Refactor.
(maybe-list-field): Add procedure, which wraps BODY in 'list' instead of
'quasiquote'.
(maybe-packages-field): Add procedure.
(maybe-inputs, maybe-native-inputs, maybe-propagated-inputs): Use
maybe-packages-field.

Change-Id: I66588f4c822d507ddbaf465a268bfb71af8a7ecd
---
 guix/import/utils.scm | 54 +++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index b7756fcc40..75bef1e9c7 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -13,6 +13,7 @@
 ;;; Copyright © 2022 Alice Brenon <alice.brenon@ens-lyon.fr>
 ;;; Copyright © 2022 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
+;;; Copyright © 2024 Herman Rimm <herman@rimm.ee>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -65,6 +66,8 @@ (define-module (guix import utils)
             guix-hash-url
 
             package-names->package-inputs
+            maybe-list-field
+            maybe-packages-field
             maybe-inputs
             maybe-native-inputs
             maybe-propagated-inputs
@@ -418,39 +421,44 @@ (define* (package-names->package-inputs names #:optional (output #f))
 optional OUTPUT, tries to generate a quoted list of inputs, as suitable to
 use in an 'inputs' field of a package definition."
   (define (make-input input version)
-    (let ((name (if version (string-append input "-" version) input)))
-      (if output
-          (list (string->symbol name) output)
-          (string->symbol name))))
+    (let ((symbol (string->symbol
+                    (if version
+                        (string-append input "-" version)
+                        input))))
+      (if output (list symbol output) symbol)))
 
   (map (match-lambda
          ((input version) (make-input input version))
          (input (make-input input #f)))
        names))
 
-(define* (maybe-inputs package-names #:optional (output #f)
-                       #:key (type #f))
-  "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a
-package definition.  TYPE can be used to specify the type of the inputs;
-either the 'native or 'propagated symbols are accepted.  Left unspecified, the
-snippet generated is for regular inputs."
-  (let ((field-name (match type
-                      ('native 'native-inputs)
-                      ('propagated 'propagated-inputs)
-                      (_ 'inputs))))
-    (match (package-names->package-inputs package-names output)
-      (()
-       '())
-      ((package-inputs ...)
-       `((,field-name (list ,@package-inputs)))))))
+(define* (maybe-list-field type body)
+  "Generates the TYPE field of a package definition if its value, BODY,
+is a non-empty list."
+  (match body
+    (()
+     '())
+    ((? list?)
+     (list (list type (cons 'list body))))))
+
+(define* (maybe-packages-field type package-names
+                               #:optional (output #f))
+  "Given a list of PACKAGE-NAMES, tries to generate the TYPE field of a
+package definition."
+  (maybe-list-field type
+    (package-names->package-inputs package-names output)))
+
+(define* (maybe-inputs package-names #:optional (output #f))
+  "MAYBE-PACKAGES-FIELD for inputs."
+  (maybe-packages-field 'inputs package-names output))
 
 (define* (maybe-native-inputs package-names #:optional (output #f))
-  "Same as MAYBE-INPUTS, but for native inputs."
-  (maybe-inputs package-names output #:type 'native))
+  "MAYBE-PACKAGES-FIELD for native inputs."
+  (maybe-packages-field 'native-inputs package-names output))
 
 (define* (maybe-propagated-inputs package-names #:optional (output #f))
-  "Same as MAYBE-INPUTS, but for propagated inputs."
-  (maybe-inputs package-names output #:type 'propagated))
+  "MAYBE-PACKAGES-FIELD for propagated inputs."
+  (maybe-packages-field 'propagated-inputs package-names output))
 
 (define* (package->definition guix-package #:optional append-version?/string)
   "If APPEND-VERSION?/STRING is #t, append the package's major+minor version.
-- 
2.45.2





  reply	other threads:[~2024-09-04 20:35 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-13 19:59 [bug#70923] [PATCH 00/13] Add (guix import utils) procedures Herman Rimm via Guix-patches via
2024-05-13 20:07 ` [bug#70923] [PATCH 01/13] build-system: cargo: Accept unlabeled #:cargo-inputs Herman Rimm via Guix-patches via
2024-05-13 20:07 ` [bug#70923] [PATCH 02/13] import: utils: Emit new-style package inputs Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 03/13] tests: go: Adjust to " Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 04/13] tests: elm: " Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 05/13] import: crate: Emit " Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 06/13] import: utils: Add 'maybe-upstream-inputs' procedure Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 07/13] import: pypi: Use 'maybe-list-field' procedure Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 08/13] import: elpa: Use maybe-propagated-inputs procedure Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 09/13] import: hackage: Use 'maybe-list-field' procedure Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 10/13] import: cran: " Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 11/13] import: cpan: Use 'maybe-upstream-inputs' procedure Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 12/13] import: egg: Use maybe-*inputs procedures Herman Rimm via Guix-patches via
2024-05-13 20:08 ` [bug#70923] [PATCH 13/13] import: hexpm: Use (guix import utils) 'maybe-inputs' procedure Herman Rimm via Guix-patches via
2024-09-04 20:32 ` [bug#70923] [PATCH v2 01/12] build-system: cargo: Accept unlabeled #:cargo-inputs Herman Rimm via Guix-patches via
2024-09-04 20:32   ` Herman Rimm via Guix-patches via [this message]
2024-09-04 20:32   ` [bug#70923] [PATCH v2 03/12] tests: elm: Adjust to new-style package inputs Herman Rimm via Guix-patches via
2024-09-04 20:32   ` [bug#70923] [PATCH v2 04/12] import: crate: Use (guix import utils) procedures Herman Rimm via Guix-patches via
2024-09-04 20:32   ` [bug#70923] [PATCH v2 05/12] import: utils: Add maybe-upstream-inputs Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 06/12] import: pypi: Use maybe-upstream-inputs Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 07/12] import: elpa: Use maybe-propagated-inputse Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 08/12] import: hackage: Use maybe-list-field Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 09/12] import: cran: Refactor format-inputs and use maybe-list-field Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 10/12] import: cpan: Use maybe-upstream-inputs Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 11/12] import: egg: Use maybe-*inputs procedures Herman Rimm via Guix-patches via
2024-09-04 20:33   ` [bug#70923] [PATCH v2 12/12] import: hexpm: Use maybe-inputs Herman Rimm via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240904203309.23715-2-herman@rimm.ee \
    --to=guix-patches@gnu.org \
    --cc=70923@debbugs.gnu.org \
    --cc=herman@rimm.ee \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.