# HG changeset patch # User Richard Westhaver # Date 1722390856 14400 # Node ID d1c75054df03ae9e87758e17aee6c1ae61cb4846 # Parent 13a6c698a6dd4080a692018d0d898e4c65a0f281 added phases diff -r 13a6c698a6dd -r d1c75054df03 lisp/bin/skel.lisp --- a/lisp/bin/skel.lisp Mon Jul 29 21:42:21 2024 -0400 +++ b/lisp/bin/skel.lisp Tue Jul 30 21:54:16 2024 -0400 @@ -76,37 +76,37 @@ (defcmd skc-id (println (std:format-sxhash (obj/id:id (find-skelfile #P"." :load t))))) -(defun call-with-args (action) - (if (zerop *argc*) +(defun call-with-args (action args) + (if (null args) (sk-call *skel-project* action) - (mapcar (lambda (x) - (sk-call *skel-project* (print (keywordicate action '- (string-upcase x))))) - *args*))) + (mapc (lambda (x) + (sk-call *skel-project* (keywordicate action '- (string-upcase x)))) + args))) (defcmd skc-compile - (call-with-args :compile)) + (call-with-args :compile *args*)) (defcmd skc-build - (call-with-args :build)) + (call-with-args :build *args*)) (defcmd skc-dist - (call-with-args :dist)) + (call-with-args :dist *args*)) (defcmd skc-install - (call-with-args :install)) + (call-with-args :install *args*)) (defcmd skc-pack - (call-with-args :pack)) + (call-with-args :pack *args*)) (defcmd skc-unpack - (call-with-args :unpack)) + (call-with-args :unpack *args*)) (defcmd skc-bundle - (call-with-args :bundle)) + (call-with-args :bundle *args*)) (defcmd skc-unbundle - (call-with-args :unbundle)) + (call-with-args :unbundle *args*)) (defcmd skc-clean - (call-with-args :clean)) + (call-with-args :clean *args*)) (defcmd skc-test - (call-with-args :test)) + (call-with-args :test *args*)) (defcmd skc-bench - (call-with-args :bench)) + (call-with-args :bench *args*)) (defcmd skc-save - (call-with-args :save)) + (call-with-args :save *args*)) (defun sk-slot-case (sel) (std/string:string-case (sel :default (skel-simple-error "invalid slot")) @@ -121,6 +121,7 @@ (":components" (sk-components *skel-project*)) (":scripts" (sk-scripts *skel-project*)) (":rules" (sk-rules *skel-project*)) + (":phases" (hash-table-alist (sk-phases *skel-project*))) (":env" (sk-env *skel-project*)) (":bind" (sk-bind *skel-project*)) (":include" (sk-include *skel-project*)) diff -r 13a6c698a6dd -r d1c75054df03 lisp/lib/skel/core/obj.lisp --- a/lisp/lib/skel/core/obj.lisp Mon Jul 29 21:42:21 2024 -0400 +++ b/lisp/lib/skel/core/obj.lisp Tue Jul 30 21:54:16 2024 -0400 @@ -315,9 +315,9 @@ (mapcar (lambda (src) (if-let* ((sr (sk-find-rule src obj))) - ;; check if we need to rerun sources - (sk-make obj sr) - (warn! "unhandled source:" src "for rule:" rule))) + ;; check if we need to rerun sources + (sk-make obj sr) + (warn! "unhandled source:" src "for rule:" rule))) sources)) (sk-run rule)) rules) @@ -359,21 +359,25 @@ ;;; Project (defclass sk-project (skel sxp sk-meta) ((name :initarg :name :initform "" :type string) + (vc :initarg :vc :initform (make-sk-vc-meta *default-skel-vc-kind*) :type sk-vc-meta :accessor sk-vc) (src :initarg :src :type pathname :accessor sk-src) - (vc :initarg :vc :initform (make-sk-vc-meta *default-skel-vc-kind*) :type sk-vc-meta :accessor sk-vc) + (stash :initarg :stash :accessor sk-stash :type pathname) + (store :initarg :store :accessor sk-store :type pathname) + (components :initform #() :initarg :components :accessor sk-components :type (vector sk-component)) + (bind :initarg :bind :initform nil :accessor sk-bind :type list) + (env :initarg :env :initform nil :accessor sk-env :type list) + (phases :initarg :phases + :initform (make-hash-table) + :accessor sk-phases + :type hash-table) (rules :initarg :rules :initform (make-array 0 :element-type 'sk-rule :adjustable t) :accessor sk-rules :type (vector sk-rule)) - (components :initform #() :initarg :components :accessor sk-components :type (vector (cons keyword pathname))) - (bind :initarg :bind :initform nil :accessor sk-bind :type list) - (env :initarg :env :initform nil :accessor sk-env :type list) (scripts :initarg :scripts :initform (make-array 0 :element-type 'sk-script :adjustable t) :accessor sk-scripts :type (vector sk-script)) - (stash :initarg :stash :accessor sk-stash :type pathname) - (store :initarg :store :accessor sk-store :type pathname) (include :initarg :include :initform (make-array 0 :element-type 'pathname :adjustable t) :accessor sk-include @@ -396,6 +400,15 @@ (defun find-sk-symbol (s) (find-symbol* (symbol-name s) :skel/core/obj t)) +(defun %recipe-phase-p (form) + "Return non-nil if FORM looks like (:PHASE &BODY BODY)." + (and (listp form) (>= (length form) 2) (keywordp (car form)))) + +(defun sk-multi-recipe-p (recipe) + "Return T if RECIPE looks like a list of (:PHASE &BODY BODY)." + (when (consp recipe) + (every '%recipe-phase-p recipe))) + ;; ast -> obj (defmethod load-ast ((self sk-project)) ;; internal ast is never tagged @@ -417,21 +430,21 @@ (let ((*default-pathname-defaults* (make-pathname :defaults (namestring *skel-path*)))) (when (bound-string-p self 'stash) (setf (sk-stash self) (pathname (the simple-string (sk-stash self))))) (when (bound-string-p self 'store) (setf (sk-store self) (pathname (the simple-string (sk-store self))))) - ;; INCLUDE + ;; INCLUDE (when-let ((include (sk-include self))) - (setf (sk-include self) (map 'vector + (setf (sk-include self) (map 'vector ;; recursively load included projects (lambda (i) (load-ast (sk-read-file (make-instance 'sk-project) i))) - include))) - ;; COMPONENTS + include))) + ;; COMPONENTS (when (slot-boundp self 'components) - (setf (sk-components self) (map 'vector - (lambda (c) - (sk-load-component (car c) (pathname (cadr c)) (namestring *default-pathname-defaults*))) - (sk-components self))))) + (setf (sk-components self) (map 'vector + (lambda (c) + (sk-load-component (car c) (pathname (cadr c)) (namestring *default-pathname-defaults*))) + (sk-components self))))) ;; SCRIPTS (if (bound-string-p self 'scripts) (if-let* ((path (probe-file (pathname (the simple-string (sk-scripts self)))))) @@ -457,13 +470,29 @@ (list (cons (sb-int:keywordicate (car e)) (cadr e))))) env))) + ;; BIND ;; RULES (when-let ((rules (sk-rules self))) - (setf (sk-rules self) (map 'vector - (lambda (x) - (destructuring-bind (target source &rest recipe) x - (make-sk-rule target source recipe))) - rules))) + (setf (sk-rules self) + (coerce + (flatten + (mapcar + (lambda (x) + (destructuring-bind (target source &rest recipe) x + ;; TODO 2024-07-30: check for phases + (if (sk-multi-recipe-p recipe) + (flatten + (mapcar + (lambda (y) + (destructuring-bind (phase source &rest recipe) y + (let ((%target (keywordicate phase '- (string-upcase target)))) + (let ((ph (gethash phase (sk-phases self)))) + (setf (gethash phase (sk-phases self)) + (push (make-sk-rule %target source recipe) ph)))))) + recipe)) + (make-sk-rule target source recipe)))) + (coerce rules 'list))) + '(vector sk-rule)))) ;; VC (when-let ((vc (sk-vc self))) (etypecase vc diff -r 13a6c698a6dd -r d1c75054df03 lisp/lib/skel/core/pkg.lisp --- a/lisp/lib/skel/core/pkg.lisp Mon Jul 29 21:42:21 2024 -0400 +++ b/lisp/lib/skel/core/pkg.lisp Tue Jul 30 21:54:16 2024 -0400 @@ -73,7 +73,8 @@ :sk-user-config :sk-system-config :*skel-user-config* :*skel-system-config* :sk-src :sk-component :sk-components :sk-module - :sk-parent)) + :sk-parent + :sk-phases)) (defpackage :skel/core/util (:use :cl :std :skel/core/obj :skel/core/vars :skel/core/proto :dat/sxp :skel/core/err) diff -r 13a6c698a6dd -r d1c75054df03 skelfile --- a/skelfile Mon Jul 29 21:42:21 2024 -0400 +++ b/skelfile Tue Jul 30 21:54:16 2024 -0400 @@ -28,7 +28,8 @@ (build-tree-sitter-alien () #$cd lisp/ffi/tree-sitter && clang -g -O2 -Wall -Wno-unused-value -ltree-sitter -shared \ alien.c -o ../../../.stash/libtree-sitter-alien.so$#) - (install-tree-sitter-alien () #$cp .stash/libtree-sitter-alien.so /usr/local/lib/$#) + (tree-sitter-alien () + (:install #$cp .stash/libtree-sitter-alien.so /usr/local/lib/$#)) (psl.dat (%stash) (download "https://publicsuffix.org/list/public_suffix_list.dat" :output ".stash/psl.dat")) (parquet.thrift (%stash) @@ -43,45 +44,58 @@ :output ".stash/alltypes_plain.parquet")) ;; lisp (%stash () #$mkdir -pv .stash$#) - (build-rdb (%stash) (with-sbcl (:noinform t :quit t) - (ql:quickload :bin/rdb) - (asdf:make :bin/rdb)) - #$mv lisp/bin/rdb .stash/rdb$#) - (build-skel (%stash) (with-sbcl (:noinform t :quit t) - (ql:quickload :bin/skel) - (asdf:make :bin/skel)) - #$mv lisp/bin/skel .stash/skel$#) - (build-skel-gui (%stash) (with-sbcl (:noinform t :quit t) - (push :tools *features*) - (ql:quickload :bin/skel) - (asdf:make :bin/skel)) - #$mv lisp/bin/skel .stash/skel$#) - (build-organ (%stash) (with-sbcl (:noinform t :quit t) + (rdb (%stash) + (:build () + (with-sbcl (:noinform t :quit t) + (ql:quickload :bin/rdb) + (asdf:make :bin/rdb)) + #$mv lisp/bin/rdb .stash/rdb$#)) + (skel (%stash) + (:build () + (with-sbcl (:noinform t :quit t) + (ql:quickload :bin/skel) + (asdf:make :bin/skel)) + #$mv lisp/bin/skel .stash/skel$#) + (:build-gui () + (with-sbcl (:noinform t :quit t) + (push :tools *features*) + (ql:quickload :bin/skel) + (asdf:make :bin/skel)) + #$mv lisp/bin/skel .stash/skel$#) + (:install () #$install -C -m 755 .stash/skel /usr/local/bin/skel$#)) + (organ (%stash) + (:build () (with-sbcl (:noinform t :quit t) (ql:quickload :bin/organ) (asdf:make :bin/organ)) - #$mv lisp/bin/organ .stash/organ$#) - (build-homer (%stash) (with-sbcl (:noinform t :quit t) - (ql:quickload :bin/homer) - (asdf:make :bin/homer)) - #$mv lisp/bin/homer .stash/homer$#) - (build-packy (%stash) (with-sbcl (:noinform t :quit t) - (ql:quickload :bin/packy) - (asdf:make :bin/packy)) - #$mv lisp/bin/packy .stash/packy$#) + #$mv lisp/bin/organ .stash/organ$#)) + (homer (%stash) + (:build () (with-sbcl (:noinform t :quit t) + (ql:quickload :bin/homer) + (asdf:make :bin/homer)) + #$mv lisp/bin/homer .stash/homer$#)) + (packy (%stash) + (:build () (with-sbcl (:noinform t :quit t) + (ql:quickload :bin/packy) + (asdf:make :bin/packy)) + #$mv lisp/bin/packy .stash/packy$#)) (build (build-rdb build-skel build-organ build-homer build-packy)) (compile () #$./x.lisp compile$#) - (save-std () #$./x.lisp save std$#) - (save-prelude () #$./x.lisp save prelude$#) - (save-user () #$./x.lisp save user$#) - (save-infra () #$./x.lisp save infra$#) - (save-core () #$./x.lisp save core$#) - (save-tests () #$./x.lisp save tests$#) - (prelude-fasl () #$./x.lisp make prelude$#) - (user-fasl () #$./x.lisp make user$#) - (core-fasl () #$./x.lisp make core$#) - (tests-fasl () #$./x.lisp make core/tests$#) - (bench-fasl () #$./x.lisp make core/bench$#) - (fasl (core-fasl tests-fasl bench-fasl user-fasl prelude-fasl)) + (std () (:save () #$./x.lisp save std$#)) + (prelude () + (:save () #$./x.lisp save prelude$#) + (:compile () #$./x.lisp make prelude$#)) + (user () + (:save () #$./x.lisp save user$#) + (:compile () #$./x.lisp make user$#)) + (infra () (:save () #$./x.lisp save infra$#)) + (core () + (:save () #$./x.lisp save core$#) + (:compile () #$./x.lisp make core$#)) + (tests () + (:save () #$./x.lisp save tests$#) + (:compile () #$./x.lisp make core/tests$#)) + (bench () (:compile () #$./x.lisp make core/bench$#)) + (fasl (compile-core compile-tests compile-bench compile-user compile-prelude)) ;; rust (mailman () #$cd rust && cargo build -Z unstable-options --bin mailman --artifact-dir ../.stash/$#) (alik () #$cd rust && cargo build -Z unstable-options --bin alik --artifact-dir ../.stash/$#)