Am Samstag, 26. Januar 2013 schrieb Ludovic Courtès:
> The function you want to patch ;-) is ‘patch-shebang’ in
> build/utils.scm.  Since that entails a full rebuild, that’s something
> for a new ‘core-updates’ branch.

Please find attached a patch for review. I tested it on a few example 
files, but not yet with a real packet - I am waiting for the full rebuild 
;-)

Andreas
From b4763457c1127a3c910dc3d28f1ce933175a8be0 Mon Sep 17 00:00:00 2001
From: Andreas Enge <andr...@enge.fr>
Date: Fri, 22 Feb 2013 23:00:41 +0100
Subject: [PATCH] Patch-shebang: Handle "#!/usr/bin/env command"

* guix/build/utils.scm (patch-shebang): Handle replacement of
   "#!.*/env CMD ARGS" by "#!/nix/store/path/.../to/CMD ARGS".
---
 guix/build/utils.scm |   29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 6921e31..bab82fe 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -426,7 +426,7 @@ bytes transferred and the continuation of the transfer as a thunk."
          (stat:mtimensec stat)))
 
 (define patch-shebang
-  (let ((shebang-rx (make-regexp "^[[:blank:]]*([[:graph:]]+)(.*)$")))
+  (let ((shebang-rx (make-regexp "^[[:blank:]]*([[:graph:]]+)[[:blank:]]*([[:graph:]]*)(.*)$")))
     (lambda* (file
               #:optional
               (path (search-path-as-string->list (getenv "PATH")))
@@ -465,16 +465,27 @@ FILE are kept unchanged."
                (let ((line (false-if-exception (read-line p))))
                  (and=> (and line (regexp-exec shebang-rx line))
                         (lambda (m)
-                          (let* ((cmd (match:substring m 1))
-                                 (bin (search-path path (basename cmd))))
+                          (let* ((first (match:substring m 1))
+                                 (second (match:substring m 2))
+                                 (third (match:substring m 3))
+                                 (has-env (string=? (string-pad first 4) "/env"))
+                                 (cmd (if has-env second (basename first)))
+                                 (bin (search-path path cmd)))
                             (if bin
-                                (if (string=? bin cmd)
+                                (if (string=? bin first)
                                     #f            ; nothing to do
-                                    (begin
-                                      (format (current-error-port)
-                                              "patch-shebang: ~a: changing `~a' to `~a'~%"
-                                              file cmd bin)
-                                      (patch p bin (match:substring m 2))))
+                                    (if has-env
+                                      (begin
+                                        (format (current-error-port)
+                                                "patch-shebang: ~a: changing `~a' to `~a'~%"
+                                                file (string-append first " " second) bin)
+                                        (patch p bin third))
+                                      (begin 
+                                        (format (current-error-port)
+                                                "patch-shebang: ~a: changing `~a' to `~a'~%"
+                                                file first bin)
+                                        (patch p bin
+                                          (string-append " " second third)))))
                                 (begin
                                   (format (current-error-port)
                                           "patch-shebang: ~a: warning: no binary for interpreter `~a' found in $PATH~%"
-- 
1.7.10.4

Reply via email to