From: Hilton Chain via Guix-patches via <guix-patches@gnu.org>
To: 65062@debbugs.gnu.org
Cc: "Hilton Chain" <hako@ultrarare.space>,
"Hilton Chain" <hako@ultrarare.space>,
"Ludovic Courtès" <ludo@gnu.org>,
"Josselin Poiret" <dev@jpoiret.xyz>,
"Christopher Baines" <guix@cbaines.net>,
"Mathieu Othacehe" <othacehe@gnu.org>,
"Ricardo Wurmus" <rekado@elephly.net>,
"Simon Tournier" <zimon.toutoune@gmail.com>,
"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification.
Date: Tue, 3 Oct 2023 17:17:02 +0800 [thread overview]
Message-ID: <dac85ddb4c5637ab522b4b37f926f00af567cc33.1696323536.git.hako@ultrarare.space> (raw)
In-Reply-To: <cover.1696323536.git.hako@ultrarare.space>
* guix/packages.scm (specification->inputs): New procedure.
(lookup-input,replace-input): Use it.
(delete-input): New procedure.
(modify-inputs)[delete]: Use it.
---
guix/packages.scm | 72 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 57 insertions(+), 15 deletions(-)
diff --git a/guix/packages.scm b/guix/packages.scm
index b004882cc6..45552bfb7f 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -1173,15 +1173,49 @@ (define (transitive-inputs inputs)
((input rest ...)
(loop rest (cons input result) propagated first? seen)))))
+(define (specification->inputs spec inputs)
+ "Lookup inputs specified by SPEC among INPUTS, an input list. Return an input
+list consists of all matching inputs, or '(). SPEC may be a package name,
+optionally containing a version number or an output name, as in these examples:
+
+ guile
+ guile@2.0.9
+ guile:debug
+ guile@2.0.9:debug
+
+If SPEC does not specify a version number, all versions are matched; if SPEC
+does not specify an output, all outputs are matched.
+
+SPEC can be an input label as well."
+ (let ((name version sub-drv
+ (package-specification->name+version+output spec #f)))
+ (filter-map
+ (lambda (input)
+ (match input
+ (((? string? label) (? package? package) . outputs)
+ (and (or (and (string=? name (package-name package))
+ (when version
+ (string-prefix? version (package-version package)))
+ (when sub-drv
+ (and (not (null? outputs))
+ (string=? sub-drv (first outputs)))))
+ ;; fallback to input label
+ (string=? label spec))
+ input))
+ ;; not a package
+ (((? string? label) _ . _)
+ (and (string=? label spec)
+ input))))
+ inputs)))
+
(define (lookup-input inputs name)
"Lookup NAME among INPUTS, an input list."
;; Note: Currently INPUTS is assumed to be an input list that contains input
;; labels. In the future, input labels will be gone and this procedure will
;; check package names.
- (match (assoc-ref inputs name)
- ((obj) obj)
- ((obj _) obj)
- (#f #f)))
+ (let ((candidates (specification->inputs name inputs)))
+ (and (not (null? candidates))
+ (second (first candidates)))))
(define (lookup-package-input package name)
"Look up NAME among PACKAGE's inputs. Return it if found, #f otherwise."
@@ -1202,17 +1236,25 @@ (define (lookup-package-direct-input package name)
otherwise."
(lookup-input (package-direct-inputs package) name))
+(define (delete-input name inputs)
+ "Delete input NAME within INPUTS."
+ (let ((to-delete (specification->inputs name inputs)))
+ (lset-difference equal? inputs to-delete)))
+
(define (replace-input name replacement inputs)
"Replace input NAME by REPLACEMENT within INPUTS."
- (map (lambda (input)
- (match input
- (((? string? label) _ . outputs)
- (if (string=? label name)
- (match replacement ;does REPLACEMENT specify an output?
- ((_ _) (cons label replacement))
- (_ (cons* label replacement outputs)))
- input))))
- inputs))
+ (let ((to-replace (specification->inputs name inputs)))
+ (append
+ (lset-difference equal? inputs to-replace)
+ (if (null? to-replace)
+ '()
+ (map (lambda (input)
+ (match input
+ ((label _ . outputs)
+ (match replacement ;does REPLACEMENT specify an output?
+ ((_ _) (cons label replacement))
+ (_ (cons* label replacement outputs))))))
+ to-replace)))))
(define-syntax prepend
(lambda (s)
@@ -1244,10 +1286,10 @@ (define-syntax modify-inputs
;; 'package-inputs' & co., is actually an alist with labels. Eventually,
;; it will operate on list of inputs without labels.
((_ inputs (delete name) clauses ...)
- (modify-inputs (alist-delete name inputs)
+ (modify-inputs (delete-input name inputs)
clauses ...))
((_ inputs (delete names ...) clauses ...)
- (modify-inputs (fold alist-delete inputs (list names ...))
+ (modify-inputs (fold delete-input inputs (list names ...))
clauses ...))
((_ inputs (prepend lst ...) clauses ...)
(modify-inputs (append (map add-input-label (list lst ...)) inputs)
--
2.41.0
next prev parent reply other threads:[~2023-10-03 9:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-05 2:50 [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out" Hilton Chain via Guix-patches via
2023-08-05 2:53 ` [bug#65062] [PATCH core-updates 1/1] packages: " Hilton Chain via Guix-patches via
2023-08-22 16:00 ` Ludovic Courtès
2023-08-24 3:42 ` Hilton Chain via Guix-patches via
2023-08-25 11:10 ` Josselin Poiret via Guix-patches via
2023-09-08 22:03 ` Ludovic Courtès
2023-10-03 9:13 ` Hilton Chain via Guix-patches via
2023-08-05 3:01 ` [bug#65062] [PATCH core-updates 0/1] " Hilton Chain via Guix-patches via
2023-08-05 3:19 ` Hilton Chain via Guix-patches via
2023-10-03 9:15 ` [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
2023-10-03 9:17 ` [bug#65062] [PATCH v2 core-updates 1/2] ui: package-specification->name+version+output: Move to (guix packages) Hilton Chain via Guix-patches via
2023-10-03 9:17 ` Hilton Chain via Guix-patches via [this message]
2023-12-20 21:26 ` [bug#65062] [PATCH core-updates] packages: Lookup inputs by specification Ludovic Courtès
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=dac85ddb4c5637ab522b4b37f926f00af567cc33.1696323536.git.hako@ultrarare.space \
--to=guix-patches@gnu.org \
--cc=65062@debbugs.gnu.org \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=hako@ultrarare.space \
--cc=ludo@gnu.org \
--cc=me@tobias.gr \
--cc=othacehe@gnu.org \
--cc=rekado@elephly.net \
--cc=zimon.toutoune@gmail.com \
/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.