summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-06-06 23:00:05 +0200
committerLudovic Courtès <ludo@gnu.org>2020-06-06 23:28:49 +0200
commitd67a88196607b57ce1209464b03b79d2a74bf5cd (patch)
treef274c092ddc968c58c4c129966ba3a43eeaa7cdc
parentb2ee53d5aead4e2c49f526c8ddcf5a279e879236 (diff)
downloadguix-d67a88196607b57ce1209464b03b79d2a74bf5cd.tar.gz
utils: Add 'with-environment-variables'.
* guix/tests/gnupg.scm (call-with-environment-variables)
(with-environment-variables): Move to...
* guix/utils.scm: ... here.
* guix/tests/git.scm: Adjust accordingly.
-rw-r--r--guix/tests/git.scm1
-rw-r--r--guix/tests/gnupg.scm22
-rw-r--r--guix/utils.scm50
3 files changed, 41 insertions, 32 deletions
diff --git a/guix/tests/git.scm b/guix/tests/git.scm
index c77c544e03..5d7056bb53 100644
--- a/guix/tests/git.scm
+++ b/guix/tests/git.scm
@@ -21,7 +21,6 @@
   #:use-module ((guix git) #:select (with-repository))
   #:use-module (guix utils)
   #:use-module (guix build utils)
-  #:use-module ((guix tests gnupg) #:select (with-environment-variables))
   #:use-module (ice-9 match)
   #:use-module (ice-9 control)
   #:export (git-command
diff --git a/guix/tests/gnupg.scm b/guix/tests/gnupg.scm
index 6e7fdbcf65..47c858d232 100644
--- a/guix/tests/gnupg.scm
+++ b/guix/tests/gnupg.scm
@@ -22,27 +22,7 @@
   #:use-module (ice-9 match)
   #:export (gpg-command
             gpgconf-command
-            with-fresh-gnupg-setup
-
-            with-environment-variables))
-
-(define (call-with-environment-variables variables thunk)
-  "Call THUNK with the environment VARIABLES set."
-  (let ((environment (environ)))
-    (dynamic-wind
-      (lambda ()
-        (for-each (match-lambda
-                    ((variable value)
-                     (setenv variable value)))
-                  variables))
-      thunk
-      (lambda ()
-        (environ environment)))))
-
-(define-syntax-rule (with-environment-variables variables exp ...)
-  "Evaluate EXP with the given environment VARIABLES set."
-  (call-with-environment-variables variables
-                                   (lambda () exp ...)))
+            with-fresh-gnupg-setup))
 
 (define gpg-command
   (make-parameter "gpg"))
diff --git a/guix/utils.scm b/guix/utils.scm
index 69e3f0a934..17a96370f1 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -89,7 +89,6 @@
             guile-version>?
             version-prefix?
             string-replace-substring
-            arguments-from-environment-variable
             file-extension
             file-sans-extension
             tarball-sans-extension
@@ -99,6 +98,9 @@
             call-with-temporary-directory
             with-atomic-file-output
 
+            with-environment-variables
+            arguments-from-environment-variable
+
             config-directory
             cache-directory
 
@@ -115,6 +117,38 @@
 
 
 ;;;
+;;; Environment variables.
+;;;
+
+(define (call-with-environment-variables variables thunk)
+  "Call THUNK with the environment VARIABLES set."
+  (let ((environment (environ)))
+    (dynamic-wind
+      (lambda ()
+        (for-each (match-lambda
+                    ((variable value)
+                     (setenv variable value)))
+                  variables))
+      thunk
+      (lambda ()
+        (environ environment)))))
+
+(define-syntax-rule (with-environment-variables variables exp ...)
+  "Evaluate EXP with the given environment VARIABLES set."
+  (call-with-environment-variables variables
+                                   (lambda () exp ...)))
+
+(define (arguments-from-environment-variable variable)
+  "Retrieve value of environment variable denoted by string VARIABLE in the
+form of a list of strings (`char-set:graphic' tokens) suitable for consumption
+by `args-fold', if VARIABLE is defined, otherwise return an empty list."
+  (let ((env (getenv variable)))
+    (if env
+        (string-tokenize env char-set:graphic)
+        '())))
+
+
+;;;
 ;;; Filtering & pipes.
 ;;;
 
@@ -582,6 +616,11 @@ minor version numbers from version-string."
       (list-prefix? (string-tokenize v1 not-dot)
                     (string-tokenize v2 not-dot)))))
 
+
+;;;
+;;; Files.
+;;;
+
 (define (file-extension file)
   "Return the extension of FILE or #f if there is none."
   (let ((dot (string-rindex file #\.)))
@@ -634,15 +673,6 @@ REPLACEMENT."
                        (substring str start index)
                        pieces))))))))
 
-(define (arguments-from-environment-variable variable)
-  "Retrieve value of environment variable denoted by string VARIABLE in the
-form of a list of strings (`char-set:graphic' tokens) suitable for consumption
-by `args-fold', if VARIABLE is defined, otherwise return an empty list."
-  (let ((env (getenv variable)))
-    (if env
-        (string-tokenize env char-set:graphic)
-        '())))
-
 (define (call-with-temporary-output-file proc)
   "Call PROC with a name of a temporary file and open output port to that
 file; close the file and delete it when leaving the dynamic extent of this