1
;;; This is asdf: Another System Definition Facility. $Revision: 1.4 $
3
;;; Feedback, bug reports, and patches are all welcome: please mail to
4
;;; <cclan-list@lists.sf.net>. But note first that the canonical
5
;;; source for asdf is presently the cCLan CVS repository at
6
;;; <URL:http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cclan/asdf/>
8
;;; If you obtained this copy from anywhere else, and you experience
9
;;; trouble using it, or find bugs, you may want to check at the
10
;;; location above for a more recent version (and for documentation
11
;;; and test files, if your copy came without them) before reporting
12
;;; bugs. There are usually two "supported" revisions - the CVS HEAD
13
;;; is the latest development version, whereas the revision tagged
14
;;; RELEASE may be slightly older but is considered `stable'
16
;;; Copyright (c) 2001-2003 Daniel Barlow and contributors
18
;;; Permission is hereby granted, free of charge, to any person obtaining
19
;;; a copy of this software and associated documentation files (the
20
;;; "Software"), to deal in the Software without restriction, including
21
;;; without limitation the rights to use, copy, modify, merge, publish,
22
;;; distribute, sublicense, and/or sell copies of the Software, and to
23
;;; permit persons to whom the Software is furnished to do so, subject to
24
;;; the following conditions:
26
;;; The above copyright notice and this permission notice shall be
27
;;; included in all copies or substantial portions of the Software.
29
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33
;;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34
;;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35
;;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
;;; the problem with writing a defsystem replacement is bootstrapping:
38
;;; we can't use defsystem to compile it. Hence, all in one file
41
(:export #:defsystem #:oos #:operate #:find-system #:run-shell-command
42
#:system-definition-pathname #:find-component ; miscellaneous
43
#:hyperdocumentation #:hyperdoc
45
#:compile-op #:load-op #:load-source-op #:test-system-version
47
#:operation ; operations
48
#:feature ; sort-of operation
49
#:version ; metaphorically sort-of an operation
51
#:input-files #:output-files #:perform ; operation methods
52
#:operation-done-p #:explain
54
#:component #:source-file
55
#:c-source-file #:cl-source-file #:java-source-file
65
#:module-components ; component accessors
67
#:component-relative-pathname
74
#:component-depends-on
77
#:system-long-description
82
#:operation-on-warnings
83
#:operation-on-failure
85
;#:*component-parent-pathname*
86
#:*system-definition-search-functions*
87
#:*central-registry* ; variables
88
#:*compile-file-warnings-behaviour*
89
#:*compile-file-failure-behaviour*
92
#:operation-error #:compile-failed #:compile-warned #:compile-error
93
#:error-component #:error-operation
94
#:system-definition-error
97
#:circular-dependency ; errors
106
(error "The author of this file habitually uses #+nil to comment out forms. But don't worry, it was unlikely to work in the New Implementation of Lisp anyway")
111
(defvar *asdf-revision* (let* ((v "$Revision: 1.4 $")
112
(colon (or (position #\: v) -1))
113
(dot (position #\. v)))
115
(list (parse-integer v :start (1+ colon)
117
(parse-integer v :start (1+ dot)
120
(defvar *compile-file-warnings-behaviour* :warn)
121
(defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
123
(defvar *verbose-out* nil)
125
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128
(defmacro aif (test then &optional else)
129
`(let ((it ,test)) (if it ,then ,else)))
131
(defun pathname-sans-name+type (pathname)
132
"Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
133
and NIL NAME and TYPE components"
134
(make-pathname :name nil :type nil :defaults pathname))
136
(define-modify-macro appendf (&rest args)
137
append "Append onto list")
139
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
140
;; classes, condiitons
142
(define-condition system-definition-error (error) ()
143
;; [this use of :report should be redundant, but unfortunately it's not.
144
;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
145
;; over print-object; this is always conditions::%print-condition for
146
;; condition objects, which in turn does inheritance of :report options at
147
;; run-time. fortunately, inheritance means we only need this kludge here in
148
;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
149
#+cmu (:report print-object))
151
(define-condition formatted-system-definition-error (system-definition-error)
152
((format-control :initarg :format-control :reader format-control)
153
(format-arguments :initarg :format-arguments :reader format-arguments))
154
(:report (lambda (c s)
155
(apply #'format s (format-control c) (format-arguments c)))))
157
(define-condition circular-dependency (system-definition-error)
158
((components :initarg :components :reader circular-dependency-components)))
160
(define-condition missing-component (system-definition-error)
161
((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
162
(version :initform nil :reader missing-version :initarg :version)
163
(parent :initform nil :reader missing-parent :initarg :parent)))
165
(define-condition missing-dependency (missing-component)
166
((required-by :initarg :required-by :reader missing-required-by)))
168
(define-condition operation-error (error)
169
((component :reader error-component :initarg :component)
170
(operation :reader error-operation :initarg :operation))
171
(:report (lambda (c s)
172
(format s "~@<erred while invoking ~A on ~A~@:>"
173
(error-operation c) (error-component c)))))
174
(define-condition compile-error (operation-error) ())
175
(define-condition compile-failed (compile-error) ())
176
(define-condition compile-warned (compile-error) ())
178
(defclass component ()
179
((name :accessor component-name :initarg :name :documentation
180
"Component name: designator for a string composed of portable pathname characters")
181
(version :accessor component-version :initarg :version)
182
(original-depends-on :accessor component-original-depends-on :initarg :original-depends-on :initform nil)
183
(in-order-to :initform nil :initarg :in-order-to)
185
(do-first :initform nil :initarg :do-first)
186
;; methods defined using the "inline" style inside a defsystem form:
187
;; need to store them somewhere so we can delete them when the system
189
(inline-methods :accessor component-inline-methods :initform nil)
190
(parent :initarg :parent :initform nil :reader component-parent)
191
;; no direct accessor for pathname, we do this as a method to allow
192
;; it to default in funky ways if not supplied
193
(relative-pathname :initarg :pathname)
194
(operation-times :initform (make-hash-table )
195
:accessor component-operation-times)
196
;; XXX we should provide some atomic interface for updating the
197
;; component properties
198
(properties :accessor component-properties :initarg :properties
201
;;;; methods: conditions
203
(defmethod print-object ((c missing-dependency) s)
204
(format s "~@<~A, required by ~A~@:>"
205
(call-next-method c nil) (missing-required-by c)))
207
(defun sysdef-error (format &rest arguments)
208
(error 'formatted-system-definition-error :format-control format :format-arguments arguments))
210
;;;; methods: components
212
(defmethod print-object ((c missing-component) s)
213
(format s "~@<component ~S not found~
214
~@[ or does not match version ~A~]~
218
(when (missing-parent c)
219
(component-name (missing-parent c)))))
221
(defgeneric component-system (component)
222
(:documentation "Find the top-level system containing COMPONENT"))
224
(defmethod component-system ((component component))
225
(aif (component-parent component)
226
(component-system it)
229
(defmethod print-object ((c component) stream)
230
(print-unreadable-object (c stream :type t :identity t)
232
(prin1 (component-name c) stream))))
234
(defclass module (component)
235
((components :initform nil :accessor module-components :initarg :components)
236
;; what to do if we can't satisfy a dependency of one of this module's
237
;; components. This allows a limited form of conditional processing
238
(if-component-dep-fails :initform :fail
239
:accessor module-if-component-dep-fails
240
:initarg :if-component-dep-fails)
241
(default-component-class :accessor module-default-component-class
242
:initform 'cl-source-file :initarg :default-component-class)))
244
(defgeneric component-pathname (component)
245
(:documentation "Extracts the pathname applicable for a particular component."))
247
(defun component-parent-pathname (component)
248
(aif (component-parent component)
249
(component-pathname it)
250
*default-pathname-defaults*))
252
(defgeneric component-relative-pathname (component)
253
(:documentation "Extracts the relative pathname applicable for a particular component."))
255
(defmethod component-relative-pathname ((component module))
256
(or (slot-value component 'relative-pathname)
258
:directory `(:relative ,(component-name component))
259
:host (pathname-host (component-parent-pathname component)))))
261
(defmethod component-pathname ((component component))
262
(let ((*default-pathname-defaults* (component-parent-pathname component)))
263
(merge-pathnames (component-relative-pathname component))))
265
(defgeneric component-property (component property))
267
(defmethod component-property ((c component) property)
268
(cdr (assoc property (slot-value c 'properties) :test #'equal)))
270
(defgeneric (setf component-property) (new-value component property))
272
(defmethod (setf component-property) (new-value (c component) property)
273
(let ((a (assoc property (slot-value c 'properties) :test #'equal)))
275
(setf (cdr a) new-value)
276
(setf (slot-value c 'properties)
277
(acons property new-value (slot-value c 'properties))))))
279
(defclass system (module)
280
((description :accessor system-description :initarg :description)
282
:accessor system-long-description :initarg :long-description)
283
(author :accessor system-author :initarg :author)
284
(maintainer :accessor system-maintainer :initarg :maintainer)
285
(licence :accessor system-licence :initarg :licence)))
287
;;; version-satisfies
289
;;; with apologies to christophe rhodes ...
290
(defun split (string &optional max (ws '(#\Space #\Tab)))
291
(flet ((is-ws (char) (find char ws)))
293
(let ((list nil) (start 0) (words 0) end)
295
(when (and max (>= words (1- max)))
296
(return (cons (subseq string start) list)))
297
(setf end (position-if #'is-ws string :start start))
298
(push (subseq string start end) list)
300
(unless end (return list))
301
(setf start (1+ end)))))))
303
(defgeneric version-satisfies (component version))
305
(defmethod version-satisfies ((c component) version)
306
(unless (and version (slot-boundp c 'version))
307
(return-from version-satisfies t))
308
(let ((x (mapcar #'parse-integer
309
(split (component-version c) nil '(#\.))))
310
(y (mapcar #'parse-integer
311
(split version nil '(#\.)))))
312
(labels ((bigger (x y)
315
((> (car x) (car y)) t)
317
(bigger (cdr x) (cdr y))))))
318
(and (= (car x) (car y))
319
(or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
321
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
324
(defvar *defined-systems* (make-hash-table :test 'equal))
325
(defun coerce-name (name)
327
(component (component-name name))
328
(symbol (string-downcase (symbol-name name)))
330
(t (sysdef-error "~@<invalid component designator ~A~@:>" name))))
332
;;; for the sake of keeping things reasonably neat, we adopt a
333
;;; convention that functions in this list are prefixed SYSDEF-
335
(defvar *system-definition-search-functions*
336
'(sysdef-central-registry-search))
338
(defun system-definition-pathname (system)
339
(some (lambda (x) (funcall x system))
340
*system-definition-search-functions*))
342
(defvar *central-registry*
343
'(*default-pathname-defaults*
344
#+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
345
#+nil "telent:asdf;systems;"))
347
(defun sysdef-central-registry-search (system)
348
(let ((name (coerce-name system)))
350
(dolist (dir *central-registry*)
351
(let* ((defaults (eval dir))
354
:defaults defaults :version :newest
355
:name name :type "asd" :case :local))))
356
(if (and file (probe-file file))
360
(defun find-system (name &optional (error-p t))
361
(let* ((name (coerce-name name))
362
(in-memory (gethash name *defined-systems*))
363
(on-disk (system-definition-pathname name)))
366
(< (car in-memory) (file-write-date on-disk))))
367
(let ((*package* (make-package (gensym #.(package-name *package*))
369
(format *verbose-out*
370
"~&~@<; ~@;loading system definition from ~A into ~A~@:>~%"
371
;; FIXME: This wants to be (ENOUGH-NAMESTRING
372
;; ON-DISK), but CMUCL barfs on that.
376
(let ((in-memory (gethash name *defined-systems*)))
378
(progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
380
(if error-p (error 'missing-component :requires name))))))
382
(defun register-system (name system)
383
(format *verbose-out* "~&~@<; ~@;registering ~A as ~A~@:>~%" system name)
384
(setf (gethash (coerce-name name) *defined-systems*)
385
(cons (get-universal-time) system)))
387
(defun system-registered-p (name)
388
(gethash (coerce-name name) *defined-systems*))
390
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391
;;; finding components
393
(defgeneric find-component (module name &optional version)
394
(:documentation "Finds the component with name NAME present in the
395
MODULE module; if MODULE is nil, then the component is assumed to be a
398
(defmethod find-component ((module module) name &optional version)
399
(if (slot-boundp module 'components)
400
(let ((m (find name (module-components module)
401
:test #'equal :key #'component-name)))
402
(if (and m (version-satisfies m version)) m))))
405
;;; a component with no parent is a system
406
(defmethod find-component ((module (eql nil)) name &optional version)
407
(let ((m (find-system name nil)))
408
(if (and m (version-satisfies m version)) m)))
410
;;; component subclasses
412
(defclass source-file (component) ())
414
(defclass cl-source-file (source-file) ())
415
(defclass c-source-file (source-file) ())
416
(defclass java-source-file (source-file) ())
417
(defclass static-file (source-file) ())
418
(defclass doc-file (static-file) ())
419
(defclass html-file (doc-file) ())
421
(defgeneric source-file-type (component system))
422
(defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
423
(defmethod source-file-type ((c c-source-file) (s module)) "c")
424
(defmethod source-file-type ((c java-source-file) (s module)) "java")
425
(defmethod source-file-type ((c html-file) (s module)) "html")
426
(defmethod source-file-type ((c static-file) (s module)) nil)
428
(defmethod component-relative-pathname ((component source-file))
429
(let* ((*default-pathname-defaults* (component-parent-pathname component))
432
:name (component-name component)
433
:type (source-file-type component
434
(component-system component)))))
435
(if (slot-value component 'relative-pathname)
437
(slot-value component 'relative-pathname)
441
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
444
;;; one of these is instantiated whenever (operate ) is called
446
(defclass operation ()
447
((forced :initform nil :initarg :force :accessor operation-forced)
448
(original-initargs :initform nil :initarg :original-initargs
449
:accessor operation-original-initargs)
450
(visited-nodes :initform nil :accessor operation-visited-nodes)
451
(visiting-nodes :initform nil :accessor operation-visiting-nodes)
452
(parent :initform nil :initarg :parent :accessor operation-parent)))
454
(defmethod print-object ((o operation) stream)
455
(print-unreadable-object (o stream :type t :identity t)
457
(prin1 (operation-original-initargs o) stream))))
459
(defmethod shared-initialize :after ((operation operation) slot-names
462
(declare (ignore slot-names force))
463
;; empty method to disable initarg validity checking
466
(defgeneric perform (operation component))
467
(defgeneric operation-done-p (operation component))
468
(defgeneric explain (operation component))
469
(defgeneric output-files (operation component))
470
(defgeneric input-files (operation component))
472
(defun node-for (o c)
473
(cons (class-name (class-of o)) c))
475
(defgeneric operation-ancestor (operation)
476
(:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
478
(defmethod operation-ancestor ((operation operation))
479
(aif (operation-parent operation)
480
(operation-ancestor it)
484
(defun make-sub-operation (c o dep-c dep-o)
485
(let* ((args (copy-list (operation-original-initargs o)))
486
(force-p (getf args :force)))
487
;; note explicit comparison with T: any other non-NIL force value
488
;; (e.g. :recursive) will pass through
489
(cond ((and (null (component-parent c))
490
(null (component-parent dep-c))
492
(when (eql force-p t)
493
(setf (getf args :force) nil))
494
(apply #'make-instance dep-o
496
:original-initargs args args))
497
((subtypep (type-of o) dep-o)
500
(apply #'make-instance dep-o
501
:parent o :original-initargs args args)))))
504
(defgeneric visit-component (operation component data))
506
(defmethod visit-component ((o operation) (c component) data)
507
(unless (component-visited-p o c)
508
(push (cons (node-for o c) data)
509
(operation-visited-nodes (operation-ancestor o)))))
511
(defgeneric component-visited-p (operation component))
513
(defmethod component-visited-p ((o operation) (c component))
514
(assoc (node-for o c)
515
(operation-visited-nodes (operation-ancestor o))
518
(defgeneric (setf visiting-component) (new-value operation component))
520
(defmethod (setf visiting-component) (new-value operation component)
521
;; MCL complains about unused lexical variables
522
(declare (ignorable new-value operation component)))
524
(defmethod (setf visiting-component) (new-value (o operation) (c component))
525
(let ((node (node-for o c))
526
(a (operation-ancestor o)))
528
(pushnew node (operation-visiting-nodes a) :test 'equal)
529
(setf (operation-visiting-nodes a)
530
(remove node (operation-visiting-nodes a) :test 'equal)))))
532
(defgeneric component-visiting-p (operation component))
534
(defmethod component-visiting-p ((o operation) (c component))
535
(let ((node (cons o c)))
536
(member node (operation-visiting-nodes (operation-ancestor o))
539
(defgeneric component-depends-on (operation component))
541
(defmethod component-depends-on ((o operation) (c component))
542
(cdr (assoc (class-name (class-of o))
543
(slot-value c 'in-order-to))))
545
(defgeneric component-self-dependencies (operation component))
547
(defmethod component-self-dependencies ((o operation) (c component))
548
(let ((all-deps (component-depends-on o c)))
549
(remove-if-not (lambda (x)
550
(member (component-name c) (cdr x) :test #'string=))
553
(defmethod input-files ((operation operation) (c component))
554
(let ((parent (component-parent c))
555
(self-deps (component-self-dependencies operation c)))
557
(mapcan (lambda (dep)
558
(destructuring-bind (op name) dep
559
(output-files (make-instance op)
560
(find-component parent name))))
562
;; no previous operations needed? I guess we work with the
563
;; original source file, then
564
(list (component-pathname c)))))
566
(defmethod input-files ((operation operation) (c module)) nil)
568
(defmethod operation-done-p ((o operation) (c component))
569
(let ((out-files (output-files o c))
570
(in-files (input-files o c)))
571
(cond ((and (not in-files) (not out-files))
572
;; arbitrary decision: an operation that uses nothing to
573
;; produce nothing probably isn't doing much
578
(component-operation-times c))))
582
(mapcar #'file-write-date in-files)) 0)))))
586
(every #'probe-file out-files)
587
(> (apply #'min (mapcar #'file-write-date out-files))
588
(apply #'max (mapcar #'file-write-date in-files)) ))))))
590
;;; So you look at this code and think "why isn't it a bunch of
591
;;; methods". And the answer is, because standard method combination
592
;;; runs :before methods most->least-specific, which is back to front
593
;;; for our purposes. And CLISP doesn't have non-standard method
594
;;; combinations, so let's keep it simple and aspire to portability
596
(defgeneric traverse (operation component))
597
(defmethod traverse ((operation operation) (c component))
599
(labels ((do-one-dep (required-op required-c required-v)
600
(let* ((dep-c (or (find-component
602
;; XXX tacky. really we should build the
603
;; in-order-to slot with canonicalized
604
;; names instead of coercing this late
605
(coerce-name required-c) required-v)
606
(error 'missing-dependency :required-by c
608
:requires required-c)))
609
(op (make-sub-operation c operation dep-c required-op)))
610
(traverse op dep-c)))
612
(cond ((eq op 'feature)
613
(or (member (car dep) *features*)
614
(error 'missing-dependency :required-by c
615
:requires (car dep) :version nil)))
619
(assert (string-equal
620
(symbol-name (first d))
623
(do-one-dep op (second d) (third d))))
625
(appendf forced (do-one-dep op d nil)))))))))
626
(aif (component-visited-p operation c)
627
(return-from traverse
628
(if (cdr it) (list (cons 'pruned-op c)) nil)))
630
(if (component-visiting-p operation c)
631
(error 'circular-dependency :components (list c)))
632
(setf (visiting-component operation c) t)
633
(loop for (required-op . deps) in (component-depends-on operation c)
634
do (do-dep required-op deps))
637
(when (typep c 'module)
638
(let ((at-least-one nil)
641
(loop for kid in (module-components c)
643
(appendf forced (traverse operation kid ))
644
(missing-dependency (condition)
645
(if (eq (module-if-component-dep-fails c) :fail)
647
(setf error condition))
650
(setf at-least-one t))))
651
(when (and (eq (module-if-component-dep-fails c) :try-next)
655
;; now the thing itself
656
(when (or forced module-ops
657
(not (operation-done-p operation c))
658
(let ((f (operation-forced (operation-ancestor operation))))
659
(and f (or (not (consp f))
660
(member (component-name
661
(operation-ancestor operation))
662
(mapcar #'coerce-name f)
664
(let ((do-first (cdr (assoc (class-name (class-of operation))
665
(slot-value c 'do-first)))))
666
(loop for (required-op . deps) in do-first
667
do (do-dep required-op deps)))
668
(setf forced (append (delete 'pruned-op forced :key #'car)
669
(delete 'pruned-op module-ops :key #'car)
670
(list (cons operation c))))))
671
(setf (visiting-component operation c) nil)
672
(visit-component operation c (and forced t))
676
(defmethod perform ((operation operation) (c source-file))
678
"~@<required method PERFORM not implemented ~
679
for operation ~A, component ~A~@:>"
680
(class-of operation) (class-of c)))
682
(defmethod perform ((operation operation) (c module))
685
(defmethod explain ((operation operation) (component component))
686
(format *verbose-out* "~&;;; ~A on ~A~%" operation component))
690
(defclass compile-op (operation)
691
((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
692
(system-p :initarg :system-p :accessor compile-op-system-p :initform nil)
693
(on-warnings :initarg :on-warnings :accessor operation-on-warnings
694
:initform *compile-file-warnings-behaviour*)
695
(on-failure :initarg :on-failure :accessor operation-on-failure
696
:initform *compile-file-failure-behaviour*)))
698
(defmethod perform :before ((operation compile-op) (c source-file))
699
(map nil #'ensure-directories-exist (output-files operation c)))
701
(defmethod perform :after ((operation operation) (c component))
702
(setf (gethash (type-of operation) (component-operation-times c))
703
(get-universal-time)))
705
;;; perform is required to check output-files to find out where to put
706
;;; its answers, in case it has been overridden for site policy
707
(defmethod perform ((operation compile-op) (c cl-source-file))
708
#-:broken-fasl-loader
709
(let ((source-file (component-pathname c))
710
(output-file (car (output-files operation c))))
711
(multiple-value-bind (output warnings-p failure-p)
712
(compile-file source-file
713
:output-file output-file
714
:system-p (compile-op-system-p operation))
715
;(declare (ignore output))
717
(case (operation-on-warnings operation)
719
"~@<COMPILE-FILE warned while performing ~A on ~A.~@:>"
721
(:error (error 'compile-warned :component c :operation operation))
724
(case (operation-on-failure operation)
726
"~@<COMPILE-FILE failed while performing ~A on ~A.~@:>"
728
(:error (error 'compile-failed :component c :operation operation))
731
(error 'compile-error :component c :operation operation)))))
733
(defmethod output-files ((operation compile-op) (c cl-source-file))
734
#-:broken-fasl-loader (list (compile-file-pathname (component-pathname c)))
735
#+:broken-fasl-loader (list (component-pathname c)))
737
(defmethod perform ((operation compile-op) (c static-file))
740
(defmethod output-files ((operation compile-op) (c static-file))
745
(defclass load-op (operation) ())
747
(defmethod perform ((o load-op) (c cl-source-file))
748
(mapcar #'load (input-files o c)))
750
(defmethod perform ((operation load-op) (c static-file))
752
(defmethod operation-done-p ((operation load-op) (c static-file))
755
(defmethod output-files ((o operation) (c component))
758
(defmethod component-depends-on ((operation load-op) (c component))
759
(cons (list 'compile-op (component-name c))
764
(defclass load-source-op (operation) ())
766
(defmethod perform ((o load-source-op) (c cl-source-file))
767
(let ((source (component-pathname c)))
768
(setf (component-property c 'last-loaded-as-source)
770
(get-universal-time)))))
772
(defmethod perform ((operation load-source-op) (c static-file))
775
(defmethod output-files ((operation load-source-op) (c component))
778
;;; FIXME: we simply copy load-op's dependencies. this is Just Not Right.
779
(defmethod component-depends-on ((o load-source-op) (c component))
780
(let ((what-would-load-op-do (cdr (assoc 'load-op
781
(slot-value c 'in-order-to)))))
782
(mapcar (lambda (dep)
783
(if (eq (car dep) 'load-op)
784
(cons 'load-source-op (cdr dep))
786
what-would-load-op-do)))
788
(defmethod operation-done-p ((o load-source-op) (c source-file))
789
(if (or (not (component-property c 'last-loaded-as-source))
790
(> (file-write-date (component-pathname c))
791
(component-property c 'last-loaded-as-source)))
794
(defclass test-op (operation) ())
796
(defmethod perform ((operation test-op) (c component))
799
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
800
;;; invoking operations
802
(defun operate (operation-class system &rest args)
803
(let* ((op (apply #'make-instance operation-class
804
:original-initargs args args))
806
(if (getf args :verbose t)
808
(make-broadcast-stream)))
809
(system (if (typep system 'component) system (find-system system)))
810
(steps (traverse op system)))
811
(with-compilation-unit ()
812
(loop for (op . component) in steps do
815
(progn (perform op component)
820
(format s "~@<Retry performing ~S on ~S.~@:>"
826
"~@<Continue, treating ~S on ~S as ~
827
having been successful.~@:>"
829
(setf (gethash (type-of op)
830
(component-operation-times component))
831
(get-universal-time))
834
(defun oos (&rest args)
835
"Alias of OPERATE function"
836
(apply #'operate args))
838
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841
(defun remove-keyword (key arglist)
842
(labels ((aux (key arglist)
843
(cond ((null arglist) nil)
844
((eq key (car arglist)) (cddr arglist))
845
(t (cons (car arglist) (cons (cadr arglist)
847
key (cddr arglist))))))))
850
(defmacro defsystem (name &body options)
851
(destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
852
(let ((component-options (remove-keyword :class options)))
854
;; system must be registered before we parse the body, otherwise
855
;; we recur when trying to find an existing system of the same name
856
;; to reuse options (e.g. pathname) from
857
(let ((s (system-registered-p ',name)))
858
(cond ((and s (eq (type-of (cdr s)) ',class))
859
(setf (car s) (get-universal-time)))
862
(sysdef-error "Cannot redefine the existing system ~A with a different class" s)
864
(change-class (cdr s) ',class))
866
(register-system (quote ,name)
867
(make-instance ',class :name ',name)))))
868
(parse-component-form nil (apply
870
:module (coerce-name ',name)
873
(pathname-sans-name+type
874
(resolve-symlinks *load-truename*))
875
*default-pathname-defaults*)
876
',component-options))))))
879
(defun class-for-type (parent type)
882
(or (find-symbol (symbol-name type) *package*)
883
(find-symbol (symbol-name type) #.(package-name *package*)))
887
(or (module-default-component-class parent)
888
(find-class 'cl-source-file)))
889
(sysdef-error "~@<don't recognize component type ~A~@:>" type))))
891
(defun maybe-add-tree (tree op1 op2 c)
892
"Add the node C at /OP1/OP2 in TREE, unless it's there already.
893
Returns the new tree (which probably shares structure with the old one)"
894
(let ((first-op-tree (assoc op1 tree)))
897
(aif (assoc op2 (cdr first-op-tree))
898
(if (find c (cdr it))
900
(setf (cdr it) (cons c (cdr it))))
901
(setf (cdr first-op-tree)
902
(acons op2 (list c) (cdr first-op-tree))))
904
(acons op1 (list (list op2 c)) tree))))
906
(defun union-of-dependencies (&rest deps)
907
(let ((new-tree nil))
909
(dolist (op-tree dep)
910
(dolist (op (cdr op-tree))
913
(maybe-add-tree new-tree (car op-tree) (car op) c))))))
917
(defun remove-keys (key-names args)
918
(loop for ( name val ) on args by #'cddr
919
unless (member (symbol-name name) key-names
920
:key #'symbol-name :test 'equal)
921
append (list name val)))
923
(defvar *serial-depends-on*)
925
(defun parse-component-form (parent options)
927
(type name &rest rest &key
928
;; the following list of keywords is reproduced below in the
929
;; remove-keys form. important to keep them in sync
930
components pathname default-component-class
931
perform explain output-files operation-done-p
932
depends-on serial in-order-to
934
&allow-other-keys) options
935
(check-component-input type name depends-on components in-order-to)
936
(let* ((other-args (remove-keys
937
'(components pathname default-component-class
938
perform explain output-files operation-done-p
939
depends-on serial in-order-to)
942
(or (find-component parent name)
943
(make-instance (class-for-type parent type)))))
944
(when (boundp '*serial-depends-on*)
946
(concatenate 'list *serial-depends-on* depends-on)))
947
(apply #'reinitialize-instance
949
:name (coerce-name name)
952
:original-depends-on depends-on
954
(when (typep ret 'module)
955
(setf (module-default-component-class ret)
956
(or default-component-class
957
(and (typep parent 'module)
958
(module-default-component-class parent))))
959
(let ((*serial-depends-on* nil))
960
(setf (module-components ret)
961
(loop for c-form in components
962
for c = (parse-component-form ret c-form)
965
do (push (component-name c) *serial-depends-on*)))))
967
(setf (slot-value ret 'in-order-to)
968
(union-of-dependencies
970
`((compile-op (compile-op ,@depends-on))
971
(load-op (load-op ,@depends-on))))
972
(slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
974
(loop for (n v) in `((perform ,perform) (explain ,explain)
975
(output-files ,output-files)
976
(operation-done-p ,operation-done-p))
978
;; this is inefficient as most of the stored
979
;; methods will not be for this particular gf n
980
;; But this is hardly performance-critical
981
(lambda (m) (remove-method (symbol-function n) m))
982
(component-inline-methods ret))
984
do (destructuring-bind (op qual (o c) &body body) v
986
(eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
988
(component-inline-methods ret))))
991
(defun check-component-input (type name depends-on components in-order-to)
992
"A partial test of the values of a component."
993
(unless (listp depends-on)
994
(sysdef-error-component ":depends-on must be a list."
995
type name depends-on))
996
(unless (listp components)
997
(sysdef-error-component ":components must be NIL or a list of components."
998
type name components))
999
(unless (and (listp in-order-to) (listp (car in-order-to)))
1000
(sysdef-error-component ":in-order-to must be NIL or a list of components."
1001
type name in-order-to)))
1003
(defun sysdef-error-component (msg type name value)
1004
(sysdef-error (concatenate 'string msg
1005
"~&The value specified for ~(~A~) ~A is ~W")
1008
(defun resolve-symlinks (path)
1009
#-allegro (truename path)
1010
#+allegro (excl:pathname-resolve-symbolic-links path)
1015
;;; run-shell-command functions for other lisp implementations will be
1016
;;; gratefully accepted, if they do the same thing. If the docstring
1017
;;; is ambiguous, send a bug report
1019
(defun run-shell-command (control-string &rest args)
1020
"Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
1021
synchronously execute the result using a Bourne-compatible shell, with
1022
output to *verbose-out*. Returns the shell's exit code."
1023
(let ((command (apply #'format nil control-string args)))
1024
(format *verbose-out* "; $ ~A~%" command)
1026
(sb-impl::process-exit-code
1030
:input nil :output *verbose-out*))
1033
(ext:process-exit-code
1037
:input nil :output *verbose-out*))
1040
(excl:run-shell-command command :input nil :output *verbose-out*)
1043
(system:call-system-showing-output
1045
:shell-type "/bin/sh"
1046
:output-stream *verbose-out*)
1048
#+clisp ;XXX not exactly *verbose-out*, I know
1049
(ext:run-shell-command command :output :terminal :wait t)
1053
(ccl:external-process-status
1054
(ccl:run-program "/bin/sh" (list "-c" command)
1055
:input nil :output *verbose-out*
1057
#+ecl ;; courtesy of Juan Jose Garcia Ripoll
1059
#-(or openmcl clisp lispworks allegro scl cmu sbcl ecl)
1060
(error "RUN-SHELL-PROGRAM not implemented for this Lisp")
1064
(defgeneric hyperdocumentation (package name doc-type))
1065
(defmethod hyperdocumentation ((package symbol) name doc-type)
1066
(hyperdocumentation (find-package package) name doc-type))
1068
(defun hyperdoc (name doc-type)
1069
(hyperdocumentation (symbol-package name) name doc-type))
1072
(pushnew :asdf *features*)
1075
(eval-when (:compile-toplevel :load-toplevel :execute)
1076
(when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
1077
(pushnew :sbcl-hooks-require *features*)))
1079
#+(and sbcl sbcl-hooks-require)
1081
(defun module-provide-asdf (name)
1082
(handler-bind ((style-warning #'muffle-warning))
1083
(let* ((*verbose-out* (make-broadcast-stream))
1084
(system (asdf:find-system name nil)))
1086
(asdf:operate 'asdf:load-op name)
1090
'(merge-pathnames "systems/"
1091
(truename (sb-ext:posix-getenv "SBCL_HOME")))
1095
'(merge-pathnames "site-systems/"
1096
(truename (sb-ext:posix-getenv "SBCL_HOME")))
1100
'(merge-pathnames ".sbcl/systems/"
1101
(user-homedir-pathname))
1104
(pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))
1106
;; Hook into ECL's require/provide
1109
(defun module-provide-asdf (name)
1110
(handler-bind ((style-warning #'muffle-warning))
1111
(let* ((*verbose-out* (make-broadcast-stream))
1112
(system (asdf:find-system name nil)))
1114
(asdf:operate 'asdf:load-op name)
1116
#+win32 (push '("asd" . si::load-source) si::*load-hooks*)
1117
(pushnew 'module-provide-asdf ext:*module-provider-functions*))