diff mbox

[1/3] build/utils: Add `wrap-language-programs`.

Message ID 20161116132734.5943-2-alex@pompo.co
State New
Headers show

Commit Message

Alex Sassmannshausen Nov. 16, 2016, 1:27 p.m. UTC
* guix/build/utils.scm (wrap-language-programs): New procedure.
---
 guix/build/utils.scm | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Ludovic Courtès Nov. 18, 2016, 11:07 p.m. UTC | #1
Hey!

Alex Sassmannshausen <alex.sassmannshausen@gmail.com> skribis:

> * guix/build/utils.scm (wrap-language-programs): New procedure.

Neat!

> +(define (wrap-language-programs path-proc env-var)

Maybe ‘program-wrapper’ or ‘program-wrapping-procedure’ or
‘program-wrapping-phase’ to suggest that it returns a procedure?  (I’m
not sure “language” is helpful.)

> +  "Return a procedure, which, invoked as part of a `wrap' phase, is capable of
> +wrapping executables inside an environment in which ENV-VAR is correctly set.
> +
> +The string ENV-VAR is the name of the environmental variable we are setting
> +for the executable we are wrapping.  PATH-PROC is a procedure of 2 arguments,
> +`inputs' and `outputs', returning the value that we should send ENV-VAR to.
> +
> +This is a specialized version of `wrap-program' below, intended specifically
> +to grant all executables that are part of our output access to all libraries
> +that were declared in our inputs.  This is of use for languages such as Perl,
> +Python and Guile."

Nitpick: the GCS now recommend straight quotes in ASCII, like 'this'.
:-)

Otherwise this and the 2 subsequent patches LGTM.

Could you make sure that the resulting wrapper is the same, either by
rebuilding one way or another as discussed earlier, or by running the
code “by hand” on an example, maybe in ‘guix environment’?

After that you could commit in ‘core-updates’.

Thank you!

Ludo’.
diff mbox

Patch

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index bc6f114..b14f96b 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -75,6 +75,7 @@ 
             patch-/usr/bin/file
             fold-port-matches
             remove-store-references
+            wrap-language-programs
             wrap-program
 
             locale-category->string))
@@ -918,6 +919,41 @@  known as `nuke-refs' in Nixpkgs."
                              (put-u8 out (char->integer char))
                              result))))))
 
+(define (wrap-language-programs path-proc env-var)
+  "Return a procedure, which, invoked as part of a `wrap' phase, is capable of
+wrapping executables inside an environment in which ENV-VAR is correctly set.
+
+The string ENV-VAR is the name of the environmental variable we are setting
+for the executable we are wrapping.  PATH-PROC is a procedure of 2 arguments,
+`inputs' and `outputs', returning the value that we should send ENV-VAR to.
+
+This is a specialized version of `wrap-program' below, intended specifically
+to grant all executables that are part of our output access to all libraries
+that were declared in our inputs.  This is of use for languages such as Perl,
+Python and Guile."
+  (define (list-of-files dir)
+    (map (cut string-append dir "/" <>)
+         (or (scandir dir (lambda (f)
+                            (let ((s (stat (string-append dir "/" f))))
+                              (eq? 'regular (stat:type s)))))
+             '())))
+  (lambda* (#:key inputs outputs #:allow-other-keys)
+    (define bindirs
+      (append-map (match-lambda
+                    ((_ . dir)
+                     (list (string-append dir "/bin")
+                           (string-append dir "/sbin"))))
+                  outputs))
+    (define vars
+      `(,env-var prefix ,(cons (path-proc inputs outputs)
+                               (search-path-as-string->list
+                                (or (getenv env-var) "")))))
+    (for-each (lambda (dir)
+                (let ((files (list-of-files dir)))
+                  (for-each (cut wrap-program <> vars)
+                            files)))
+              bindirs)))
+
 (define* (wrap-program prog #:rest vars)
   "Make a wrapper for PROG.  VARS should look like this: