[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/22: packages: Define this-package-input and this-package-native-input
From: |
guix-commits |
Subject: |
05/22: packages: Define this-package-input and this-package-native-input. |
Date: |
Wed, 14 Jul 2021 13:20:48 -0400 (EDT) |
mothacehe pushed a commit to branch core-updates
in repository guix.
commit aaf9aa4824a8c30e5efc869d0e7dc34754892934
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Jul 14 13:12:50 2021 +0200
packages: Define this-package-input and this-package-native-input.
These macros are intended to be used in build phases.
More precisely, (assoc-ref %build-inputs "input") can be
replaced by #$(this-package-input "input") or #+(this-package-native-input
"native-input") as appropriate.
* guix/packages.scm
(package-input, package-native-input): New (unexported) procedures.
(this-package-input, this-package-native-input): New macros.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
---
guix/packages.scm | 29 +++++++++++++++++++++++++++++
tests/packages.scm | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/guix/packages.scm b/guix/packages.scm
index dfb4c68..d3fa72f 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -109,6 +109,9 @@
deprecated-package
package-field-location
+ this-package-input
+ this-package-native-input
+
lookup-package-input
lookup-package-native-input
lookup-package-propagated-input
@@ -547,6 +550,32 @@ object."
#f)))
(_ #f)))
+(define (package-input package name)
+ "Return the package input NAME of PACKAGE--i.e., an input
+from the ‘inputs’ or ‘propagated-inputs’ field. Native inputs are not
+considered. If this input does not exist, return #f instead."
+ (and=> (or (assoc-ref (package-inputs package) name)
+ (assoc-ref (package-propagated-inputs package) name))
+ car))
+
+(define (package-native-input package name)
+ "Return the native package input NAME of PACKAGE--i.e., an input
+from the ‘native-inputs’ field. If this native input does not exist,
+return #f instead."
+ (and=> (assoc-ref (package-native-inputs package) name)
+ car))
+
+(define-syntax-rule (this-package-input name)
+ "Return the input NAME of the package being defined--i.e., an input
+from the ‘inputs’ or ‘propagated-inputs’ field. Native inputs are not
+considered. If this input does not exist, return #f instead."
+ (package-input this-package name))
+
+(define-syntax-rule (this-package-native-input name)
+ "Return the native package input NAME of the package being defined--i.e.,
+an input from the ‘native-inputs’ field. If this native input does not
+exist, return #f instead."
+ (package-native-input this-package name))
;; Error conditions.
diff --git a/tests/packages.scm b/tests/packages.scm
index 9ec4dd1..2e1ca10 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021
Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -1864,6 +1865,39 @@
(package-location (specification->package "guile@2"))
(specification->location "guile@2"))
+(test-eq "this-package-input, exists"
+ hello
+ (package-arguments
+ (dummy-package "a"
+ (inputs `(("hello" ,hello)))
+ (arguments (this-package-input "hello")))))
+
+(test-eq "this-package-input, exists in propagated-inputs"
+ hello
+ (package-arguments
+ (dummy-package "a"
+ (propagated-inputs `(("hello" ,hello)))
+ (arguments (this-package-input "hello")))))
+
+(test-eq "this-package-input, does not exist"
+ #f
+ (package-arguments
+ (dummy-package "a"
+ (arguments (this-package-input "hello")))))
+
+(test-eq "this-package-native-input, exists"
+ hello
+ (package-arguments
+ (dummy-package "a"
+ (native-inputs `(("hello" ,hello)))
+ (arguments (this-package-native-input "hello")))))
+
+(test-eq "this-package-native-input, does not exists"
+ #f
+ (package-arguments
+ (dummy-package "a"
+ (arguments (this-package-native-input "hello")))))
+
(test-end "packages")
;;; Local Variables:
- branch core-updates updated (b4ccf3d -> 8456581), guix-commits, 2021/07/14
- 07/22: tzdata: Don't bother with cross-compiling., guix-commits, 2021/07/14
- 09/22: libgpg-error: Prevent silent miscompilation some systems., guix-commits, 2021/07/14
- 05/22: packages: Define this-package-input and this-package-native-input.,
guix-commits <=
- 02/22: utils: Define 'target-hurd?' predicate., guix-commits, 2021/07/14
- 06/22: net-base: Don't cross-compile., guix-commits, 2021/07/14
- 14/22: openssl: Use G-exp machinery for referring to outputs., guix-commits, 2021/07/14
- 20/22: glib: Look up "tzdata" in 'native-inputs', not 'inputs'., guix-commits, 2021/07/14
- 21/22: libelf: Update configure script and config.guess and config.sub., guix-commits, 2021/07/14
- 15/22: openssl: Move documentation instead of copying and deleting it., guix-commits, 2021/07/14
- 19/22: glib: Verify the cross-compiled python is used in installed scripts., guix-commits, 2021/07/14
- 16/22: openssl: Move all man pages to separate output, not only man3., guix-commits, 2021/07/14
- 04/22: utils: Define a target-x86-32? and target-x86-64? predicate., guix-commits, 2021/07/14
- 01/22: utils: Define 'target-linux?' predicate., guix-commits, 2021/07/14