guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/05: environment: Move iteration outside of 'for-each-search-path'.


From: Ludovic Courtès
Subject: 05/05: environment: Move iteration outside of 'for-each-search-path'.
Date: Tue, 05 May 2015 13:14:15 +0000

civodul pushed a commit to branch master
in repository guix.

commit 8e3a3bc290cf5de266979fdf9abb87891de4f0ab
Author: Ludovic Courtès <address@hidden>
Date:   Tue May 5 15:02:35 2015 +0200

    environment: Move iteration outside of 'for-each-search-path'.
    
    * guix/search-paths.scm (search-path-definition): New procedure.
    * guix/scripts/environment.scm (for-each-search-path): Rename to...
      (evaluate-input-search-paths): ... this.  Remove 'proc' and 'pure?'
      parameters, and return directly the list of search-path/value pairs.
      (create-environment): Use 'for-each' and 'evaluate-input-search-paths'
      instead of 'for-each-search-path'.
      (show-search-paths): Use 'for-each', 'search-path-definition', and
      'evaluate-search-paths' instead of 'for-each-search-path'.
---
 guix/scripts/environment.scm |   36 +++++++++++++++++++-----------------
 guix/search-paths.scm        |   15 +++++++++++++--
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index cf402d3..e81532c 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -36,11 +36,9 @@
   #:use-module (srfi srfi-98)
   #:export (guix-environment))
 
-(define (for-each-search-path proc inputs derivations pure?)
-  "Apply PROC for each native search path in INPUTS in addition to 'PATH'.
-Use the output paths of DERIVATIONS to build each search path.  When PURE? is
-#t, the existing search path value is ignored.  Otherwise, the existing search
-path value is appended."
+(define (evaluate-input-search-paths inputs derivations)
+  "Evaluate the native search paths of INPUTS, a list of packages, of the
+outputs of DERIVATIONS, and return a list of search-path/value pairs."
   (let ((directories (append-map (lambda (drv)
                                    (map (match-lambda
                                           ((_ . output)
@@ -51,14 +49,7 @@ path value is appended."
                            (delete-duplicates
                             (append-map package-native-search-paths
                                         inputs)))))
-    (for-each (match-lambda
-                ((($ <search-path-specification> variable _ sep) . value)
-                 (let ((current  (getenv variable)))
-                   (proc variable
-                         (if (and current (not pure?))
-                             (string-append value sep current)
-                             value)))))
-              (evaluate-search-paths paths directories))))
+    (evaluate-search-paths paths directories)))
 
 ;; Protect some env vars from purification.  Borrowed from nix-shell.
 (define %precious-variables
@@ -78,15 +69,26 @@ as 'HOME' and 'USER' are left untouched."
 PURE? is #t, unset the variables in the current environment.  Otherwise,
 augment existing enviroment variables with additional search paths."
   (when pure? (purify-environment))
-  (for-each-search-path setenv inputs derivations pure?))
+  (for-each (match-lambda
+              ((($ <search-path-specification> variable _ separator) . value)
+               (let ((current (getenv variable)))
+                 (setenv variable
+                         (if (and current (not pure?))
+                             (string-append value separator current)
+                             value)))))
+            (evaluate-input-search-paths inputs derivations)))
 
 (define (show-search-paths inputs derivations pure?)
   "Display the needed search paths to build an environment that contains the
 packages within INPUTS.  When PURE? is #t, do not augment existing environment
 variables with additional search paths."
-  (for-each-search-path (lambda (variable value)
-                          (format #t "export ~a=\"~a\"~%" variable value))
-                        inputs derivations pure?))
+  (for-each (match-lambda
+              ((search-path . value)
+               (display
+                (search-path-definition search-path value
+                                        #:kind (if pure? 'exact 'prefix)))
+               (newline)))
+            (evaluate-input-search-paths inputs derivations)))
 
 (define (show-help)
   (display (_ "Usage: guix environment [OPTION]... PACKAGE...
diff --git a/guix/search-paths.scm b/guix/search-paths.scm
index 89af1e1..ee7e9a1 100644
--- a/guix/search-paths.scm
+++ b/guix/search-paths.scm
@@ -36,7 +36,8 @@
             search-path-specification->sexp
             sexp->search-path-specification
             evaluate-search-paths
-            environment-variable-definition))
+            environment-variable-definition
+            search-path-definition))
 
 ;;; Commentary:
 ;;;
@@ -160,7 +161,7 @@ report only settings not already effective."
                                           #:key
                                           (kind 'exact)
                                           (separator ":"))
-  "Return a the definition of VARIABLE to VALUE in Bash syntax:
+  "Return a the definition of VARIABLE to VALUE in Bash syntax.
 
 KIND can be either 'exact (return the definition of VARIABLE=VALUE),
 'prefix (return the definition where VALUE is added as a prefix to VARIABLE's
@@ -178,4 +179,14 @@ prefix/suffix."
      (format #f "export ~a=\"$~a${~a:+~a}~a\""
              variable variable variable separator value))))
 
+(define* (search-path-definition search-path value
+                                 #:key (kind 'exact))
+  "Similar to 'environment-variable-definition', but applied to a
+<search-path-specification>."
+  (match search-path
+    (($ <search-path-specification> variable _ separator)
+     (environment-variable-definition variable value
+                                      #:kind kind
+                                      #:separator separator))))
+
 ;;; search-paths.scm ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]