[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#49169] [PATCH v2 04/16] packages: Add 'lookup-package-input' & co.
From: |
Ludovic Courtès |
Subject: |
[bug#49169] [PATCH v2 04/16] packages: Add 'lookup-package-input' & co. |
Date: |
Wed, 30 Jun 2021 22:48:20 +0200 |
* guix/packages.scm (lookup-input, lookup-package-input)
(lookup-package-native-input, lookup-package-propagated-input)
(lookup-package-direct-input): New procedures.
* doc/guix.texi (package Reference): Document them.
---
doc/guix.texi | 24 ++++++++++++++++++++++++
guix/packages.scm | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/doc/guix.texi b/doc/guix.texi
index 0e5d1a9fa7..d88f857c3a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6817,6 +6817,30 @@ cross-compiling:
It is an error to refer to @code{this-package} outside a package definition.
@end deffn
+The following helper procedures are provided to help deal with package
+inputs.
+
+@deffn {Scheme Procedure} lookup-package-input @var{package} @var{name}
+@deffnx {Scheme Procedure} lookup-package-native-input @var{package} @var{name}
+@deffnx {Scheme Procedure} lookup-package-propagated-input @var{package}
@var{name}
+@deffnx {Scheme Procedure} lookup-package-direct-input @var{package} @var{name}
+Look up @var{name} among @var{package}'s inputs (or native, propagated,
+or direct inputs). Return it if found, @code{#f} otherwise.
+
+@var{name} is the name of a package depended on. Here's how you might
+use it:
+
+@lisp
+(use-modules (guix packages) (gnu packages base))
+
+(lookup-package-direct-input coreutils "gmp")
+@result{} #<package gmp@@6.2.1 @dots{}>
+@end lisp
+
+In this example we obtain the @code{gmp} package that is among the
+direct inputs of @code{coreutils}.
+@end deffn
+
Because packages are regular Scheme objects that capture a complete
dependency graph and associated build procedures, it is often useful to
write procedures that take a package and return a modified version
diff --git a/guix/packages.scm b/guix/packages.scm
index 087e6e6a4a..c845026827 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -108,6 +108,11 @@
deprecated-package
package-field-location
+ lookup-package-input
+ lookup-package-native-input
+ lookup-package-propagated-input
+ lookup-package-direct-input
+
package-direct-sources
package-transitive-sources
package-direct-inputs
@@ -889,6 +894,35 @@ preserved, and only duplicate propagated inputs are
removed."
((input rest ...)
(loop rest (cons input result) propagated first? seen)))))
+(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)))
+
+(define (lookup-package-input package name)
+ "Look up NAME among PACKAGE's inputs. Return it if found, #f otherwise."
+ (lookup-input (package-inputs package) name))
+
+(define (lookup-package-native-input package name)
+ "Look up NAME among PACKAGE's native inputs. Return it if found, #f
+otherwise."
+ (lookup-input (package-native-inputs package) name))
+
+(define (lookup-package-propagated-input package name)
+ "Look up NAME among PACKAGE's propagated inputs. Return it if found, #f
+otherwise."
+ (lookup-input (package-propagated-inputs package) name))
+
+(define (lookup-package-direct-input package name)
+ "Look up NAME among PACKAGE's direct inputs. Return it if found, #f
+otherwise."
+ (lookup-input (package-direct-inputs package) name))
+
(define (package-direct-sources package)
"Return all source origins associated with PACKAGE; including origins in
PACKAGE's inputs."
--
2.32.0
- [bug#49169] [PATCH 10/11] utils: 'edit-expression' copies part of the original source map., (continued)
- [bug#49169] [PATCH 00/11] Removing input labels from package definitions, Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 00/11] Removing input labels from package definitions, Ludovic Courtès, 2021/06/27
- [bug#49169] [PATCH v2 00/16] Removing input labels from package definitions, Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 01/16] records: Support field sanitizers., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 03/16] lint: Add 'input-labels' checker., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 02/16] packages: Allow inputs to be plain package lists., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 04/16] packages: Add 'lookup-package-input' & co.,
Ludovic Courtès <=
- [bug#49169] [PATCH v2 05/16] packages: Add 'modify-inputs'., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 07/16] utils: 'edit-expression' no longer leaks file ports., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 06/16] gnu: Change inputs of core packages to plain lists., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 10/16] utils: 'edit-expression' copies part of the original source map., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 12/16] packages: 'hidden-package' inherits the original package location., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 13/16] import: pypi: Emit new-style package inputs., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 14/16] import: cran: Emit new-style package inputs., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 15/16] import: print: Emit new-style package inputs when possible., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 08/16] utils: Add 'go-to-location' with source location caching., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 09/16] utils: 'edit-expression' modifies the file only if necessary., Ludovic Courtès, 2021/06/30