Eliminate the separately maintained Lisp system version number.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Sep 2015 17:10:06 +0000 (18:10 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 14 Sep 2015 17:11:19 +0000 (18:11 +0100)
  * Have `configure.ac' derive a version string which ASDF won't choke
    on and make that available as an output variable.

  * Move the ASD files to `.in' files, and substitute the source path
    into them at build time, so that they actually still work.

  * At build time, construct an `auto.lisp' file with the relevant version
    information; modify the ASD `.in' files to load this.

  * At install time, construct the ASD files differently, by stripping
    out the source path and substituting the version information bodily
    into the files.

  * Actually install the `sod-frontend' system definition, just in case
    it's useful to someone.

  * Actually remove the ASDF symlinks when we're finished.

configure.ac
src/Makefile.am
src/auto.lisp.in [new file with mode: 0644]
src/package.lisp
src/sod-frontend.asd.in [moved from src/sod-frontend.asd with 95% similarity]
src/sod-test.asd.in [moved from src/sod-test.asd with 93% similarity]
src/sod.asd.in [moved from src/sod.asd with 97% similarity]
src/test-base.lisp
vars.am

index cb1c5a6..c1fed50 100644 (file)
@@ -39,6 +39,32 @@ AX_CFLAGS_WARN_ALL
 mdw_LIBTOOL_VERSION_INFO
 
 dnl--------------------------------------------------------------------------
+dnl Convert the version number for ASDF.
+
+## This is surprisingly awful.  The convention for official version numbers
+## is that they look like MAJOR.MINOR.PATCH[.BPB][-N-gHEX[+]].  ASDF
+## insists on simple numeric things separated by dots.  If there's no Git
+## thing on the end, then the main version number will do fine.  If there
+## is, then we insert /two/ `0's in, followed by N and the HEX converted to
+## decimal.  Why two?  Because if there's no brown-paper-bag number, we
+## want to make sure that the first BPB release is higher than any of the
+## preceding Git revisions.
+ver=AC_PACKAGE_VERSION
+case $ver in
+  *-*-g*)
+    base=${ver%%-*} tail=${ver#*-}
+    n=${tail%%-*} tail=${tail#*-g}
+    case $tail in *+) grubby=.1 tail=${tail%+} ;; *) grubby= ;; esac
+    rev=$(( 0x$tail ))
+    ASDF_VERSION=$base.0.0.$n.$rev$grubby
+    ;;
+  *)
+    ASDF_VERSION=$ver
+    ;;
+esac
+AC_SUBST([ASDF_VERSION])
+
+dnl--------------------------------------------------------------------------
 dnl Common Lisp things.
 
 AC_ARG_WITH([lisp-system],
index c7779f9..7b23dd8 100644 (file)
@@ -27,13 +27,11 @@ include     $(top_srcdir)/vars.am
 
 nobase_dist_pkglispsrc_DATA = $(LISP_SOURCES)
 LISP_SOURCES            =
+SYSDEFS                         =
 
 ###--------------------------------------------------------------------------
 ### The source files.
 
-## The system definition file.
-LISP_SOURCES           += sod.asd
-
 ## The package definition file.
 LISP_SOURCES           += package.lisp
 
@@ -87,7 +85,6 @@ LISP_SOURCES          += method-proto.lisp method-impl.lisp
 LISP_SOURCES           += method-aggregate.lisp
 
 ## User interface.
-LISP_SOURCES           += sod-frontend.asd
 LISP_SOURCES           += frontend.lisp optparse.lisp
 
 ## Finishing touches.
@@ -98,20 +95,39 @@ LISP_SOURCES                += final.lisp
 
 CLEANFILES             += *.$(fasl) parser/*.$(fasl)
 
+## Autodetected configuration.
+EXTRA_DIST             += auto.lisp.in
+CLEANFILES             += auto.lisp
+auto.lisp: auto.lisp.in Makefile
+       $(SUBST) $(srcdir)/auto.lisp.in >$@.new $(SUBSTITUTIONS) && \
+               grep '^[^;]' $@.new >$@.strip && \
+               rm -f $@.new && mv $@.strip $@
+
+## Building a working-tree system definition.
+EXTRA_DIST             += sod.asd.in
+CLEANFILES             += sod.asd
+sod.asd: sod.asd.in Makefile
+       $(SUBST) $(srcdir)/sod.asd.in >$@.new $(SUBSTITUTIONS) && \
+               mv $@.new $@
+
+EXTRA_DIST             += sod-frontend.asd.in
+CLEANFILES             += sod-frontend.asd
+sod-frontend.asd: sod-frontend.asd.in Makefile
+       $(SUBST) $(srcdir)/sod-frontend.asd.in >$@.new $(SUBSTITUTIONS) && \
+               mv $@.new $@
+
 ## Building the executable image.
 bin_PROGRAMS           += sod
 sod_SOURCES             =
-sod: $(LISP_SOURCES)
-       $(V_DUMP)true_srcdir=$$(cd $(srcdir); pwd); \
-       ASDF_OUTPUT_TRANSLATIONS=$$true_srcdir:$(abs_builddir): \
-       $(CL_LAUNCH) -o sod -d ! -l $(LISPSYS) +I -S $$true_srcdir/: \
+sod: $(LISP_SOURCES) sod.asd sod-frontend.asd auto.lisp
+       $(V_DUMP)$(CL_LAUNCH) -o sod -d ! -l $(LISPSYS) +I \
                -s sod-frontend -r sod-frontend:main
 
 ###--------------------------------------------------------------------------
 ### Unit testing.
 
 ## The system definition.
-EXTRA_DIST             += sod-test.asd
+EXTRA_DIST             += sod-test.asd.in
 
 ## Basic utilities.
 EXTRA_DIST             += test-base.lisp
@@ -125,15 +141,17 @@ EXTRA_DIST                += c-types-test.lisp
 EXTRA_DIST             += codegen-test.lisp
 EXTRA_DIST             += lexer-test.lisp
 
+## The system definition.
+EXTRA_DIST             += sod-test.asd.in
+CLEANFILES             += sod-test.asd
+sod-test.asd: sod-test.asd.in Makefile
+       $(SUBST) $(srcdir)/sod-test.asd.in >$@.new $(SUBSTITUTIONS) && \
+               mv $@.new $@
+
 ## Running the Lisp tests.
-check-local:
-       $(V_TEST)true_srcdir=$$(cd $(srcdir); pwd); \
-       ASDF_OUTPUT_TRANSLATIONS=$$true_srcdir:$(abs_builddir): \
-       $(CL_LAUNCH) -l $(LISPSYS) -s sod-test +I -S $$true_srcdir/: \
-               -i '(handler-case ;\
-                     (progn ;\
-                       (setf sod-test:*build-version* "$(VERSION)") ;\
-                       (asdf:test-system "sod")) ;\
+check-local: sod sod-test.asd
+       $(V_TEST)$(CL_LAUNCH) -l $(LISPSYS) -s sod-test +I \
+               -i '(handler-case (asdf:test-system "sod") ;\
                      (error (cond) ;\
                        (format *error-output* "ERR: ~A~%" cond) ;\
                        (cl-launch:quit 1)))'
@@ -148,9 +166,9 @@ check-local:
 ## don't have spaces in them; but that's generally a bad idea in Makefiles
 ## anyway.
 install-data-local:
-       $(MKDIR_P) $(DESTDIR)$(lispsysdir)
+       $(MKDIR_P) $(DESTDIR)$(lispsysdir) $(DESTDIR)$(pkglispsrcdir)
        @set -e; \
-       from=$(lispsysdir) to=$(pkglispsrcdir)/sod.asd; \
+       from=$(lispsysdir) to=$(pkglispsrcdir); \
        set -- $$(echo $$from | tr "/" " "); fwd=$$*; \
        set -- $$(echo $$to | tr "/" " "); twd=$$*; \
        while :; do \
@@ -163,8 +181,21 @@ install-data-local:
        done; \
        dots=$$(echo $$fwd | sed 's/[^ ][^ ]*/../g'); \
        rel=$$(echo $$dots $$twd | tr " " "/"); \
-       echo >&2 "ln -s $$rel $$to"; \
-       ln -s $$rel $(DESTDIR)$$from/sod.asd.new; \
-       mv $(DESTDIR)$$from/sod.asd.new $(DESTDIR)$$from/sod.asd
+       for i in sod.asd sod-frontend.asd; do \
+         echo >&2 "CREATE $$to/$$i"; \
+         sed -e '/#|@-auto-@|#/ { r auto.lisp' -e ' d; }' \
+             -e '/#|@-path-@|#/ d' \
+               $(srcdir)/$$i.in >$(DESTDIR)$(pkglispsrcdir)/$$i.new; \
+         mv $(DESTDIR)$(pkglispsrcdir)/$$i.new \
+               $(DESTDIR)$(pkglispsrcdir)/$$i; \
+         echo >&2 "LINK $$rel/$$i $$to/$$i"; \
+         ln -s $$rel/$$i $(DESTDIR)$$from/$$i.new; \
+         mv $(DESTDIR)$$from/$$i.new $(DESTDIR)$$from/$$i; \
+       done
+
+uninstall-local:
+       for i in sod.asd sod-frontend.asd; do \
+         rm -f $(DESTDIR)$(pkglispsrcdir)/$$i $(DESTDIR)$(lispsysdir)/$$i; \
+       done
 
 ###----- That's all, folks --------------------------------------------------
diff --git a/src/auto.lisp.in b/src/auto.lisp.in
new file mode 100644 (file)
index 0000000..758ef23
--- /dev/null
@@ -0,0 +1,7 @@
+;;; -*-lisp-*-
+
+(defparameter *version* "@VERSION@"
+  "The official Sod revision number.")
+
+(defparameter *sysdef-version* "@ASDF_VERSION@"
+  "The Sod revision number, forced into ASDF's limited format.")
index a6b9785..d6e47f4 100644 (file)
@@ -31,7 +31,7 @@
 (cl:in-package #:sod)
 
 (export '*sod-version*)
-(defvar *sod-version* (asdf:component-version (asdf:find-system "sod"))
+(defparameter *sod-version* sod-sysdef:*version*
   "The version of the SOD translator system, as a string.")
 
 ;;;----- That's all, folks --------------------------------------------------
similarity index 95%
rename from src/sod-frontend.asd
rename to src/sod-frontend.asd.in
index 6ba17cd..b81fd2d 100644 (file)
 
 (cl:in-package #:sod-sysdef)
 
+#|@-auto-@|# (load "auto.lisp")
+
 ;;;--------------------------------------------------------------------------
 ;;; Definition.
 
 (defsystem sod-frontend
 
   ;; Boring copyright stuff.
-  :version "1.0.0"
+  :version #.*sysdef-version*
   :author "Mark Wooding"
   :license "GNU General Public License, version 2 or later"
+  #|@-path-@|# :pathname "@srcdir@"
 
   ;; Documentation.
   :description "A Sensible Object Design for C, command-line frontend."
similarity index 93%
rename from src/sod-test.asd
rename to src/sod-test.asd.in
index b3024dc..6b2a83b 100644 (file)
 ;;; along with SOD; if not, write to the Free Software Foundation,
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-(cl:defpackage #:sod-test-sysdef
+(cl:defpackage #:sod-sysdef
   (:use #:common-lisp #:asdf))
 
-(cl:in-package #:sod-test-sysdef)
+(cl:in-package #:sod-sysdef)
+
+#|@-auto-@|# (load "auto.lisp")
 
 ;;;--------------------------------------------------------------------------
 ;;; Definition.
 (defsystem sod-test
 
   ;; Boring copyright stuff.
-  :version "1.0.0"
+  :version #:*sysdef-version*
   :author "Mark Wooding"
   :license "GNU General Public License, version 2 or later"
+  #|@-path-@|# :pathname "@srcdir@"
 
   ;; Documentation.
   :description "Tests for the Sensible Object Design translator."
similarity index 97%
rename from src/sod.asd
rename to src/sod.asd.in
index f207df0..d710fb1 100644 (file)
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 (cl:defpackage #:sod-sysdef
-  (:use #:common-lisp #:asdf))
+  (:use #:common-lisp #:asdf)
+  (:export #:*version*))
 
 (cl:in-package #:sod-sysdef)
 
+#|@-auto-@|# (load "auto.lisp")
+
 ;;;--------------------------------------------------------------------------
 ;;; Definition.
 
 (defsystem sod
 
   ;; Boring copyright stuff.
-  :version "0.2.0"
+  :version #.*sysdef-version*
   :author "Mark Wooding"
   :license "GNU General Public License, version 2 or later"
+  #|@-path-@|# :pathname "@srcdir@"
 
   ;; Documentation.
   :description "A Sensible Object Design for C."
index f7210ab..203f918 100644 (file)
 (defclass base-test (test-case) ())
 (add-test *sod-test-suite* (get-suite base-test))
 
-(export '*build-version*)
-(defvar *build-version* nil)
-
-(def-test-method check-version ((test base-test) :run nil)
-  (unless (or (null *build-version*)
-             (and (>= (length *build-version*) (length *sod-version*))
-                  (string= *build-version* *sod-version*
-                           :end1 (length *sod-version*))))
-    (failure "Build version ~A doesn't match package version ~A."
-            *build-version* *sod-version*)))
-
 (defun run-tests (&optional which)
   (textui-test-run (acond
                     ((null which) *sod-test-suite*)
diff --git a/vars.am b/vars.am
index 1b360ee..7e7406c 100644 (file)
--- a/vars.am
+++ b/vars.am
@@ -66,7 +66,8 @@ SUBSTITUTIONS = \
        prefix=$(prefix) exec_prefix=$(exec_prefix) \
        libdir=$(libdir) includedir=$(includedir) \
        bindir=$(bindir) sbindir=$(sbindir) \
-       PACKAGE=$(PACKAGE) VERSION=$(VERSION)
+       srcdir=$(srcdir) \
+       PACKAGE=$(PACKAGE) VERSION=$(VERSION) ASDF_VERSION=$(ASDF_VERSION)
 
 V_SUBST = $(V_SUBST_$(V))
 V_SUBST_ = $(V_SUBST_$(AM_DEFAULT_VERBOSITY))