From: Mark Wooding Date: Mon, 1 Apr 2013 15:25:51 +0000 (+0100) Subject: sbcl-build: Improve error handling and generally tidy up. X-Git-Url: https://git.distorted.org.uk/~mdw/fringe/commitdiff_plain/9c91361f02fa5df1b8d87495407b36fb55ee211c sbcl-build: Improve error handling and generally tidy up. In particular, the polyglot rune is now a bit less awful, and we have pleasant error messages rather than vast stack traces of doom. --- diff --git a/sbcl-build b/sbcl-build index b5170f1..b97cd7a 100755 --- a/sbcl-build +++ b/sbcl-build @@ -1,23 +1,35 @@ #! /bin/sh -e -#| -*-lisp-*- -exec sbcl --script "$0" "$0" "$@" -|# +":"; exec sbcl --script "$0" "$@" # -*-lisp-*- (require 'sb-executable) (let* ((args (cdr *posix-argv*)) - (prog (pop args)) + (prog (pathname-name *load-pathname*)) (cmd (pop args))) - (cond - ((string= cmd "build") - (let ((rc 0)) - (dolist (file args) - (unless (compile-file file :verbose nil :print nil) - (setf rc 1))) - (quit :unix-status rc))) - ((string= cmd "link") - (let ((out (pop args))) - (sb-executable:make-executable out args))) - (t - (format *error-output* "~A: unknown command `~A'~%" prog cmd) - (quit :unix-status 1)))) + (labels ((moan (message &rest arguments) + (format *error-output* "~A: ~?~%" prog message arguments)) + (die (message &rest arguments) + (apply #'moan message arguments) + (exit :code 1))) + (cond + ((not cmd) + (format *error-output* + "Usage: ~A build SOURCE SOURCE ...~%~ + ~0~ ~:*~A link OUTPUT FASL FASL ...~%" + prog) + (exit :code 1)) + ((string= cmd "build") + (let ((rc 0)) + (dolist (file args) + (unless (handler-case (compile-file file :verbose nil :print nil) + (error (cond) + (moan "failed to compile `~A':~%~8T~A" file cond))) + (setf rc 1))) + (exit :code rc))) + ((string= cmd "link") + (let ((out (pop args))) + (handler-case (sb-executable:make-executable out args) + (error (cond) + (die "failed to make executable:~%~8T~A" cond))))) + (t + (die "unknown command `~A'" cmd)))))