From 6e325f67e0d3dfacae36c1c81b9478ec6eaebb98 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Wed, 21 Nov 2018 21:44:56 +0100 Subject: [PATCH] Implement the save.lisp idea for the bundle. This should make it easier to build pgloader with CCL rather than SBCL, all from the bundle distribution, and also easier to support windows. In passing, add a new file in the bundle distribution: version.sexp should contain a CL string containing the pgloader version string. --- Makefile | 10 +++++++--- bundle/Makefile | 3 +++ bundle/save.lisp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/save.lisp | 8 ++++++-- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 bundle/save.lisp diff --git a/Makefile b/Makefile index 5708b8d..83c523a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # pgloader build tool APP_NAME = pgloader -VERSION = 3.5.2 +VERSION = 3.6.0 # use either sbcl or ccl CL = sbcl @@ -24,7 +24,7 @@ QLDIR = $(BUILDDIR)/quicklisp MANIFEST = $(BUILDDIR)/manifest.ql LATEST = $(BUILDDIR)/pgloader-latest.tgz -BUNDLEDIST = 2018-04-30 +BUNDLEDIST = 2018-10-18 BUNDLENAME = pgloader-bundle-$(VERSION) BUNDLEDIR = $(BUILDDIR)/bundle/$(BUNDLENAME) BUNDLE = $(BUILDDIR)/$(BUNDLENAME).tgz @@ -182,8 +182,12 @@ $(BUNDLEDIR): --eval '(defvar *ql-dist* "$(BUNDLEDIST)")' \ --load bundle/ql.lisp -$(BUNDLE): $(BUNDLEDIR) +$(BUNDLEDIR)/version.sexp: $(BUNDLEDIR) + echo "\"$(VERSION)\"" > $@ + +$(BUNDLE): $(BUNDLEDIR) $(BUNDLEDIR)/version.sexp cp bundle/README.md $(BUNDLEDIR) + cp bundle/save.lisp $(BUNDLEDIR) sed -e s/%VERSION%/$(VERSION)/ < bundle/Makefile > $(BUNDLEDIR)/Makefile git archive --format=tar --prefix=pgloader-$(VERSION)/ master \ | tar -C $(BUNDLEDIR)/local-projects/ -xf - diff --git a/bundle/Makefile b/bundle/Makefile index 246438f..9102bd4 100644 --- a/bundle/Makefile +++ b/bundle/Makefile @@ -61,4 +61,7 @@ $(PGLOADER): $(BUILDAPP) test: $(PGLOADER) $(MAKE) PGLOADER=$(realpath $(PGLOADER)) -C $(SRCDIR)/test regress +save: + sbcl --no-userinit --load ./save.lisp + check: test ; diff --git a/bundle/save.lisp b/bundle/save.lisp new file mode 100644 index 0000000..d955b6c --- /dev/null +++ b/bundle/save.lisp @@ -0,0 +1,47 @@ +;;; +;;; Create a build/bin/pgloader executable from the source code, using +;;; Quicklisp to load pgloader and its dependencies. +;;; + +(in-package #:cl-user) + +(require :asdf) ; should work in SBCL and CCL + +(let* ((cwd (uiop:getcwd)) + (bundle.lisp (uiop:merge-pathnames* "bundle.lisp" cwd)) + (version-file (uiop:merge-pathnames* "version.sexp" cwd)) + (version-string (uiop:read-file-form version-file)) + (asdf:*central-registry* (list cwd))) + + (format t "Loading bundle.lisp~%") + (load bundle.lisp) + + (format t "Loading system pgloader ~a~%" version-string) + (asdf:load-system :pgloader :verbose nil) + (load (asdf:system-relative-pathname :pgloader "src/hooks.lisp")) + + (let* ((pgl (find-package "PGLOADER")) + (version-symbol (find-symbol "*VERSION-STRING*" pgl))) + (setf (symbol-value version-symbol) version-string))) + +(defun pgloader-image-main () + (let ((argv #+sbcl sb-ext:*posix-argv* + #+ccl ccl:*command-line-argument-list*)) + (pgloader::main argv))) + +(let* ((cwd (uiop:getcwd)) + (bin-dir (uiop:merge-pathnames* "bin/" cwd)) + (bin-filename (uiop:merge-pathnames* "pgloader" bin-dir))) + + (ensure-directories-exist bin-dir) + + #+ccl + (ccl:save-application bin-filename + :toplevel-function #'cl-user::pgloader-image-main + :prepend-kernel t) + #+sbcl + (sb-ext:save-lisp-and-die bin-filename + :toplevel #'cl-user::pgloader-image-main + :executable t + :save-runtime-options t + :compression t)) diff --git a/src/save.lisp b/src/save.lisp index 3da0967..43b0de2 100644 --- a/src/save.lisp +++ b/src/save.lisp @@ -27,7 +27,9 @@ (unless (probe-file qlsetup) (format t "File ~a is not found, installing Quicklisp from ~a~%" qlsetup *quicklisp.lisp*) - (uiop:run-program (format nil "curl -o ~a ~a" ql.lisp *quicklisp.lisp*)) + (let ((command (format nil "curl -o ~a ~a" ql.lisp *quicklisp.lisp*))) + (format t "Running command: ~a~%" command) + (uiop:run-program command)) (load ql.lisp) (let* ((quickstart (find-package "QUICKLISP-QUICKSTART")) (ql-install (find-symbol "INSTALL" quickstart))) @@ -57,7 +59,9 @@ #+ccl ccl:*command-line-argument-list*)) (pgloader::main argv))) -(let ((image-filename "/Users/dim/dev/pgloader/build/bin/pgloader")) +(let* ((cwd (uiop:getcwd)) + (build-dir (uiop:merge-pathnames* "build/bin/" cwd)) + (image-filename (uiop:merge-pathnames* "pgloader" build-dir))) #+ccl (ccl:save-application image-filename :toplevel-function #'cl-user::pgloader-image-main