changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / autogen.lisp

changeset 276: 8f6b1cd443fe
parent: cd797f4eb846
child: 8b385a72c75f
author: Richard Westhaver <ellis@rwest.io>
date: Sun, 16 Jun 2024 21:13:25 -0400
permissions: -rw-r--r--
description: bump
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  (sb-thread:make-thread (lambda () (sk-call* *skel-project* :packy-repos)))))
75  (vc:run-hg-command "clone" (list ".stash/src/core.hg" ".stash/src/core"))
76  (vc:run-hg-command "clone" (list ".stash/src/home.hg" ".stash/src/home"))
77  (vc:run-hg-command "clone" (list ".stash/src/etc.hg" ".stash/src/etc")))
78 
79 (defun make-pods ()
80  (vc:run-hg-command "clone" (list ".stash/src/pod.hg" ".stash/src/pod"))
81  (std/thread:wait-for-threads
82  (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box)))
83  (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker))))))
84 
85 (defun make-boxes ()
86  (vc:run-hg-command "clone" (list ".stash/src/box.hg" ".stash/src/box")))
87 
88 (defun make-org ()
89  (vc:run-hg-command "clone" (list ".stash/src/org.hg" ".stash/src/org")))
90 
91 (defun autogen ()
92  "Auto-generate the INFRA system."
93  (info! "starting autogen")
94  (in-readtable :shell)
95  (terpri)
96  (init-profile)
97  (init-skel-vars)
98  (setq *skel-project* (find-skelfile *default-pathname-defaults* :load t))
99  (unless (probe-file #p".stash")
100  (sk-call* *skel-project* :bootstrap))
101  ;; print host, env, profile
102  (format t "core: ~A~%" *core*)
103  (terpri)
104  (println "host:")
105  (loop for (k v) on *host* by 'cddr
106  do (format t " ~A = ~A~%" k v))
107  (println "env:")
108  (loop for k being the hash-key
109  using (hash-value v) of *host-env*
110  do (format t " ~A = ~:A~%" k v))
111  (println "profile:")
112  (loop for (k v) on *profile* by 'cddr
113  do (format t " ~A = ~A~%" k v))
114  (make-default))
115 
116 ;;; *host*
117 ;; The host profile is generated automatically by 'check.sh'. After running
118 ;; the script you'll have a file HOST.sxp.
119 
120 ;;; *profile*
121 ;; The default profile is defined in 'default.sxp'. You can use that as a base
122 ;; configuration and override it with INFRA_PROFILE