1 ;;; This is asdf: Another System Definition Facility. 1.79
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 #: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
73 #:component-depends-on
76 #:system-long-description
81 #:operation-on-warnings
82 #:operation-on-failure
84 ;#:*component-parent-pathname*
85 #:*system-definition-search-functions*
86 #:*central-registry* ; variables
87 #:*compile-file-warnings-behaviour*
88 #:*compile-file-failure-behaviour*
91 #:operation-error #:compile-failed #:compile-warned #:compile-error
92 #:error-component #:error-operation
93 #:system-definition-error
96 #:circular-dependency ; errors
105 (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")
110 (defvar *asdf-revision* (let* ((v "1.79")
111 (colon (or (position #\: v) -1))
112 (dot (position #\. v)))
114 (list (parse-integer v :start (1+ colon)
116 (parse-integer v :start (1+ dot)
119 (defvar *compile-file-warnings-behaviour* :warn)
120 (defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
122 (defvar *verbose-out* nil)
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 (defmacro aif (test then &optional else)
128 `(let ((it ,test)) (if it ,then ,else)))
130 (defun pathname-sans-name+type (pathname)
131 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
132 and NIL NAME and TYPE components"
133 (make-pathname :name nil :type nil :defaults pathname))
135 (define-modify-macro appendf (&rest args)
136 append "Append onto list")
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 ;; classes, condiitons
141 (define-condition system-definition-error (error) ()
142 ;; [this use of :report should be redundant, but unfortunately it's not.
143 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
144 ;; over print-object; this is always conditions::%print-condition for
145 ;; condition objects, which in turn does inheritance of :report options at
146 ;; run-time. fortunately, inheritance means we only need this kludge here in
147 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
148 #+cmu (:report print-object))
150 (define-condition formatted-system-definition-error (system-definition-error)
151 ((format-control :initarg :format-control :reader format-control)
152 (format-arguments :initarg :format-arguments :reader format-arguments))
153 (:report (lambda (c s)
154 (apply #'format s (format-control c) (format-arguments c)))))
156 (define-condition circular-dependency (system-definition-error)
157 ((components :initarg :components :reader circular-dependency-components)))
159 (define-condition missing-component (system-definition-error)
160 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
161 (version :initform nil :reader missing-version :initarg :version)
162 (parent :initform nil :reader missing-parent :initarg :parent)))
164 (define-condition missing-dependency (missing-component)
165 ((required-by :initarg :required-by :reader missing-required-by)))
167 (define-condition operation-error (error)
168 ((component :reader error-component :initarg :component)
169 (operation :reader error-operation :initarg :operation))
170 (:report (lambda (c s)
171 (format s (formatter "~@<erred while invoking ~A on ~A~@:>")
172 (error-operation c) (error-component c)))))
173 (define-condition compile-error (operation-error) ())
174 (define-condition compile-failed (compile-error) ())
175 (define-condition compile-warned (compile-error) ())
177 (defclass component ()
178 ((name :type string :accessor component-name :initarg :name :documentation
179 "Component name, restricted to portable pathname characters")
180 (version :accessor component-version :initarg :version)
181 (in-order-to :initform nil :initarg :in-order-to)
183 (do-first :initform nil :initarg :do-first)
184 ;; methods defined using the "inline" style inside a defsystem form:
185 ;; need to store them somewhere so we can delete them when the system
187 (inline-methods :accessor component-inline-methods :initform nil)
188 (parent :initarg :parent :initform nil :reader component-parent)
189 ;; no direct accessor for pathname, we do this as a method to allow
190 ;; it to default in funky ways if not supplied
191 (relative-pathname :initarg :pathname)
192 (operation-times :initform (make-hash-table )
193 :accessor component-operation-times)
194 ;; XXX we should provide some atomic interface for updating the
195 ;; component properties
196 (properties :accessor component-properties :initarg :properties
199 ;;;; methods: conditions
201 (defmethod print-object ((c missing-dependency) s)
202 (format s (formatter "~@<~A, required by ~A~@:>")
203 (call-next-method c nil)
204 (missing-required-by c)))
206 (defun sysdef-error (format &rest arguments)
207 (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
209 ;;;; methods: components
211 (defmethod print-object ((c missing-component) s)
212 (format s (formatter "~@<component ~S not found~
213 ~@[ or does not match version ~A~]~
217 (when (missing-parent c)
218 (component-name (missing-parent c)))))
220 (defgeneric component-system (component)
221 (:documentation "Find the top-level system containing COMPONENT"))
223 (defmethod component-system ((component component))
224 (aif (component-parent component)
225 (component-system it)
228 (defmethod print-object ((c component) stream)
229 (print-unreadable-object (c stream :type t :identity t)
231 (prin1 (component-name c) stream))))
233 (defclass module (component)
234 ((components :initform nil :accessor module-components :initarg :components)
235 ;; what to do if we can't satisfy a dependency of one of this module's
236 ;; components. This allows a limited form of conditional processing
237 (if-component-dep-fails :initform :fail
238 :accessor module-if-component-dep-fails
239 :initarg :if-component-dep-fails)
240 (default-component-class :accessor module-default-component-class
241 :initform 'cl-source-file :initarg :default-component-class)))
243 (defgeneric component-pathname (component)
244 (:documentation "Extracts the pathname applicable for a particular component."))
246 (defun component-parent-pathname (component)
247 (aif (component-parent component)
248 (component-pathname it)
249 *default-pathname-defaults*))
251 (defgeneric component-relative-pathname (component)
252 (:documentation "Extracts the relative pathname applicable for a particular component."))
254 (defmethod component-relative-pathname ((component module))
255 (or (slot-value component 'relative-pathname)
257 :directory `(:relative ,(component-name component))
258 :host (pathname-host (component-parent-pathname component)))))
260 (defmethod component-pathname ((component component))
261 (let ((*default-pathname-defaults* (component-parent-pathname component)))
262 (merge-pathnames (component-relative-pathname component))))
264 (defgeneric component-property (component property))
266 (defmethod component-property ((c component) property)
267 (cdr (assoc property (slot-value c 'properties) :test #'equal)))
269 (defgeneric (setf component-property) (new-value component property))
271 (defmethod (setf component-property) (new-value (c component) property)
272 (let ((a (assoc property (slot-value c 'properties) :test #'equal)))
274 (setf (cdr a) new-value)
275 (setf (slot-value c 'properties)
276 (acons property new-value (slot-value c 'properties))))))
278 (defclass system (module)
279 ((description :accessor system-description :initarg :description)
281 :accessor system-long-description :initarg :long-description)
282 (author :accessor system-author :initarg :author)
283 (maintainer :accessor system-maintainer :initarg :maintainer)
284 (licence :accessor system-licence :initarg :licence)))
286 ;;; version-satisfies
288 ;;; with apologies to christophe rhodes ...
289 (defun split (string &optional max (ws '(#\Space #\Tab)))
290 (flet ((is-ws (char) (find char ws)))
292 (let ((list nil) (start 0) (words 0) end)
294 (when (and max (>= words (1- max)))
295 (return (cons (subseq string start) list)))
296 (setf end (position-if #'is-ws string :start start))
297 (push (subseq string start end) list)
299 (unless end (return list))
300 (setf start (1+ end)))))))
302 (defgeneric version-satisfies (component version))
304 (defmethod version-satisfies ((c component) version)
305 (unless (and version (slot-boundp c 'version))
306 (return-from version-satisfies t))
307 (let ((x (mapcar #'parse-integer
308 (split (component-version c) nil '(#\.))))
309 (y (mapcar #'parse-integer
310 (split version nil '(#\.)))))
311 (labels ((bigger (x y)
314 ((> (car x) (car y)) t)
316 (bigger (cdr x) (cdr y))))))
317 (and (= (car x) (car y))
318 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
323 (defvar *defined-systems* (make-hash-table :test 'equal))
324 (defun coerce-name (name)
326 (component (component-name name))
327 (symbol (string-downcase (symbol-name name)))
329 (t (sysdef-error (formatter "~@<invalid component designator ~A~@:>")
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 (formatter "~&~@<; ~@;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*
384 (formatter "~&~@<; ~@;registering ~A as ~A~@:>~%") system name)
385 (setf (gethash (coerce-name name) *defined-systems*)
386 (cons (get-universal-time) system)))
388 (defun system-registered-p (name)
389 (gethash (coerce-name name) *defined-systems*))
391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
392 ;;; finding components
394 (defgeneric find-component (module name &optional version)
395 (:documentation "Finds the component with name NAME present in the
396 MODULE module; if MODULE is nil, then the component is assumed to be a
399 (defmethod find-component ((module module) name &optional version)
400 (if (slot-boundp module 'components)
401 (let ((m (find name (module-components module)
402 :test #'equal :key #'component-name)))
403 (if (and m (version-satisfies m version)) m))))
406 ;;; a component with no parent is a system
407 (defmethod find-component ((module (eql nil)) name &optional version)
408 (let ((m (find-system name nil)))
409 (if (and m (version-satisfies m version)) m)))
411 ;;; component subclasses
413 (defclass source-file (component) ())
415 (defclass cl-source-file (source-file) ())
416 (defclass c-source-file (source-file) ())
417 (defclass java-source-file (source-file) ())
418 (defclass static-file (source-file) ())
419 (defclass doc-file (static-file) ())
420 (defclass html-file (doc-file) ())
422 (defgeneric source-file-type (component system))
423 (defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
424 (defmethod source-file-type ((c c-source-file) (s module)) "c")
425 (defmethod source-file-type ((c java-source-file) (s module)) "java")
426 (defmethod source-file-type ((c html-file) (s module)) "html")
427 (defmethod source-file-type ((c static-file) (s module)) nil)
429 (defmethod component-relative-pathname ((component source-file))
430 (let* ((*default-pathname-defaults* (component-parent-pathname component))
433 :name (component-name component)
434 :type (source-file-type component
435 (component-system component)))))
436 (if (slot-value component 'relative-pathname)
438 (slot-value component 'relative-pathname)
442 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
445 ;;; one of these is instantiated whenever (operate ) is called
447 (defclass operation ()
448 ((forced :initform nil :initarg :force :accessor operation-forced)
449 (original-initargs :initform nil :initarg :original-initargs
450 :accessor operation-original-initargs)
451 (visited-nodes :initform nil :accessor operation-visited-nodes)
452 (visiting-nodes :initform nil :accessor operation-visiting-nodes)
453 (parent :initform nil :initarg :parent :accessor operation-parent)))
455 (defmethod print-object ((o operation) stream)
456 (print-unreadable-object (o stream :type t :identity t)
458 (prin1 (operation-original-initargs o) stream))))
460 (defmethod shared-initialize :after ((operation operation) slot-names
463 (declare (ignore slot-names force))
464 ;; empty method to disable initarg validity checking
467 (defgeneric perform (operation component))
468 (defgeneric operation-done-p (operation component))
469 (defgeneric explain (operation component))
470 (defgeneric output-files (operation component))
471 (defgeneric input-files (operation component))
473 (defun node-for (o c)
474 (cons (class-name (class-of o)) c))
476 (defgeneric operation-ancestor (operation)
477 (:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
479 (defmethod operation-ancestor ((operation operation))
480 (aif (operation-parent operation)
481 (operation-ancestor it)
485 (defun make-sub-operation (c o dep-c dep-o)
486 (let* ((args (copy-list (operation-original-initargs o)))
487 (force-p (getf args :force)))
488 ;; note explicit comparison with T: any other non-NIL force value
489 ;; (e.g. :recursive) will pass through
490 (cond ((and (null (component-parent c))
491 (null (component-parent dep-c))
493 (when (eql force-p t)
494 (setf (getf args :force) nil))
495 (apply #'make-instance dep-o
497 :original-initargs args args))
498 ((subtypep (type-of o) dep-o)
501 (apply #'make-instance dep-o
502 :parent o :original-initargs args args)))))
505 (defgeneric visit-component (operation component data))
507 (defmethod visit-component ((o operation) (c component) data)
508 (unless (component-visited-p o c)
509 (push (cons (node-for o c) data)
510 (operation-visited-nodes (operation-ancestor o)))))
512 (defgeneric component-visited-p (operation component))
514 (defmethod component-visited-p ((o operation) (c component))
515 (assoc (node-for o c)
516 (operation-visited-nodes (operation-ancestor o))
519 (defgeneric (setf visiting-component) (new-value operation component))
521 (defmethod (setf visiting-component) (new-value operation component)
522 ;; MCL complains about unused lexical variables
523 (declare (ignorable new-value operation component)))
525 (defmethod (setf visiting-component) (new-value (o operation) (c component))
526 (let ((node (node-for o c))
527 (a (operation-ancestor o)))
529 (pushnew node (operation-visiting-nodes a) :test 'equal)
530 (setf (operation-visiting-nodes a)
531 (remove node (operation-visiting-nodes a) :test 'equal)))))
533 (defgeneric component-visiting-p (operation component))
535 (defmethod component-visiting-p ((o operation) (c component))
536 (let ((node (cons o c)))
537 (member node (operation-visiting-nodes (operation-ancestor o))
540 (defgeneric component-depends-on (operation component))
542 (defmethod component-depends-on ((o operation) (c component))
543 (cdr (assoc (class-name (class-of o))
544 (slot-value c 'in-order-to))))
546 (defgeneric component-self-dependencies (operation component))
548 (defmethod component-self-dependencies ((o operation) (c component))
549 (let ((all-deps (component-depends-on o c)))
550 (remove-if-not (lambda (x)
551 (member (component-name c) (cdr x) :test #'string=))
554 (defmethod input-files ((operation operation) (c component))
555 (let ((parent (component-parent c))
556 (self-deps (component-self-dependencies operation c)))
558 (mapcan (lambda (dep)
559 (destructuring-bind (op name) dep
560 (output-files (make-instance op)
561 (find-component parent name))))
563 ;; no previous operations needed? I guess we work with the
564 ;; original source file, then
565 (list (component-pathname c)))))
567 (defmethod input-files ((operation operation) (c module)) nil)
569 (defmethod operation-done-p ((o operation) (c component))
570 (let ((out-files (output-files o c))
571 (in-files (input-files o c)))
572 (cond ((and (not in-files) (not out-files))
573 ;; arbitrary decision: an operation that uses nothing to
574 ;; produce nothing probably isn't doing much
579 (component-operation-times c))))
583 (mapcar #'file-write-date in-files)) 0)))))
587 (every #'probe-file out-files)
588 (> (apply #'min (mapcar #'file-write-date out-files))
589 (apply #'max (mapcar #'file-write-date in-files)) ))))))
591 ;;; So you look at this code and think "why isn't it a bunch of
592 ;;; methods". And the answer is, because standard method combination
593 ;;; runs :before methods most->least-specific, which is back to front
594 ;;; for our purposes. And CLISP doesn't have non-standard method
595 ;;; combinations, so let's keep it simple and aspire to portability
597 (defgeneric traverse (operation component))
598 (defmethod traverse ((operation operation) (c component))
600 (labels ((do-one-dep (required-op required-c required-v)
601 (let* ((dep-c (or (find-component
603 ;; XXX tacky. really we should build the
604 ;; in-order-to slot with canonicalized
605 ;; names instead of coercing this late
606 (coerce-name required-c) required-v)
607 (error 'missing-dependency :required-by c
609 :requires required-c)))
610 (op (make-sub-operation c operation dep-c required-op)))
611 (traverse op dep-c)))
613 (cond ((eq op 'feature)
614 (or (member (car dep) *features*)
615 (error 'missing-dependency :required-by c
616 :requires (car dep) :version nil)))
620 (assert (string-equal
621 (symbol-name (first d))
624 (do-one-dep op (second d) (third d))))
626 (appendf forced (do-one-dep op d nil)))))))))
627 (aif (component-visited-p operation c)
628 (return-from traverse
629 (if (cdr it) (list (cons 'pruned-op c)) nil)))
631 (if (component-visiting-p operation c)
632 (error 'circular-dependency :components (list c)))
633 (setf (visiting-component operation c) t)
634 (loop for (required-op . deps) in (component-depends-on operation c)
635 do (do-dep required-op deps))
638 (when (typep c 'module)
639 (let ((at-least-one nil)
642 (loop for kid in (module-components c)
644 (appendf forced (traverse operation kid ))
645 (missing-dependency (condition)
646 (if (eq (module-if-component-dep-fails c) :fail)
648 (setf error condition))
651 (setf at-least-one t))))
652 (when (and (eq (module-if-component-dep-fails c) :try-next)
656 ;; now the thing itself
657 (when (or forced module-ops
658 (not (operation-done-p operation c))
659 (let ((f (operation-forced (operation-ancestor operation))))
660 (and f (or (not (consp f))
661 (member (component-name
662 (operation-ancestor operation))
663 (mapcar #'coerce-name f)
665 (let ((do-first (cdr (assoc (class-name (class-of operation))
666 (slot-value c 'do-first)))))
667 (loop for (required-op . deps) in do-first
668 do (do-dep required-op deps)))
669 (setf forced (append (delete 'pruned-op forced :key #'car)
670 (delete 'pruned-op module-ops :key #'car)
671 (list (cons operation c))))))
672 (setf (visiting-component operation c) nil)
673 (visit-component operation c (and forced t))
677 (defmethod perform ((operation operation) (c source-file))
679 (formatter "~@<required method PERFORM not implemented~
680 for operation ~A, component ~A~@:>")
681 (class-of operation) (class-of c)))
683 (defmethod perform ((operation operation) (c module))
686 (defmethod explain ((operation operation) (component component))
687 (format *verbose-out* "~&;;; ~A on ~A~%"
688 operation component))
692 (defclass compile-op (operation)
693 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
694 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
695 :initform *compile-file-warnings-behaviour*)
696 (on-failure :initarg :on-failure :accessor operation-on-failure
697 :initform *compile-file-failure-behaviour*)))
699 (defmethod perform :before ((operation compile-op) (c source-file))
700 (map nil #'ensure-directories-exist (output-files operation c)))
702 (defmethod perform :after ((operation operation) (c component))
703 (setf (gethash (type-of operation) (component-operation-times c))
704 (get-universal-time)))
706 ;;; perform is required to check output-files to find out where to put
707 ;;; its answers, in case it has been overridden for site policy
708 (defmethod perform ((operation compile-op) (c cl-source-file))
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 ;(declare (ignore output))
716 (case (operation-on-warnings operation)
718 (formatter "~@<COMPILE-FILE warned while ~
719 performing ~A on ~A.~@:>")
721 (:error (error 'compile-warned :component c :operation operation))
724 (case (operation-on-failure operation)
726 (formatter "~@<COMPILE-FILE failed while ~
727 performing ~A on ~A.~@:>")
729 (:error (error 'compile-failed :component c :operation operation))
732 (error 'compile-error :component c :operation operation)))))
734 (defmethod output-files ((operation compile-op) (c cl-source-file))
735 (list (compile-file-pathname (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)
821 (formatter "~@<Retry performing ~S on ~S.~@:>")
827 (formatter "~@<Continue, treating ~S on ~S as ~
828 having been successful.~@:>")
830 (setf (gethash (type-of op)
831 (component-operation-times component))
832 (get-universal-time))
835 (defun oos (&rest args)
836 "Alias of OPERATE function"
837 (apply #'operate args))
839 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
842 (defun remove-keyword (key arglist)
843 (labels ((aux (key arglist)
844 (cond ((null arglist) nil)
845 ((eq key (car arglist)) (cddr arglist))
846 (t (cons (car arglist) (cons (cadr arglist)
848 key (cddr arglist))))))))
851 (defmacro defsystem (name &body options)
852 (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
853 (let ((component-options (remove-keyword :class options)))
855 ;; system must be registered before we parse the body, otherwise
856 ;; we recur when trying to find an existing system of the same name
857 ;; to reuse options (e.g. pathname) from
858 (let ((s (system-registered-p ',name)))
859 (cond ((and s (eq (type-of (cdr s)) ',class))
860 (setf (car s) (get-universal-time)))
863 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
865 (change-class (cdr s) ',class))
867 (register-system (quote ,name)
868 (make-instance ',class :name ',name)))))
869 (parse-component-form nil (apply
871 :module (coerce-name ',name)
874 (pathname-sans-name+type
875 (resolve-symlinks *load-truename*))
876 *default-pathname-defaults*)
877 ',component-options))))))
880 (defun class-for-type (parent type)
881 (let ((class (find-class
882 (or (find-symbol (symbol-name type) *package*)
883 (find-symbol (symbol-name type) #.*package*)) nil)))
886 (or (module-default-component-class parent)
887 (find-class 'cl-source-file)))
888 (sysdef-error (formatter "~@<don't recognize component type ~A~@:>")
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)
953 (when (typep ret 'module)
954 (setf (module-default-component-class ret)
955 (or default-component-class
956 (and (typep parent 'module)
957 (module-default-component-class parent))))
958 (let ((*serial-depends-on* nil))
959 (setf (module-components ret)
960 (loop for c-form in components
961 for c = (parse-component-form ret c-form)
964 do (push (component-name c) *serial-depends-on*)))))
966 (setf (slot-value ret 'in-order-to)
967 (union-of-dependencies
969 `((compile-op (compile-op ,@depends-on))
970 (load-op (load-op ,@depends-on))))
971 (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
973 (loop for (n v) in `((perform ,perform) (explain ,explain)
974 (output-files ,output-files)
975 (operation-done-p ,operation-done-p))
977 ;; this is inefficient as most of the stored
978 ;; methods will not be for this particular gf n
979 ;; But this is hardly performance-critical
980 (lambda (m) (remove-method (symbol-function n) m))
981 (component-inline-methods ret))
983 do (destructuring-bind (op qual (o c) &body body) v
985 (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
987 (component-inline-methods ret))))
990 (defun check-component-input (type name depends-on components in-order-to)
991 "A partial test of the values of a component."
992 (unless (listp depends-on)
993 (sysdef-error-component ":depends-on must be a list."
994 type name depends-on))
995 (unless (listp components)
996 (sysdef-error-component ":components must be NIL or a list of components."
997 type name components))
998 (unless (and (listp in-order-to) (listp (car in-order-to)))
999 (sysdef-error-component ":in-order-to must be NIL or a list of components."
1000 type name in-order-to)))
1002 (defun sysdef-error-component (msg type name value)
1003 (sysdef-error (concatenate 'string msg
1004 "~&The value specified for ~(~A~) ~A is ~W")
1007 (defun resolve-symlinks (path)
1008 #-allegro (truename path)
1009 #+allegro (excl:pathname-resolve-symbolic-links path)
1014 ;;; run-shell-command functions for other lisp implementations will be
1015 ;;; gratefully accepted, if they do the same thing. If the docstring
1016 ;;; is ambiguous, send a bug report
1018 (defun run-shell-command (control-string &rest args)
1019 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
1020 synchronously execute the result using a Bourne-compatible shell, with
1021 output to *verbose-out*. Returns the shell's exit code."
1022 (let ((command (apply #'format nil control-string args)))
1023 (format *verbose-out* "; $ ~A~%" command)
1025 (sb-impl::process-exit-code
1029 :input nil :output *verbose-out*))
1032 (ext:process-exit-code
1036 :input nil :output *verbose-out*))
1039 (excl:run-shell-command command :input nil :output *verbose-out*)
1042 (system:call-system-showing-output
1044 :shell-type "/bin/sh"
1045 :output-stream *verbose-out*)
1047 #+clisp ;XXX not exactly *verbose-out*, I know
1048 (ext:run-shell-command command :output :terminal :wait t)
1052 (ccl:external-process-status
1053 (ccl:run-program "/bin/sh" (list "-c" command)
1054 :input nil :output *verbose-out*
1057 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
1058 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
1062 (defgeneric hyperdocumentation (package name doc-type))
1063 (defmethod hyperdocumentation ((package symbol) name doc-type)
1064 (hyperdocumentation (find-package package) name doc-type))
1066 (defun hyperdoc (name doc-type)
1067 (hyperdocumentation (symbol-package name) name doc-type))
1070 (pushnew :asdf *features*)
1073 (eval-when (:compile-toplevel :load-toplevel :execute)
1074 (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
1075 (pushnew :sbcl-hooks-require *features*)))
1077 #+(and sbcl sbcl-hooks-require)
1079 (defun module-provide-asdf (name)
1080 (handler-bind ((style-warning #'muffle-warning))
1081 (let* ((*verbose-out* (make-broadcast-stream))
1082 (system (asdf:find-system name nil)))
1084 (asdf:operate 'asdf:load-op name)
1088 '(merge-pathnames "systems/"
1089 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1093 '(merge-pathnames "site-systems/"
1094 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1098 '(merge-pathnames ".sbcl/systems/"
1099 (user-homedir-pathname))
1102 (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))