utils: Allow overriding the shell interpreter in ‘wrap-program’.

Previously, when creating new wrappers, 'wrap-program' would search
for an interpreter to use in PATH. However, this is incorrect when
cross-compiling. Allow overriding the shell interpreter to use,
via an optional keyword argument #:sh.

In time, when all users of 'wrap-program' have been corrected,
this keyword argument can be made mandatory.

* guix/build/utils.scm (wrap-program): Introduce a #:sh keyword
  argument, defaulting to (which "sh"). Use this keyword argument.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Maxime Devos 2021-05-31 18:22:31 +02:00 committed by Ludovic Courtès
parent 0fdf2cdef0
commit 8b0899963f
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -7,6 +7,7 @@
;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il> ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -1234,7 +1235,7 @@ (define (wrapped-program? prog)
(and (string-prefix? "." base) (and (string-prefix? "." base)
(string-suffix? "-real" base))))) (string-suffix? "-real" base)))))
(define* (wrap-program prog #:rest vars) (define* (wrap-program prog #:key (sh (which "bash")) #:rest vars)
"Make a wrapper for PROG. VARS should look like this: "Make a wrapper for PROG. VARS should look like this:
'(VARIABLE DELIMITER POSITION LIST-OF-DIRECTORIES) '(VARIABLE DELIMITER POSITION LIST-OF-DIRECTORIES)
@ -1261,7 +1262,12 @@ (define* (wrap-program prog #:rest vars)
modules in $GUILE_LOAD_PATH, etc. modules in $GUILE_LOAD_PATH, etc.
If PROG has previously been wrapped by 'wrap-program', the wrapper is extended If PROG has previously been wrapped by 'wrap-program', the wrapper is extended
with definitions for VARS." with definitions for VARS. If it is not, SH will be used as interpreter."
(define vars/filtered
(match vars
((#:sh _ . vars) vars)
(vars vars)))
(define wrapped-file (define wrapped-file
(string-append (dirname prog) "/." (basename prog) "-real")) (string-append (dirname prog) "/." (basename prog) "-real"))
@ -1315,7 +1321,7 @@ (define (export-variable lst)
(for-each (lambda (var) (for-each (lambda (var)
(display (export-variable var) port) (display (export-variable var) port)
(newline port)) (newline port))
vars) vars/filtered)
(display last port) (display last port)
(close-port port)) (close-port port))
@ -1327,8 +1333,8 @@ (define (export-variable lst)
(lambda (port) (lambda (port)
(format port (format port
"#!~a~%~a~%exec -a \"$0\" \"~a\" \"$@\"~%" "#!~a~%~a~%exec -a \"$0\" \"~a\" \"$@\"~%"
(which "bash") sh
(string-join (map export-variable vars) "\n") (string-join (map export-variable vars/filtered) "\n")
(canonicalize-path wrapped-file)))) (canonicalize-path wrapped-file))))
(chmod prog-tmp #o755) (chmod prog-tmp #o755)