commit db0dd0bec578b1fa62a1c9c7cf17fc4b02a769ea Spenser Truex <web@spensertruex.com> 2019-11-02 21:20:11 -0700 Installation detects itself, and does itself.
CONFIG-ASDF.lisp | 1 - CONFIG-QUICKLISP.lisp | 1 - README.md | 13 ++++++++++++- code/defaults.lisp | 5 +++++ code/early.lisp | 12 ------------ code/install.lisp | 33 +++++++++++++++++++++++++++++++-- code/package.lisp | 5 ----- code/save.lisp | 31 +++++++++++++++---------------- code/util.lisp | 1 + package.lisp | 4 ++++ sbcl-librarian.asd | 8 +++----- sbcl-librarian.fasl | Bin 0 -> 608 bytes 12 files changed, 71 insertions(+), 43 deletions(-)
diff --git a/CONFIG-ASDF.lisp b/CONFIG-ASDF.lisp index 3732ebd..e411864 100644 --- a/CONFIG-ASDF.lisp +++ b/CONFIG-ASDF.lisp @@ -1,5 +1,4 @@ (in-package #:sbcl-librarian) - (defparameter *asdf-packages* '( ;; Example: diff --git a/CONFIG-QUICKLISP.lisp b/CONFIG-QUICKLISP.lisp index 0e8c9c3..99749b0 100644 --- a/CONFIG-QUICKLISP.lisp +++ b/CONFIG-QUICKLISP.lisp @@ -1,5 +1,4 @@ (in-package #:sbcl-librarian) - (defparameter *quicklisp-packages* '( ;; Example: diff --git a/README.md b/README.md index 34f6f38..d73bbab 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,18 @@ dumping a core once. ## Install -We need to know which packages are needed, and whether they are from quicklisp. Modify `CONFIG-ASDF.lisp` and/or `CONFIG-QUICKLISP.lisp`. +We need to know which packages are needed, and whether they are from quicklisp. + + +1. Modify `CONFIG-ASDF.lisp` and/or `CONFIG-QUICKLISP.lisp` with the desired + packages. +2. Install: `(sbcl-librarian:install)`. + +## Updating packages + +Run `(sbcl-librarian:update)`. + +## ## License diff --git a/code/defaults.lisp b/code/defaults.lisp new file mode 100644 index 0000000..af5d89d --- /dev/null +++ b/code/defaults.lisp @@ -0,0 +1,5 @@ +(in-package #:sbcl-librarian) + +(defparameter *core-path* #P"~/.sbcl-library.core" + "The default place to store the library core.") +(defparameter *sbclrc-path* #P"~/.sbclrc") diff --git a/code/early.lisp b/code/early.lisp deleted file mode 100644 index 136dbbb..0000000 --- a/code/early.lisp +++ /dev/null @@ -1,12 +0,0 @@ -(in-package #:sbcl-librarian) - -(defun untilde (path) - "Ensure the has no tilde." - (if (char= #\~ (elt path 0)) - (merge-pathnames (user-homedir-pathname) - (subseq path 2)) - path)) - -(defparameter *core-path* (untilde "~/.sbcl-library.core") - "The default place to store the library core.") -(defparameter *sbclrc-path* (untilde "~/.sbclrc")) diff --git a/code/install.lisp b/code/install.lisp index 9c14ce1..b090a88 100644 --- a/code/install.lisp +++ b/code/install.lisp @@ -1,4 +1,33 @@ (in-package #:sbcl-librarian) -(defun install (&optional (core-path *core-path*) - (sbclrc-path *sbclrc-path*))) +(defparameter *installed* ";;; Leave this line for sbcl-librarian!") + +(defun until (stream match) + (let ((line (read-line stream nil nil))) + (when line + (when (not (search match line :test #'string=)) + (until stream match))))) + +(defun installedp (sbclrc-path) + "Determine if sbcl-librarian is installed in the .sbclrc." + (with-open-file (sbclrc sbclrc-path + :direction :input + :if-does-not-exist nil) + (when sbclrc (until sbclrc *installed*)))) +(defun install (&optional (sbclrc-path *sbclrc-path*) (core-path *core-path*)) + (with-open-file (sbclrc sbclrc-path + :direction :output + :if-exists :append + :if-does-not-exist :create) + (when (not (installedp sbclrc-path)) + (format sbclrc "~%~A~%" *installed*) + (prin1 `(progn + (when (probe-file ,core-path)) + (pushnew :sblibr *features*)) + sbclrc) + (format sbclrc "~%~A~%" "#-sblibr") + (prin1 '(asdf:load-system :sbcl-librarian) sbclrc) + (format sbclrc "~%~A~%" "#-sblibr") + (prin1 '(sbcl-librarian:update) sbclrc) + (format sbclrc "~%"))) + (update core-path)) diff --git a/code/package.lisp b/code/package.lisp deleted file mode 100644 index a6b1c06..0000000 --- a/code/package.lisp +++ /dev/null @@ -1,5 +0,0 @@ -;;;; package.lisp - -(defpackage #:sbcl-librarian - (:use #:cl) - (:export #:save #:install)) diff --git a/code/save.lisp b/code/save.lisp index 56d28ff..0d74463 100644 --- a/code/save.lisp +++ b/code/save.lisp @@ -1,28 +1,27 @@ (in-package #:sbcl-librarian) -(defun save (&optional (core-path *core-path*)) +(defun update (&optional (core-path *core-path*)) (load-configs) + (save core-path)) + +(defun save (&optional (core-path *core-path*)) ;; Should ensure that this is friendly. ~ is not allowed, does it actually ;; exist, etc. - (save-lisp-and-die + (sb-ext:save-lisp-and-die (asdf/pathname:ensure-absolute-pathname - (untilde core-path)))) + core-path))) (defun load-configs () - (with-open-file (q "CONFIG-QUICKLISP.lisp") - (with-open-file (a "CONFIG-ASDF.lisp") - (let ((qpack (verifying :quicklisp (read q))) - (apack (verifying :asdf (read a)))) - (mapcar #'(lambda (fn lst) - (mapc fn lst) - (require lst)) - `(#',ql:quickload #',asdf:load-system) - `(,apack ,qpack)))))) + (mapcar #'(lambda (fn pkg) + (when pkg + (mapc fn pkg) + (require pkg))) + (list #'ql:quickload #'asdf:load-system) + (list (verify-ql *quicklisp-packages*) + (verify-asdf *asdf-packages*)))) -(defgeneric verifying (manager packages) - (:documentation "Verify that packages exist for a given manager.")) +(defun verify-ql (packages) packages) +(defun verify-asdf (packages) packages) ;;; Would be nice to have an interface here with continuations, friendly output ;;; and warnings, etc. -(defmethod verifying ((manager :quicklisp) packages) packages) -(defmethod verifying ((manager :asdf) packages) packages) diff --git a/code/util.lisp b/code/util.lisp new file mode 100644 index 0000000..9891772 --- /dev/null +++ b/code/util.lisp @@ -0,0 +1 @@ +(in-package #:sbcl-librarian) diff --git a/package.lisp b/package.lisp new file mode 100644 index 0000000..852edf8 --- /dev/null +++ b/package.lisp @@ -0,0 +1,4 @@ +(defpackage #:sbcl-librarian + (:use #:cl) + (:nicknames #:sblibr) + (:export #:update #:install)) diff --git a/sbcl-librarian.asd b/sbcl-librarian.asd index f355534..e0bba04 100644 --- a/sbcl-librarian.asd +++ b/sbcl-librarian.asd @@ -1,14 +1,12 @@ -;;;; sbcl-librarian.asd - (asdf:defsystem #:sbcl-librarian :description "Load up projects and dump the core somewhere." :author "Spenser Truex <web@spensertruex.com>" :license "GNU GPL v3" :version "0.0.1" :serial t - :components ((:file "CONFIG-ASDF") + :components ((:file "package") + (:file "CONFIG-ASDF") (:file "CONFIG-QUICKLISP") - (:file "code/package") - (:file "code/early") + (:file "code/defaults") (:file "code/save") (:file "code/install"))) diff --git a/sbcl-librarian.fasl b/sbcl-librarian.fasl new file mode 100644 index 0000000..3ac556e Binary files /dev/null and b/sbcl-librarian.fasl differ