-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.lisp
52 lines (43 loc) · 1.65 KB
/
version.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#+xcvb
(module
(:build-depends-on ("driver")
:depends-on ("/asdf")))
;;; Versioning
(in-package :xcvb-driver)
(defun get-xcvb-directory ()
(asdf:system-source-directory :xcvb))
(defun xcvb-git-checkout-p ()
(asdf::probe-file* (asdf::subpathname (get-xcvb-directory) ".git/")))
(defun xcvb-version-file ()
(asdf::subpathname (get-xcvb-directory) "version.text"))
(defun get-xcvb-version-from-git ()
(and (xcvb-git-checkout-p)
(run-program
(format nil "cd ~A ; git describe --tags --dirty=+" (get-xcvb-directory))
:output '(:string :stripped t))))
(defun get-xcvb-version-from-file ()
(with-open-file (s (xcvb-version-file) :direction :input :if-does-not-exist nil)
(read s)))
(defun get-xcvb-version ()
(or
(get-xcvb-version-from-git)
(get-xcvb-version-from-file)
(error "Cannot determine XCVB version: neither .git/ nor version.text in ~A"
(get-xcvb-directory))))
(defun make-xcvb-version-file (&optional file)
(let ((version (get-xcvb-version-from-git))
(file (asdf::merge-pathnames* file (xcvb-version-file))))
(unless version
(error "Could not get XCVB version from git"))
(with-open-file (s file :direction :output
:if-does-not-exist :create :if-exists :rename-and-delete)
(format s "~
;;; This file was automatically generated by (xcvb::make-xcvb-version-file)
;;; from a git checkout. It is only consulted in a gitless code checkout.
;;; Edit manually at your own risk.
~S~%"
version))
(when (>= (or *xcvb-verbosity* 5) 5)
(format *error-output* "~&Saved version ~A in version file ~A~%"
version (truename file)))
(values)))