From 11996d85d3cfa31ecf969421b4dc718b617bf2ff Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Fri, 22 Feb 2013 23:00:41 +0100 Subject: 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 | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'guix/build') diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 6921e31bdd..f7fb7938e5 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013 Ludovic Courtès +;;; Copyright © 2013 Andreas Enge ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,7 +52,7 @@ (define-module (guix build utils) fold-port-matches remove-store-references)) - + ;;; ;;; Directories. ;;; @@ -426,7 +427,7 @@ (define (set-file-time file stat) (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 +466,27 @@ (define (patch p interpreter rest-of-line) (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* ((interp (match:substring m 1)) + (arg1 (match:substring m 2)) + (rest (match:substring m 3)) + (has-env (string-suffix? "/env" interp)) + (cmd (if has-env arg1 (basename interp))) + (bin (search-path path cmd))) (if bin - (if (string=? bin cmd) + (if (string=? bin interp) #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 interp " " arg1) bin) + (patch p bin rest)) + (begin + (format (current-error-port) + "patch-shebang: ~a: changing `~a' to `~a'~%" + file interp bin) + (patch p bin + (string-append " " arg1 rest))))) (begin (format (current-error-port) "patch-shebang: ~a: warning: no binary for interpreter `~a' found in $PATH~%" -- cgit v1.2.3