~fitzsim/cl-starter-script

6deae62d3d6a559e0826f62d2fb689559c1b083b — Thomas Fitzsimmons 1 year, 4 months ago 865d15a
Add compilation support
5 files changed, 71 insertions(+), 13 deletions(-)

A .gitignore
M README.md
A compile.lisp
M run-tests.lisp
M start.lisp
A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
start

M README.md => README.md +35 -6
@@ 11,21 11,48 @@ Then, as a normal user, run:

and you should see:

	Usage: ./cl-starter-script/start.lisp [-h|--help] [-v|--verbose]
	                                      [-l|--level LEVEL] [-o|--output FILE] [REST]
	Usage: start.lisp [-h|--help] [-v|--verbose] [-l|--level LEVEL]
	                  [-o|--output FILE] [REST]
	Common Lisp script
	

	Available options:
	  -h, --help        print this help text
	  -v, --verbose     verbose output
	  -l, --level LEVEL run at LEVEL
	  -o, --output FILE output to FILE

	Change.

You can compile the script:

    cd ./cl-starter-script
    ./compile.lisp
    ./start --help

and you should see:

    Usage: start [-h|--help] [-v|--verbose] [-l|--level LEVEL] [-o|--output FILE] [REST]
	Common Lisp script

	Available options:
	  -h, --help        print this help text
	  -v, --verbose     verbose output
	  -l, --level LEVEL run at LEVEL
	  -o, --output FILE output to FILE
	

	Change.

If that doesn't work, complain by filing a
If anything doesn't work, complain by filing a
[todo](https://todo.sr.ht/~fitzsim/cl-starter-script).

# Renaming

The package name is derived from the file name.  To start customizing
just rename the scipt:

	mv start.lisp myscript.lisp
	ln -sf myscript.lisp compile.lisp

# It's a start...

Features:


@@ 40,7 67,9 @@ Features:

* SBCL, GNU CLISP and ECL support, so far.

* Self-contained within the checkout directory.
* Compilation support for SBCL and GNU CLISP.

* Self-contained within the recursive checkout directory.

* Runnable without an Internet connection after the first Git clone.


A compile.lisp => compile.lisp +1 -0
@@ 0,0 1,1 @@
start.lisp
\ No newline at end of file

M run-tests.lisp => run-tests.lisp +23 -7
@@ 18,13 18,13 @@ SPDX-License-Identifier: Apache-2.0 |#
  (let ((lines (uiop:read-file-lines "start.lisp")))
    (with-open-file  (out "start.lisp" :direction :io :if-exists :supersede)
      (loop for line in lines do
        (cond ((eq 0 (search (concatenate 'string "type ") line))
        (cond ((eq 0 (search "type " line))
               (if lisp
                   (if (eq 0 (search (concatenate 'string "type " lisp) line))
                       (write-line line out) ; leave unnuked
                       (write-line (concatenate 'string "#" line) out)) ;; nuke
                   (write-line line out)))
              ((eq 0 (search (concatenate 'string "#type ") line))
              ((eq 0 (search "#type " line))
               (if lisp
                   (if (eq 0 (search (concatenate 'string "#type " lisp) line))
                       (write-line (subseq line 1) out) ; unnuke


@@ 32,28 32,41 @@ SPDX-License-Identifier: Apache-2.0 |#
                   (write-line (subseq line 1) out))) ; unnuke all
              (t
               (write-line line out)))))))
(defun main () "Entry point for the script."
  (let ((lisps '("sbcl" "clisp" "ecl"))
(defun run-compile ()
  (uiop:run-program
   (concatenate 'string "./compile.lisp")
   :output *standard-output*
   :error-output *standard-output*))
(defun compare-lisps (&optional binary)
  (let ((lisps (if binary
                   '("sbcl" "clisp")
                   '("sbcl" "clisp" "ecl")))
        (outputs (make-hash-table :test #'equal))
        (optionss '(" --help" " a" " -l 3" " -l 3 --output file.txt a b"))
        (times (make-hash-table :test #'equal)))
    (dolist (lisp lisps)
      (format t "Test ~a~a~%" lisp " --verbose")
      (unnuke lisp)
      (when binary
        (run-compile))
      (time (uiop:run-program
             (concatenate 'string "./start.lisp --verbose")
             (concatenate 'string
                          (if binary "./start" "./start.lisp") " --verbose")
             :output *standard-output*
             :error-output *standard-output*)))
    (dolist (options optionss)
      (dolist (lisp lisps)
        (format t "Test ~a~a~%" lisp options)
        (unnuke lisp)
        (when binary
          (run-compile))
        (setf
         (gethash lisp outputs)
         (with-output-to-string (out)
           (setf (gethash lisp times)
                 (uiop:run-program
                  (concatenate 'string "./start.lisp" options)
                  (concatenate 'string
                               (if binary "./start" "./start.lisp") options)
                  :output out :error-output out)))))
      (loop for lisp1 in lisps
            do (loop for lisp2 in (delete lisp1 (copy-list lisps))


@@ 65,7 78,10 @@ SPDX-License-Identifier: Apache-2.0 |#
                                  lisp2 (gethash lisp2 outputs))
                          (unnuke)
                          (uiop:quit 1)))
               (format t "Pass ~a~a~%" lisp1 options))))
               (format t "Pass ~a~a~%" lisp1 options)))))
(defun main () "Entry point for the script."
  (compare-lisps)
  (compare-lisps t)
  (unnuke)
  (when (uiop:argv0) (uiop:quit)))
(when (uiop:argv0) (handler-case (with-user-abort:with-user-abort (main))

M start.lisp => start.lisp +11 -0
@@ 40,5 40,16 @@ SPDX-License-Identifier: Apache-2.0 |#
              (cl:dolist (option options) (cl:print option)) (cl:terpri)
              (cl:format cl:t "Remainder:~22T~A~%" arguments))))
    (cl:when name (uiop:quit))))
(cl:let ((name (uiop:argv0)) (out cl-user::*program-name*)
         (package cl-user::*program-package*))
  (cl:when (cl:and name (cl:equal (cl:file-namestring name) "compile.lisp"))
    (cl:setf uiop:*image-entry-point* (cl:intern "MAIN" package))
    (uiop:dump-image out :executable cl:t) ; not supported on ECL.
    (uiop:quit)))
(cl:when (uiop:argv0) (cl:handler-case (with-user-abort:with-user-abort (main))
                        (with-user-abort:user-abort () (uiop:quit 1))))
;;; Local Variables:
;;; mode: Lisp
;;; syntax: ANSI-Common-Lisp
;;; compile-command: "./compile.lisp"
;;; End: