changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / scripts/check.lisp

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