changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / scripts/check.lisp

changeset 25: 30fa758d74b7
parent: 3491c1d1815d
child: 4e73da2d9c63
author: ellis <ellis@rwest.io>
date: Sun, 24 Dec 2023 13:37:49 -0500
permissions: -rwxr-xr-x
description: fixes
1 ;;; scripts/check.lisp --- check host features
2 
3 ;; This script runs some basic checks to ensure the host is ready for
4 ;; bootstrapping.
5 
6 ;;; Code:
7 #+quicklisp
8 (mapc (lambda (x) (unless (find-package x) (ql:quickload x)))
9  '(:cli :std :sb-alien :cli :log))
10 
11 (defpackage :infra/scripts/check
12  (:nicknames :check)
13  (:use :cl :std :sb-alien :cli :log)
14  (:export :main
15  :*results*
16  :check))
17 
18 (in-package :infra/scripts/check)
19 
20 (defvar *results* (make-hash-table :size 32 :test 'equal))
21 
22 (defparameter *library-path* (ld-library-path-list))
23 (defparameter *exec-path* (exec-path-list))
24 
25 (defun get-result (k) (gethash k *results*))
26 
27 (defun push-result (k &optional v)
28  (setf (gethash k *results*) v))
29 
30 (defmacro check-err (is-warn ctrl name)
31  `(if ,is-warn
32  (and
33  (warn 'simple-warning
34  :format-control ,ctrl
35  :format-arguments (list ,name))
36  (push-result ,name))
37  (error 'simple-program-error
38  :format-control ,ctrl
39  :format-arguments (list ,name))))
40 
41 (defun check-for-shared-lib (name &optional warn)
42  "Check for a shared library by loading it in the current session with dlopen.
43 
44 When WARN is non-nil, signal a warning instead of an error."
45  (if-let ((lib (ignore-errors (load-shared-object (format nil "lib~a.so" name)))))
46  (prog1
47  (push-result name lib)
48  (unload-shared-object lib))
49  (check-err warn "shared library missing: ~x" name)))
50 
51 (defun check-for-bin (name &optional warn)
52  (if-let ((exe (find-exe name)))
53  (push-result name exe)
54  (check-err warn "executable program missing: ~x" name)))
55 
56 (defun check-for-src (name)
57  (push-result name))
58 
59 (defun check-hostname () (push-result "hostname" (machine-instance)))
60 
61 (defun check-user () (push-result "user" (cons (sb-posix:getenv "USER") (user-homedir-pathname))))
62 
63 (defun check-system ()
64  (destructuring-bind (lisp version features)
65  (my-lisp-implementation)
66  (push-result "lisp" (list lisp version features)
67  #-sbcl (push-result "lisp" "unsupported")
68  #-sb-core-compression (println "WARNING: feature sb-core-compression disabled")
69  #-mark-region-gc (println "WARNING: feature mark-region-gc disabled")
70 )))
71 
72 (defun check-shell ()
73  (push-result "shell" (sb-posix:getenv "SHELL")))
74 
75 (defun check-display ()
76  (push-result "display" (sb-posix:getenv "DISPLAY")))
77 
78 (defun check-net ()
79  (push-result "net"))
80 
81 (defun check-cpu ()
82  (push-result "cpu" (machine-version)))
83 
84 (defmethod print-object ((object hash-table) stream)
85  (format stream "#HOST-FEATURES{~{~{~%(~a . ~a)~}~^ ~}}"
86  (loop for k being the hash-keys of *results*
87  using (hash-value v)
88  unless (null v)
89  collect (list k v))))
90 
91 (defun check (&optional warn)
92  "Check the host for required features."
93 
94  (setq *library-path* (ld-library-path-list)
95  *exec-path* (exec-path-list))
96 
97  (debug! (format nil "LD_LIBRARY_PATH: ~A~%" *library-path*))
98  (debug! (format nil "PATH: ~A~%" *exec-path*))
99  (check-system)
100  (check-user)
101  (check-net)
102  (check-hostname)
103  (check-cpu)
104  (check-shell)
105  (check-display)
106  (check-for-bin "sbcl" warn)
107  (check-for-bin "rustc" warn)
108  (check-for-bin "clang" warn)
109  (check-for-bin "gcc" warn)
110  (check-for-bin "emacs" warn)
111  ;; vcs
112  (check-for-bin "hg" warn)
113  (check-for-bin "git" warn)
114  ;; virt
115  (check-for-bin "podman" warn)
116 
117  (check-for-src "core")
118  ;; core dependencies
119  (check-for-shared-lib "rocksdb" warn)
120  (check-for-shared-lib "uring" warn)
121  (check-for-shared-lib "btrfs" warn)
122  (check-for-shared-lib "btrfsutil" warn)
123  (check-for-shared-lib "tree-sitter" warn)
124  ;; extras
125  (check-for-shared-lib "gtk-4" warn)
126  (check-for-shared-lib "blake3" warn)
127  (check-for-shared-lib "k" warn)
128  (check-for-shared-lib "cbqn" warn)
129  *results*)
130 
131 (defmain () (println (check)))