utils: Add a `path' argument to `patch-shebang'.
* guix/build/utils.scm (patch-shebang): Add an optional `path' parameter. Change SHEBANG-RX to match the whole interpreter file name. Don't patch when BIN and CMD are the same. Add docstring.master
parent
54ba617e9f
commit
525a59d6d3
|
@ -255,10 +255,12 @@ match substring."
|
||||||
(loop (get-bytevector-n! in buffer 0 buffer-size))))))
|
(loop (get-bytevector-n! in buffer 0 buffer-size))))))
|
||||||
|
|
||||||
(define patch-shebang
|
(define patch-shebang
|
||||||
(let ((shebang-rx (make-regexp "^[[:blank:]]*([[:graph:]]*)/([[:alnum:]]+)(.*)$")))
|
(let ((shebang-rx (make-regexp "^[[:blank:]]*([[:graph:]]+)(.*)$")))
|
||||||
(lambda (file)
|
(lambda* (file
|
||||||
"Patch the #! interpreter path in FILE, if FILE actually starts with a
|
#:optional (path (search-path-as-string->list (getenv "PATH"))))
|
||||||
shebang."
|
"Replace the #! interpreter file name in FILE by a valid one found in
|
||||||
|
PATH, when FILE actually starts with a shebang. Return #t when FILE was
|
||||||
|
patched, #f otherwise."
|
||||||
(define (patch p interpreter rest-of-line)
|
(define (patch p interpreter rest-of-line)
|
||||||
(let* ((template (string-append file ".XXXXXX"))
|
(let* ((template (string-append file ".XXXXXX"))
|
||||||
(out (mkstemp! template))
|
(out (mkstemp! template))
|
||||||
|
@ -287,21 +289,21 @@ shebang."
|
||||||
(let ((line (false-if-exception (read-line p))))
|
(let ((line (false-if-exception (read-line p))))
|
||||||
(and=> (and line (regexp-exec shebang-rx line))
|
(and=> (and line (regexp-exec shebang-rx line))
|
||||||
(lambda (m)
|
(lambda (m)
|
||||||
(let* ((PATH
|
(let* ((cmd (match:substring m 1))
|
||||||
(search-path-as-string->list (getenv "PATH")))
|
(bin (search-path path
|
||||||
(cmd (match:substring m 2))
|
(basename cmd))))
|
||||||
(bin (search-path PATH cmd)))
|
|
||||||
(if bin
|
(if bin
|
||||||
(begin
|
(if (string=? bin cmd)
|
||||||
(format (current-error-port)
|
#f ; nothing to do
|
||||||
"patch-shebang: ~a: changing `~a/~a' to `~a'~%"
|
(begin
|
||||||
file (match:substring m 1)
|
(format (current-error-port)
|
||||||
cmd bin)
|
"patch-shebang: ~a: changing `~a' to `~a'~%"
|
||||||
(patch p bin (match:substring m 3)))
|
file cmd bin)
|
||||||
|
(patch p bin (match:substring m 2))))
|
||||||
(begin
|
(begin
|
||||||
(format (current-error-port)
|
(format (current-error-port)
|
||||||
"patch-shebang: ~a: warning: no binary for interpreter `~a' found in $PATH~%"
|
"patch-shebang: ~a: warning: no binary for interpreter `~a' found in $PATH~%"
|
||||||
file cmd)
|
file (basename cmd))
|
||||||
#f)))))))))))))
|
#f)))))))))))))
|
||||||
|
|
||||||
;;; Local Variables:
|
;;; Local Variables:
|
||||||
|
|
Reference in New Issue