changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > infra / autogen.lisp

revision 271: cd797f4eb846
parent 269: 2e100f53d0d7
child 276: 8f6b1cd443fe
     1.1--- a/autogen.lisp	Sun Jun 16 15:02:42 2024 -0400
     1.2+++ b/autogen.lisp	Sun Jun 16 19:15:28 2024 -0400
     1.3@@ -1,6 +1,18 @@
     1.4-;;; autogen.lisp --- Setup the current directory for 
     1.5+;;; autogen.lisp --- Auto-generate CC Infrastructure
     1.6+
     1.7+;; This script must be ran with a compliant CC lisp core image from a complian
     1.8+;; CC lisp compiler. The easiest way to get started is by running the
     1.9+;; 'bootstrap.sh' script first which will download these for you into the
    1.10+;; local 'STASH' directory and run this script automatically.
    1.11 
    1.12-;; sbcl --core .stash/share/lisp/user.core --load autogen.lisp
    1.13+#|
    1.14+# download pre-compiled binaries and run autogen.lisp
    1.15+./bootstrap.sh 
    1.16+
    1.17+# or run manually with local lisp runtime and core
    1.18+sbcl --core $LISP_HOME/user.core --script autogen.lisp \
    1.19+     --eval "(infra/autogen:autogen)"
    1.20+|#
    1.21 
    1.22 ;;; Code:
    1.23 (in-package :std-user)
    1.24@@ -10,27 +22,22 @@
    1.25         :dat/json :dat/sxp :net/fetch :net/util
    1.26         :cli/progress :cli/ansi :cli/ed :cli/prompt
    1.27         :cli/shell :std/hash-table :std/alien :std/macs
    1.28-        :std/fmt))
    1.29+        :std/fmt)
    1.30+  (:export :autogen))
    1.31 
    1.32 (in-package :infra/autogen)
    1.33-
    1.34 (in-readtable :shell)
    1.35-
    1.36+;;; Vars
    1.37 (defparameter *profile* (uiop:read-file-forms
    1.38                          (if-let ((profile (sb-posix:getenv "INFRA_PROFILE")))
    1.39-                                 profile
    1.40-                                 #P"default.sxp")))
    1.41+                           profile
    1.42+                           #P"default.sxp")))
    1.43 (defparameter *core* sb-ext:*core-pathname*)
    1.44 (defparameter *host* (uiop:read-file-forms
    1.45                       (let ((hcfg (format nil "~a.sxp" (sb-unix:unix-gethostname))))
    1.46                         (unless (probe-file hcfg)
    1.47                           (print #0$./check.sh$#))
    1.48                         hcfg)))
    1.49-
    1.50-(defun gethost (k) (getf *host* k))
    1.51-(defun getprofile (k) (getf *profile* k))
    1.52-(init-skel-vars)
    1.53-(setq *skel-project* (find-skelfile *default-pathname-defaults* :load t))
    1.54 (defparameter *host-env* (let ((table (make-hash-table :test 'equal))
    1.55                                (keys (list "STASH" "STORE" "DIST" "PACKY_URL" "VC_URL" "INSTALL_PREFIX"
    1.56                                            "CC" "AR" "HG" "GIT" "LISP" "RUST" "LD" "SHELL" "DEV" "DEV_HOME"
    1.57@@ -38,20 +45,49 @@
    1.58                                            "LISP_HOME" "INFRA_PROFILE")))
    1.59                            (dolist (k keys table)
    1.60                              (setf (gethash k table) (sb-posix:getenv k)))))
    1.61+
    1.62+;;; Utils
    1.63+(defun gethost (k) (getf *host* k))
    1.64+(defun getprofile (k) (getf *profile* k))
    1.65+
    1.66 (defun getenv (k) (gethash *host-env* k))
    1.67 
    1.68-(defun build-default ()
    1.69-  (let ((comp-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :repos))))
    1.70-        (packy-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :packy-repos))))
    1.71-        (operator-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box))))
    1.72-        (worker-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker)))))
    1.73-    (std/thread:wait-for-threads
    1.74-     (list comp-builder packy-builder))))
    1.75+(defun setenv (k v)
    1.76+  (sb-posix:setenv k v 1)
    1.77+  (setf (gethash k *host-env*) v))
    1.78+
    1.79+;;; Config
    1.80+(defun init-profile ()
    1.81+  (let ((stash (getprofile :stash))
    1.82+        (cc (getprofile :cc)))
    1.83+    (if-let ((stash (probe-file stash)))
    1.84+      (setenv "STASH" (namestring stash))
    1.85+      (error "STASH not found: ~A" stash))
    1.86+    (if-let ((cc (cli:find-exe cc)))
    1.87+      (setenv "CC" (namestring cc))
    1.88+      (error "STASH not found: ~A" cc))))
    1.89+
    1.90+;;; Build
    1.91+(defun make-default ()
    1.92+  (std/thread:wait-for-threads
    1.93+   (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :repos)))
    1.94+         (sb-thread:make-thread (lambda () (sk-call* *skel-project* :packy-repos))))))
    1.95+
    1.96+(defun make-pods ()
    1.97+  (std/thread:wait-for-threads
    1.98+   (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box)))
    1.99+         (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker))))))
   1.100 
   1.101 (defun autogen ()
   1.102   "Auto-generate the INFRA system."
   1.103-  (info! "starting autogen.lisp" sb-ext:*core-pathname*)
   1.104+  (info! "starting autogen")
   1.105+  (in-readtable :shell)
   1.106   (terpri)
   1.107+  (init-profile)
   1.108+  (init-skel-vars)
   1.109+  (setq *skel-project* (find-skelfile *default-pathname-defaults* :load t))
   1.110+  (unless (probe-file #p".stash")
   1.111+    (sk-call* *skel-project* :bootstrap))
   1.112   ;; print host, env, profile
   1.113   (format t "core: ~A~%" *core*)
   1.114   (terpri)
   1.115@@ -65,8 +101,7 @@
   1.116   (println "profile:")
   1.117   (loop for (k v) on *profile* by 'cddr
   1.118         do (format t "  ~A = ~A~%" k v))
   1.119-
   1.120-  (build-default))
   1.121+  (make-default))
   1.122 
   1.123 ;;; *host*
   1.124 ;; The host profile is generated automatically by 'check.sh'. After running
   1.125@@ -75,12 +110,3 @@
   1.126 ;;; *profile*
   1.127 ;; The default profile is defined in 'default.sxp'. You can use that as a base
   1.128 ;; configuration and override it with INFRA_PROFILE
   1.129-
   1.130-;; (sb-ext:quit)
   1.131-
   1.132-(unless (probe-file #p".stash")
   1.133-  (sk-call* *skel-project* :bootstrap))
   1.134-
   1.135-;; (build-default)
   1.136-(autogen)
   1.137-