changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/skel/comp/asd.lisp

changeset 698: 96958d3eb5b0
parent: cc89b337384b
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; lib/skel/comp/asd.lisp --- ASDF Components
2 
3 ;; ASDF/PARSE-DEFSYSTEM may come in handy for testing.
4 
5 ;; The problem with ASD files is that they're read-only afaik - eg there's no
6 ;; 'write' methods implemented on ASD:SYSTEM objects. This makes it a bit
7 ;; tedious because we obviously want to transform SK-LISP-SYSTEM objects
8 ;; directly to SYSTEM, but also need to be able to write them out as discrete
9 ;; files for portability. Probably will end up violating all that is DRY and
10 ;; holy.
11 
12 ;;; Code:
13 (in-package :skel/comp/asd)
14 
15 (defclass sk-lisp-system (sk-mod asdf:system)
16  ;; these slots are inferred in ASDF:SYSTEM. Since we are primarily concerned
17  ;; with generating ASDF:SYSTEM definitions rather than parsing them we restore them here.
18  ((serial :initform nil :type boolean :accessor sk-lisp-system-serial)
19  (perform :initform nil :type list :accessor sk-lisp-system-perform)))
20 
21 (defun read-system-definitions (system)
22  (with-open-file (file (asdf:system-source-file system))
23  (loop for x = (read file nil)
24  while x
25  collect x)))
26 
27 (defun to-sk-system (system)
28  (let ((sys (change-class system 'sk-lisp-system)))
29  (setf (sk-lisp-system-serial sys) nil
30  (sk-lisp-system-perform sys) nil)
31  (id:update-id sys)
32  sys))
33 
34 (defmethod sk-convert ((self asdf:system))
35  (to-sk-system self))
36 
37 (defun find-sk-system (system)
38  (to-sk-system (asdf:find-system system)))
39 
40 (defun parse-sk-lisp-system (name path &optional opts)
41  (to-sk-system (asdf::parse-component-form nil (list* :system name :pathname path opts))))
42 
43 (defmethod sk-load ((self sk-lisp-system) &key force force-not verbose version)
44  (asdf:load-system self :force force :force-not force-not :verbose verbose :version version))
45 
46 (defmethod sk-load-component ((kind (eql :asd)) (form pathname) &optional (path *default-pathname-defaults*))
47  (declare (ignore kind))
48  (let* ((type (pathname-type form))
49  (name (namestring (if type (pathname-name form) form)))
50  (fname (if type form (make-pathname :name name :type "asd"))))
51  (parse-sk-lisp-system name (merge-pathnames fname path))))
52 
53 (defmethod sk-compile ((self sk-lisp-system) &key force force-not verbose version &allow-other-keys)
54  (asdf:compile-system self :force force :force-not force-not :verbose verbose :version version))
55 
56 (defun sk-write-asd-components (module)
57  (etypecase module
58  (asdf:file-component
59  `(,(keywordicate (string-upcase (asdf:file-type module)))
60  ,(pathname-name (asdf:component-relative-pathname module))
61  ,@(when-let ((x (asdf::component-if-feature module)))
62  `(:if-feature ,x))
63  ,@(when-let ((x (asdf::component-depends-on nil module)))
64  `(:depends-on ,x))))
65  (asdf:module
66  `(:module
67  ,(asdf:component-name module)
68  ,@(when-let ((x (asdf::component-if-feature module)))
69  `(:if-feature ,x))
70  ,@(when-let ((x (asdf::component-depends-on nil module)))
71  `(:depends-on ,x))
72  ,@(when-let ((x (asdf:module-components module)))
73  `(:components ,(mapcar #'sk-write-asd-components x)))))))
74 
75 (defmethod sk-write-file ((self sk-lisp-system) &key path)
76  (let ((name (asdf:component-name self)))
77  (with-open-file (s path
78  :direction :output
79  :if-does-not-exist :create)
80  (format s ";;; ASDF definition for system ~A" name)
81  (let ((*print-case* :downcase))
82  (pprint `(defsystem ,name
83  :class sk-lisp-system
84  ,@(when-let ((x (asdf:component-version self))) `(:version ,x))
85  ,@(when-let ((x (asdf:system-depends-on self))) `(:depends-on ,x))
86  ,@(when-let ((x (asdf:system-description self))) `(:description ,x))
87  ,@(when-let ((x (asdf:system-long-description self))) `(:long-description ,x))
88  ,@(when-let ((x (asdf:system-author self))) `(:author ,x))
89  ,@(when-let ((x (asdf:system-maintainer self))) `(:maintainer ,x))
90  ,@(when-let ((x (asdf:system-mailto self))) `(:mailto ,x))
91  ,@(when-let ((x (asdf::system-license self))) `(:license ,x))
92  ,@(when-let ((x (asdf:system-homepage self))) `(:homepage ,x))
93  ,@(when-let ((x (asdf:system-bug-tracker self))) `(:bug-tracker ,x))
94  ,@(when-let ((x (asdf:system-source-control self))) `(:source-control ,x))
95  ,@(when-let ((x (asdf::component-in-order-to self))) `(:in-order-to ,x))
96  ,@(when-let ((x (asdf::component-build-pathname self))) `(:build-pathname ,x))
97  ,@(when-let ((x (asdf::component-build-operation self))) `(:build-operation ,x))
98  ,@(when-let ((x (asdf::component-entry-point self))) `(:entry-point ,x))
99  ,@(when-let ((x (sk-lisp-system-perform self))) `(:perform ,x))
100  ,@(when-let ((x (sk-lisp-system-serial self))) `(:serial ,x))
101  :components ,(mapcar #'sk-write-asd-components
102  (asdf:module-components self)))
103  s)
104  (terpri s)))))
105 
106 ;; (sk-write-file (find-sk-system :obj) :path "test")
107 ;; (describe (parse-sk-lisp-system "skel" "/home/ellis/comp/core/lisp/lib/"))
108 
109 (defmethod sk-read-file ((self sk-lisp-system) path)
110  (parse-sk-lisp-system (pathname-name path) (pathname-directory path)))