From 1f61e376ce7e6e5873744181bd740b8223a7f93f Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Thu, 2 Jul 2020 14:12:10 +0200 Subject: nonguix: Allow disabling passing $0 in make-wrapper. * nonguix/build/utils.scm (make-wrapper): Add skip-argument-0? keyword. --- nonguix/build/utils.scm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'nonguix') diff --git a/nonguix/build/utils.scm b/nonguix/build/utils.scm index 451f63b..ab437f2 100644 --- a/nonguix/build/utils.scm +++ b/nonguix/build/utils.scm @@ -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))) #: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. The wrapper automatically changes directory to that of REAL-FILE. @@ -76,13 +76,24 @@ contents: (format #f "export ~a=\"$~a${~a:+:}~a\"" var var var (string-join rest ":"))))) + (define (remove-keyword-arguments lst) + (match lst + (() '()) + (((? keyword? _) _ lst ...) + (remove-keyword-arguments lst)) + (_ lst))) + (mkdir-p (dirname wrapper)) (call-with-output-file wrapper (lambda (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") - (string-join (map export-variable vars) "\n") + (string-join + (map export-variable (remove-keyword-arguments vars)) + "\n") (dirname real-file) (canonicalize-path real-file)))) (chmod wrapper #o755)) -- cgit v1.2.3