nonguix: Allow disabling passing $0 in make-wrapper.

* nonguix/build/utils.scm (make-wrapper): Add skip-argument-0? keyword.
This commit is contained in:
Julien Lepiller 2020-07-02 14:12:10 +02:00
parent 7d21e7db2b
commit 1f61e376ce
No known key found for this signature in database
GPG key ID: 53D457B2D636EE82

View file

@ -35,7 +35,7 @@ See https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header."
(array-ref (get-bytevector-n (current-input-port) 5) 4))) (array-ref (get-bytevector-n (current-input-port) 5) 4)))
#:binary #t)) #:binary #t))
(define* (make-wrapper wrapper real-file #:rest vars) (define* (make-wrapper wrapper real-file #:key (skip-argument-0? #f) #:rest vars)
"Like `wrap-program' but create WRAPPER around REAL-FILE. "Like `wrap-program' but create WRAPPER around REAL-FILE.
The wrapper automatically changes directory to that of REAL-FILE. The wrapper automatically changes directory to that of REAL-FILE.
@ -76,13 +76,24 @@ contents:
(format #f "export ~a=\"$~a${~a:+:}~a\"" (format #f "export ~a=\"$~a${~a:+:}~a\""
var var var (string-join rest ":"))))) var var var (string-join rest ":")))))
(define (remove-keyword-arguments lst)
(match lst
(() '())
(((? keyword? _) _ lst ...)
(remove-keyword-arguments lst))
(_ lst)))
(mkdir-p (dirname wrapper)) (mkdir-p (dirname wrapper))
(call-with-output-file wrapper (call-with-output-file wrapper
(lambda (port) (lambda (port)
(format port (format port
"#!~a~%~a~%cd \"~a\"~%exec -a \"$0\" \"~a\" \"$@\"~%" (if skip-argument-0?
"#!~a~%~a~%cd \"~a\"~%exec \"~a\" \"$@\"~%"
"#!~a~%~a~%cd \"~a\"~%exec -a \"$0\" \"~a\" \"$@\"~%")
(which "bash") (which "bash")
(string-join (map export-variable vars) "\n") (string-join
(map export-variable (remove-keyword-arguments vars))
"\n")
(dirname real-file) (dirname real-file)
(canonicalize-path real-file)))) (canonicalize-path real-file))))
(chmod wrapper #o755)) (chmod wrapper #o755))