|
25 | 25 | ;; ---------------------------------------------------------------------------- |
26 | 26 | ;; Version. Pull from git when available, otherwise fall back. |
27 | 27 |
|
28 | | -(defparameter +rlgl-version+ |
29 | | - (or (ignore-errors |
30 | | - (string-trim '(#\Newline #\Space) |
31 | | - (with-output-to-string (legit:*git-output*) |
32 | | - (legit:git-describe :tags t)))) |
33 | | - "unknown")) |
| 28 | +;; +RLGL-VERSION+ is the base version from rlgl.asd at load time, and is |
| 29 | +;; updated to include git information (tag/hash, "+dirty" suffix) when the |
| 30 | +;; standalone binary is built via program-op. |
| 31 | +(version-string:define-version-parameter +rlgl-version+ :rlgl) |
34 | 32 |
|
35 | 33 | ;; ---------------------------------------------------------------------------- |
36 | 34 | ;; Installation root. This is the directory containing the recog.d |
37 | | -;; report-recognition scripts. Resolved at runtime from (in order): |
38 | | -;; the --root option, the RLGL_ROOT environment variable, the directory |
39 | | -;; of the running executable (if it contains recog.d), or the current |
40 | | -;; working directory. |
| 35 | +;; report-recognition scripts. At runtime we pick the first of a list of |
| 36 | +;; candidate directories that actually contains recog.d: the --root option, |
| 37 | +;; the RLGL_ROOT environment variable, the directory of the running |
| 38 | +;; executable (running from a build tree), the data directory of a system |
| 39 | +;; install (e.g. /usr/share/rlgl when the binary is /usr/bin/rlgl), and |
| 40 | +;; finally the current working directory. |
41 | 41 |
|
42 | 42 | (defvar *rlgl-root* nil) |
43 | 43 |
|
44 | 44 | (defun rlgl-root () |
45 | 45 | *rlgl-root*) |
46 | 46 |
|
47 | 47 | (defun directory-has-recog.d? (dir) |
48 | | - (and dir (fad:directory-exists-p (merge-pathnames "recog.d/" dir)))) |
| 48 | + (and dir (ignore-errors (fad:directory-exists-p (merge-pathnames "recog.d/" dir))))) |
| 49 | + |
| 50 | +(defun rlgl-root-candidates (override) |
| 51 | + (let ((argv0-dir (ignore-errors |
| 52 | + (uiop:pathname-directory-pathname |
| 53 | + (uiop:ensure-absolute-pathname (uiop:argv0) (uiop:getcwd)))))) |
| 54 | + (remove nil |
| 55 | + (list |
| 56 | + (and override (uiop:ensure-directory-pathname override)) |
| 57 | + (let ((env (uiop:getenv "RLGL_ROOT"))) |
| 58 | + (and env (uiop:ensure-directory-pathname env))) |
| 59 | + argv0-dir |
| 60 | + ;; /usr/bin/rlgl -> /usr/share/rlgl, /usr/local/bin -> /usr/local/share |
| 61 | + (and argv0-dir (merge-pathnames #p"../share/rlgl/" argv0-dir)) |
| 62 | + #p"/usr/share/rlgl/" |
| 63 | + #p"/usr/local/share/rlgl/" |
| 64 | + (uiop:getcwd))))) |
49 | 65 |
|
50 | 66 | (defun resolve-rlgl-root (&optional override) |
51 | 67 | "Determine and set *RLGL-ROOT*." |
52 | | - (let ((root |
53 | | - (or (and override (uiop:ensure-directory-pathname override)) |
54 | | - (let ((env (uiop:getenv "RLGL_ROOT"))) |
55 | | - (and env (uiop:ensure-directory-pathname env))) |
56 | | - (let ((argv0-dir (ignore-errors |
57 | | - (uiop:pathname-directory-pathname |
58 | | - (uiop:ensure-absolute-pathname |
59 | | - (uiop:argv0) (uiop:getcwd)))))) |
60 | | - (and (directory-has-recog.d? argv0-dir) argv0-dir)) |
61 | | - (uiop:getcwd)))) |
62 | | - (setf *rlgl-root* (namestring root)) |
63 | | - (unless (directory-has-recog.d? root) |
64 | | - (error "Can't find report recognizers (recog.d) under ~A.~%~ |
| 68 | + (let* ((candidates (rlgl-root-candidates override)) |
| 69 | + (root (find-if #'directory-has-recog.d? candidates))) |
| 70 | + (unless root |
| 71 | + (error "Can't find report recognizers (recog.d). Looked in:~%~{ ~A~%~}~ |
65 | 72 | Set RLGL_ROOT or pass --root to point at the rlgl installation directory." |
66 | | - *rlgl-root*)) |
67 | | - *rlgl-root*)) |
| 73 | + (mapcar #'namestring candidates))) |
| 74 | + (setf *rlgl-root* (namestring root)))) |
68 | 75 |
|
69 | 76 | ;; ---------------------------------------------------------------------------- |
70 | 77 | ;; Policy checkout directory. Policies are git repositories that we |
|
0 commit comments