changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / autogen.lisp

changeset 283: 8b385a72c75f
parent: 8f6b1cd443fe
child: 71ac00213ae3
author: Richard Westhaver <ellis@rwest.io>
date: Mon, 17 Jun 2024 20:07:44 +0000
permissions: -rw-r--r--
description: fix
1 ;;; autogen.lisp --- Auto-generate CC Infrastructure
2 
3 ;; This script must be ran with a compliant CC lisp core image from a complian
4 ;; CC lisp compiler. The easiest way to get started is by running the
5 ;; 'bootstrap.sh' script first which will download these for you into the
6 ;; local 'STASH' directory and run this script automatically.
7 
8 #|
9 # download pre-compiled binaries and run autogen.lisp
10 ./bootstrap.sh
11 
12 # or run manually with local lisp runtime and core
13 sbcl --core $LISP_HOME/user.core --script autogen.lisp \
14  --eval "(infra/autogen:autogen)"
15 |#
16 
17 ;;; Code:
18 (in-package :std-user)
19 
20 (defpkg :infra/autogen
21  (:use :cl :skel :log :std/named-readtables
22  :dat/json :dat/sxp :net/fetch :net/util
23  :cli/progress :cli/ansi :cli/ed :cli/prompt
24  :cli/shell :std/hash-table :std/alien :std/macs
25  :std/fmt)
26  (:export :autogen))
27 
28 (in-package :infra/autogen)
29 (in-readtable :shell)
30 ;;; Vars
31 (defparameter *profile* (uiop:read-file-forms
32  (if-let ((profile (sb-posix:getenv "INFRA_PROFILE")))
33  profile
34  #P"default.sxp")))
35 (defparameter *core* sb-ext:*core-pathname*)
36 (defparameter *host* (uiop:read-file-forms
37  (let ((hcfg (format nil "~a.sxp" (sb-unix:unix-gethostname))))
38  (unless (probe-file hcfg)
39  (print #0$./check.sh$#))
40  hcfg)))
41 (defparameter *host-env* (let ((table (make-hash-table :test 'equal))
42  (keys (list "STASH" "STORE" "DIST" "PACKY_URL" "VC_URL" "INSTALL_PREFIX"
43  "CC" "AR" "HG" "GIT" "LISP" "RUST" "LD" "SHELL" "DEV" "DEV_HOME"
44  "DEV_ID" "WORKER" "WORKER_ID" "WORKER_HOME" "CARGO_HOME" "RUSTUP_HOME"
45  "LISP_HOME" "INFRA_PROFILE")))
46  (dolist (k keys table)
47  (setf (gethash k table) (sb-posix:getenv k)))))
48 
49 ;;; Utils
50 (defun gethost (k) (getf *host* k))
51 (defun getprofile (k) (getf *profile* k))
52 
53 (defun getenv (k) (gethash *host-env* k))
54 
55 (defun setenv (k v)
56  (sb-posix:setenv k v 1)
57  (setf (gethash k *host-env*) v))
58 
59 ;;; Config
60 (defun init-profile ()
61  (let ((stash (getprofile :stash))
62  (cc (getprofile :cc)))
63  (if-let ((stash (probe-file stash)))
64  (setenv "STASH" (namestring stash))
65  (error "STASH not found: ~A" stash))
66  (if-let ((cc (cli:find-exe cc)))
67  (setenv "CC" (namestring cc))
68  (error "STASH not found: ~A" cc))))
69 
70 ;;; Build
71 (defun make-default ()
72  (std/thread:wait-for-threads
73  (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :repos)))))
74  (vc:run-hg-command "clone" (list ".stash/src/core.hg" ".stash/src/core"))
75  (vc:run-hg-command "clone" (list ".stash/src/home.hg" ".stash/src/home"))
76  (vc:run-hg-command "clone" (list ".stash/src/etc.hg" ".stash/src/etc")))
77 
78 (defun make-pods ()
79  (vc:run-hg-command "clone" (list ".stash/src/pod.hg" ".stash/src/pod"))
80  (std/thread:wait-for-threads
81  (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box)))
82  (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker))))))
83 
84 (defun make-boxes ()
85  (vc:run-hg-command "clone" (list ".stash/src/box.hg" ".stash/src/box")))
86 
87 (defun make-org ()
88  (vc:run-hg-command "clone" (list ".stash/src/org.hg" ".stash/src/org")))
89 
90 (defun autogen ()
91  "Auto-generate the INFRA system."
92  (info! "starting autogen")
93  (in-readtable :shell)
94  (terpri)
95  (init-profile)
96  (init-skel-vars)
97  (setq *skel-project* (find-skelfile *default-pathname-defaults* :load t))
98  (unless (probe-file #p".stash")
99  (sk-call* *skel-project* :bootstrap))
100  ;; print host, env, profile
101  (format t "core: ~A~%" *core*)
102  (terpri)
103  (println "host:")
104  (loop for (k v) on *host* by 'cddr
105  do (format t " ~A = ~A~%" k v))
106  (println "env:")
107  (loop for k being the hash-key
108  using (hash-value v) of *host-env*
109  do (format t " ~A = ~:A~%" k v))
110  (println "profile:")
111  (loop for (k v) on *profile* by 'cddr
112  do (format t " ~A = ~A~%" k v))
113  (make-default))
114 
115 ;;; *host*
116 ;; The host profile is generated automatically by 'check.sh'. After running
117 ;; the script you'll have a file HOST.sxp.
118 
119 ;;; *profile*
120 ;; The default profile is defined in 'default.sxp'. You can use that as a base
121 ;; configuration and override it with INFRA_PROFILE