1 ;;; This is asdf: Another System Definition Facility. 1.65
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
46 #:operation ; operations
47 #:feature ; sort-of operation
48 #:version ; metaphorically sort-of an operation
50 #:output-files #:perform ; operation methods
51 #:operation-done-p #:explain
53 #:component #:source-file
54 #:c-source-file #:cl-source-file #:java-source-file
64 #:module-components ; component accessors
66 #:component-relative-pathname
72 #:component-depends-on
74 ;#:*component-parent-pathname*
75 #:*central-registry* ; variables
77 #:operation-error #:compile-failed #:compile-warned #:compile-error
78 #:system-definition-error
81 #:circular-dependency ; errors
86 (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")
91 (defvar *asdf-revision* (let* ((v "1.65")
92 (colon (or (position #\: v) -1))
93 (dot (position #\. v)))
95 (list (parse-integer v :start (1+ colon)
97 (parse-integer v :start (1+ dot)
100 (defvar *compile-file-warnings-behaviour* :warn)
101 (defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 (defmacro aif (test then &optional else)
107 `(let ((it ,test)) (if it ,then ,else)))
109 (defun pathname-sans-name+type (pathname)
110 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
111 and NIL NAME and TYPE components"
112 (make-pathname :name nil :type nil :defaults pathname))
114 (define-modify-macro appendf (&rest args)
115 append "Append onto list")
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118 ;; classes, condiitons
120 (define-condition system-definition-error (error) ()
121 ;; [this use of :report should be redundant, but unfortunately it's not.
122 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
123 ;; over print-object; this is always conditions::%print-condition for
124 ;; condition objects, which in turn does inheritance of :report options at
125 ;; run-time. fortunately, inheritance means we only need this kludge here in
126 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
127 #+cmu (:report print-object))
129 (define-condition formatted-system-definition-error (system-definition-error)
130 ((format-control :initarg :format-control :reader format-control)
131 (format-arguments :initarg :format-arguments :reader format-arguments))
132 (:report (lambda (c s)
133 (apply #'format s (format-control c) (format-arguments c)))))
135 (define-condition circular-dependency (system-definition-error)
136 ((components :initarg :components :reader circular-dependency-components)))
138 (define-condition missing-component (system-definition-error)
139 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
140 (version :initform nil :reader missing-version :initarg :version)
141 (parent :initform nil :reader missing-parent :initarg :parent)))
143 (define-condition missing-dependency (missing-component)
144 ((required-by :initarg :required-by :reader missing-required-by)))
146 (define-condition operation-error (error)
147 ((component :reader error-component :initarg :component)
148 (operation :reader error-operation :initarg :operation))
149 (:report (lambda (c s)
150 (format s (formatter "~@<erred while invoking ~A on ~A~@:>")
151 (error-operation c) (error-component c)))))
152 (define-condition compile-error (operation-error) ())
153 (define-condition compile-failed (compile-error) ())
154 (define-condition compile-warned (compile-error) ())
156 (defclass component ()
157 ((name :type string :accessor component-name :initarg :name :documentation
158 "Component name, restricted to portable pathname characters")
159 (version :accessor component-version :initarg :version)
160 (in-order-to :initform nil :initarg :in-order-to)
162 (do-first :initform nil :initarg :do-first)
163 ;; methods defined using the "inline" style inside a defsystem form:
164 ;; need to store them somewhere so we can delete them when the system
166 (inline-methods :accessor component-inline-methods :initform nil)
167 (parent :initarg :parent :initform nil :reader component-parent)
168 ;; no direct accessor for pathname, we do this as a method to allow
169 ;; it to default in funky ways if not supplied
170 (relative-pathname :initarg :pathname)
171 (operation-times :initform (make-hash-table )
172 :accessor component-operation-times)
173 ;; XXX we should provide some atomic interface for updating the
174 ;; component properties
175 (properties :accessor component-properties :initarg :properties
178 ;;;; methods: conditions
180 (defmethod print-object ((c missing-dependency) s)
181 (format s (formatter "~@<~A, required by ~A~@:>")
182 (call-next-method c nil)
183 (missing-required-by c)))
185 (defun sysdef-error (format &rest arguments)
186 (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
188 ;;;; methods: components
190 (defmethod print-object ((c missing-component) s)
191 (format s (formatter "~@<component ~S not found~
192 ~@[ or does not match version ~A~]~
196 (when (missing-parent c)
197 (component-name (missing-parent c)))))
199 (defgeneric component-system (component)
200 (:documentation "Find the top-level system containing COMPONENT"))
202 (defmethod component-system ((component component))
203 (aif (component-parent component)
204 (component-system it)
207 (defmethod print-object ((c component) stream)
208 (print-unreadable-object (c stream :type t :identity t)
210 (prin1 (component-name c) stream))))
212 (defclass module (component)
213 ((components :initform nil :accessor module-components :initarg :components)
214 ;; what to do if we can't satisfy a dependency of one of this module's
215 ;; components. This allows a limited form of conditional processing
216 (if-component-dep-fails :initform :fail
217 :accessor module-if-component-dep-fails
218 :initarg :if-component-dep-fails)
219 (default-component-class :accessor module-default-component-class
220 :initform 'cl-source-file :initarg :default-component-class)))
222 (defgeneric component-pathname (component)
223 (:documentation "Extracts the pathname applicable for a particular component."))
225 (defun component-parent-pathname (component)
226 (aif (component-parent component)
227 (component-pathname it)
228 *default-pathname-defaults*))
230 (defgeneric component-relative-pathname (component)
231 (:documentation "Extracts the relative pathname applicable for a particular component."))
233 (defmethod component-relative-pathname ((component module))
234 (or (slot-value component 'relative-pathname)
236 :directory `(:relative ,(component-name component))
237 :host (pathname-host (component-parent-pathname component)))))
239 (defmethod component-pathname ((component component))
240 (let ((*default-pathname-defaults* (component-parent-pathname component)))
241 (merge-pathnames (component-relative-pathname component))))
243 (defgeneric component-property (component property))
245 (defmethod component-property ((c component) property)
246 (cdr (assoc property (slot-value c 'properties))))
248 (defgeneric (setf component-property) (new-value component property))
250 (defmethod (setf component-property) (new-value (c component) property)
251 (let ((a (assoc property (slot-value c 'properties))))
253 (setf (cdr a) new-value)
254 (setf (slot-value c 'properties)
255 (acons property new-value (slot-value c 'properties))))))
259 (defclass system (module)
260 ((description :accessor system-description :initarg :description)
261 (long-description :accessor long-description :initarg :long-description)
262 (author :accessor system-author :initarg :author)
263 (maintainer :accessor system-maintainer :initarg :maintainer)
264 (licence :accessor system-licence :initarg :licence)))
266 ;;; version-satisfies
268 ;;; with apologies to christophe rhodes ...
269 (defun split (string &optional max (ws '(#\Space #\Tab)))
270 (flet ((is-ws (char) (find char ws)))
272 (let ((list nil) (start 0) (words 0) end)
274 (when (and max (>= words (1- max)))
275 (return (cons (subseq string start) list)))
276 (setf end (position-if #'is-ws string :start start))
277 (push (subseq string start end) list)
279 (unless end (return list))
280 (setf start (1+ end)))))))
282 (defgeneric version-satisfies (component version))
284 (defmethod version-satisfies ((c component) version)
285 (unless (and version (slot-boundp c 'version))
286 (return-from version-satisfies t))
287 (let ((x (mapcar #'parse-integer
288 (split (component-version c) nil '(#\.))))
289 (y (mapcar #'parse-integer
290 (split version nil '(#\.)))))
291 (labels ((bigger (x y)
294 ((> (car x) (car y)) t)
296 (bigger (cdr x) (cdr y))))))
297 (and (= (car x) (car y))
298 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
303 (defvar *defined-systems* (make-hash-table :test 'equal))
304 (defun coerce-name (name)
306 (component (component-name name))
307 (symbol (string-downcase (symbol-name name)))
309 (t (sysdef-error (formatter "~@<invalid component designator ~A~@:>")
312 ;;; for the sake of keeping things reasonably neat, we adopt a
313 ;;; convention that functions in this list are prefixed SYSDEF-
315 (defvar *system-definition-search-functions*
316 '(sysdef-central-registry-search))
318 (defun system-definition-pathname (system)
319 (some (lambda (x) (funcall x system))
320 *system-definition-search-functions*))
322 (defvar *central-registry*
323 '(*default-pathname-defaults*
324 #+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
325 #+nil "telent:asdf;systems;"))
327 (defun sysdef-central-registry-search (system)
328 (let ((name (coerce-name system)))
330 (dolist (dir *central-registry*)
331 (let* ((defaults (eval dir))
334 :defaults defaults :version :newest
335 :name name :type "asd" :case :local))))
336 (if (and file (probe-file file))
340 (defun find-system (name &optional (error-p t))
341 (let* ((name (coerce-name name))
342 (in-memory (gethash name *defined-systems*))
343 (on-disk (system-definition-pathname name)))
346 (< (car in-memory) (file-write-date on-disk))))
347 (let ((*package* (make-package (gensym (package-name #.*package*))
350 (formatter "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%")
351 ;; FIXME: This wants to be (ENOUGH-NAMESTRING
352 ;; ON-DISK), but CMUCL barfs on that.
356 (let ((in-memory (gethash name *defined-systems*)))
358 (progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
360 (if error-p (error 'missing-component :requires name))))))
362 (defun register-system (name system)
363 (format t (formatter "~&~@<; ~@;registering ~A as ~A~@:>~%") system name)
364 (setf (gethash (coerce-name name) *defined-systems*)
365 (cons (get-universal-time) system)))
367 (defun system-registered-p (name)
368 (gethash (coerce-name name) *defined-systems*))
370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371 ;;; finding components
373 (defgeneric find-component (module name &optional version)
374 (:documentation "Finds the component with name NAME present in the
375 MODULE module; if MODULE is nil, then the component is assumed to be a
378 (defmethod find-component ((module module) name &optional version)
379 (if (slot-boundp module 'components)
380 (let ((m (find name (module-components module)
381 :test #'equal :key #'component-name)))
382 (if (and m (version-satisfies m version)) m))))
385 ;;; a component with no parent is a system
386 (defmethod find-component ((module (eql nil)) name &optional version)
387 (let ((m (find-system name nil)))
388 (if (and m (version-satisfies m version)) m)))
390 ;;; component subclasses
392 (defclass source-file (component) ())
394 (defclass cl-source-file (source-file) ())
395 (defclass c-source-file (source-file) ())
396 (defclass java-source-file (source-file) ())
397 (defclass static-file (source-file) ())
398 (defclass doc-file (static-file) ())
399 (defclass html-file (doc-file) ())
401 (defgeneric source-file-type (component system))
402 (defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
403 (defmethod source-file-type ((c c-source-file) (s module)) "c")
404 (defmethod source-file-type ((c java-source-file) (s module)) "java")
405 (defmethod source-file-type ((c html-file) (s module)) "html")
406 (defmethod source-file-type ((c static-file) (s module)) nil)
408 (defmethod component-relative-pathname ((component source-file))
409 (let* ((*default-pathname-defaults* (component-parent-pathname component))
412 :name (component-name component)
413 :type (source-file-type component
414 (component-system component)))))
415 (if (slot-value component 'relative-pathname)
417 (slot-value component 'relative-pathname)
421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
424 ;;; one of these is instantiated whenever (operate ) is called
426 (defclass operation ()
427 ((forced :initform nil :initarg :force :accessor operation-forced)
428 (original-initargs :initform nil :initarg :original-initargs
429 :accessor operation-original-initargs)
430 (visited-nodes :initform nil :accessor operation-visited-nodes)
431 (visiting-nodes :initform nil :accessor operation-visiting-nodes)
432 (parent :initform nil :initarg :parent :accessor operation-parent)))
434 (defmethod print-object ((o operation) stream)
435 (print-unreadable-object (o stream :type t :identity t)
437 (prin1 (operation-original-initargs o) stream))))
439 (defmethod shared-initialize :after ((operation operation) slot-names
442 (declare (ignore slot-names force))
443 ;; empty method to disable initarg validity checking
446 (defgeneric perform (operation component))
447 (defgeneric operation-done-p (operation component))
448 (defgeneric explain (operation component))
449 (defgeneric output-files (operation component))
450 (defgeneric input-files (operation component))
452 (defun node-for (o c)
453 (cons (class-name (class-of o)) c))
455 (defgeneric operation-ancestor (operation)
456 (:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
458 (defmethod operation-ancestor ((operation operation))
459 (aif (operation-parent operation)
460 (operation-ancestor it)
464 (defun make-sub-operation (c o dep-c dep-o)
465 (let* ((args (copy-list (operation-original-initargs o)))
466 (force-p (getf args :force)))
467 ;; note explicit comparison with T: any other non-NIL force value
468 ;; (e.g. :recursive) will pass through
469 (cond ((and (null (component-parent c))
470 (null (component-parent dep-c))
472 (when (eql force-p t)
473 (setf (getf args :force) nil))
474 ;; note we lose the parent slot, because we don't want
475 ;; forced to propagate backwards either (changes in depended-on
476 ;; systems shouldn't force recompilation of the depending system)
477 (apply #'make-instance dep-o
479 :original-initargs args args))
480 ((subtypep (type-of o) dep-o)
483 (apply #'make-instance dep-o
484 :parent o :original-initargs args args)))))
487 (defgeneric visit-component (operation component data))
489 (defmethod visit-component ((o operation) (c component) data)
490 (unless (component-visited-p o c)
491 (push (cons (node-for o c) data)
492 (operation-visited-nodes (operation-ancestor o)))))
494 (defgeneric component-visited-p (operation component))
496 (defmethod component-visited-p ((o operation) (c component))
497 (assoc (node-for o c)
498 (operation-visited-nodes (operation-ancestor o))
501 (defgeneric (setf visiting-component) (new-value operation component))
503 (defmethod (setf visiting-component) (new-value operation component)
504 ;; MCL complains about unused lexical variables
505 (declare (ignorable new-value operation component)))
507 (defmethod (setf visiting-component) (new-value (o operation) (c component))
508 (let ((node (node-for o c))
509 (a (operation-ancestor o)))
511 (pushnew node (operation-visiting-nodes a) :test 'equal)
512 (setf (operation-visiting-nodes a)
513 (remove node (operation-visiting-nodes a) :test 'equal)))))
515 (defgeneric component-visiting-p (operation component))
517 (defmethod component-visiting-p ((o operation) (c component))
518 (let ((node (cons o c)))
519 (member node (operation-visiting-nodes (operation-ancestor o))
522 (defgeneric component-depends-on (operation component))
524 (defmethod component-depends-on ((o operation) (c component))
525 (cdr (assoc (class-name (class-of o))
526 (slot-value c 'in-order-to))))
528 (defgeneric component-self-dependencies (operation component))
530 (defmethod component-self-dependencies ((o operation) (c component))
531 (let ((all-deps (component-depends-on o c)))
532 (remove-if-not (lambda (x)
533 (member (component-name c) (cdr x) :test #'string=))
536 (defmethod input-files ((operation operation) (c component))
537 (let ((parent (component-parent c))
538 (self-deps (component-self-dependencies operation c)))
540 (mapcan (lambda (dep)
541 (destructuring-bind (op name) dep
542 (output-files (make-instance op)
543 (find-component parent name))))
545 ;; no previous operations needed? I guess we work with the
546 ;; original source file, then
547 (list (component-pathname c)))))
549 (defmethod input-files ((operation operation) (c module)) nil)
551 (defmethod operation-done-p ((o operation) (c component))
552 (let ((out-files (output-files o c))
553 (in-files (input-files o c)))
554 (cond ((and (not in-files) (not out-files))
555 ;; arbitrary decision: an operation that uses nothing to
556 ;; produce nothing probably isn't doing much
561 (component-operation-times c))))
565 (mapcar #'file-write-date in-files)) 0)))))
569 (every #'probe-file out-files)
570 (> (apply #'min (mapcar #'file-write-date out-files))
571 (apply #'max (mapcar #'file-write-date in-files)) ))))))
573 ;;; So you look at this code and think "why isn't it a bunch of
574 ;;; methods". And the answer is, because standard method combination
575 ;;; runs :before methods most->least-specific, which is back to front
576 ;;; for our purposes. And CLISP doesn't have non-standard method
577 ;;; combinations, so let's keep it simple and aspire to portability
579 (defgeneric traverse (operation component))
580 (defmethod traverse ((operation operation) (c component))
582 (labels ((do-one-dep (required-op required-c required-v)
583 (let* ((dep-c (or (find-component
585 ;; XXX tacky. really we should build the
586 ;; in-order-to slot with canonicalized
587 ;; names instead of coercing this late
588 (coerce-name required-c) required-v)
589 (error 'missing-dependency :required-by c
591 :requires required-c)))
592 (op (make-sub-operation c operation dep-c required-op)))
593 (traverse op dep-c)))
595 (cond ((eq op 'feature)
596 (or (member (car dep) *features*)
597 (error 'missing-dependency :required-by c
598 :requires (car dep) :version nil)))
602 (assert (string-equal
603 (symbol-name (first d))
606 (do-one-dep op (second d) (third d))))
608 (appendf forced (do-one-dep op d nil)))))))))
609 (aif (component-visited-p operation c)
610 (return-from traverse
611 (if (cdr it) (list (cons 'pruned-op c)) nil)))
613 (if (component-visiting-p operation c)
614 (error 'circular-dependency :components (list c)))
615 (setf (visiting-component operation c) t)
616 (loop for (required-op . deps) in (component-depends-on operation c)
617 do (do-dep required-op deps))
620 (when (typep c 'module)
621 (let ((at-least-one nil)
624 (loop for kid in (module-components c)
626 (appendf forced (traverse operation kid ))
627 (missing-dependency (condition)
628 (if (eq (module-if-component-dep-fails c) :fail)
630 (setf error condition))
633 (setf at-least-one t))))
634 (when (and (eq (module-if-component-dep-fails c) :try-next)
638 ;; now the thing itself
639 (when (or forced module-ops
640 (not (operation-done-p operation c))
641 (let ((f (operation-forced (operation-ancestor operation))))
642 (and f (or (not (consp f))
643 (member (component-name
644 (operation-ancestor operation))
645 (mapcar #'coerce-name f)
647 (let ((do-first (cdr (assoc (class-name (class-of operation))
648 (slot-value c 'do-first)))))
649 (loop for (required-op . deps) in do-first
650 do (do-dep required-op deps)))
651 (setf forced (append (delete 'pruned-op forced :key #'car)
652 (delete 'pruned-op module-ops :key #'car)
653 (list (cons operation c))))))
654 (setf (visiting-component operation c) nil)
655 (visit-component operation c (and forced t))
659 (defmethod perform ((operation operation) (c source-file))
661 (formatter "~@<required method PERFORM not implemented~
662 for operation ~A, component ~A~@:>")
663 (class-of operation) (class-of c)))
665 (defmethod perform ((operation operation) (c module))
668 (defmethod explain ((operation operation) (component component))
669 (format *trace-output* "~&;;; ~A on ~A~%"
670 operation component))
674 (defclass compile-op (operation)
675 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
676 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
677 :initform *compile-file-warnings-behaviour*)
678 (on-failure :initarg :on-failure :accessor operation-on-failure
679 :initform *compile-file-failure-behaviour*)))
681 (defmethod perform :before ((operation compile-op) (c source-file))
682 (map nil #'ensure-directories-exist (output-files operation c)))
684 (defmethod perform :after ((operation operation) (c component))
685 (setf (gethash (type-of operation) (component-operation-times c))
686 (get-universal-time)))
688 ;;; perform is required to check output-files to find out where to put
689 ;;; its answers, in case it has been overridden for site policy
690 (defmethod perform ((operation compile-op) (c cl-source-file))
691 (let ((source-file (component-pathname c))
692 (output-file (car (output-files operation c))))
693 (multiple-value-bind (output warnings-p failure-p)
694 (compile-file source-file
695 :output-file output-file)
696 ;(declare (ignore output))
698 (case (operation-on-warnings operation)
699 (:warn (warn "COMPILE-FILE warned while performing ~A on ~A"
701 (:error (error 'compile-warned :component c :operation operation))
704 (case (operation-on-failure operation)
705 (:warn (warn "COMPILE-FILE failed while performing ~A on ~A"
707 (:error (error 'compile-failed :component c :operation operation))
710 (error 'compile-error :component c :operation operation)))))
712 (defmethod output-files ((operation compile-op) (c cl-source-file))
713 (list (compile-file-pathname (component-pathname c))))
715 (defmethod perform ((operation compile-op) (c static-file))
718 (defmethod output-files ((operation compile-op) (c static-file))
723 (defclass load-op (operation) ())
725 (defmethod perform ((o load-op) (c cl-source-file))
726 (mapcar #'load (input-files o c)))
728 (defmethod perform ((operation load-op) (c static-file))
730 (defmethod operation-done-p ((operation load-op) (c static-file))
733 (defmethod output-files ((o operation) (c component))
736 (defmethod component-depends-on ((operation load-op) (c component))
737 (cons (list 'compile-op (component-name c))
742 (defclass load-source-op (operation) ())
744 (defmethod perform ((o load-source-op) (c cl-source-file))
745 (let ((source (component-pathname c)))
746 (setf (component-property c 'last-loaded-as-source)
748 (get-universal-time)))))
750 (defmethod perform ((operation load-source-op) (c static-file))
753 (defmethod output-files ((operation load-source-op) (c component))
756 ;;; FIXME: we simply copy load-op's dependencies. this is Just Not Right.
757 (defmethod component-depends-on ((o load-source-op) (c component))
758 (let ((what-would-load-op-do (cdr (assoc 'load-op
759 (slot-value c 'in-order-to)))))
760 (mapcar (lambda (dep)
761 (if (eq (car dep) 'load-op)
762 (cons 'load-source-op (cdr dep))
764 what-would-load-op-do)))
766 (defmethod operation-done-p ((o load-source-op) (c source-file))
767 (if (or (not (component-property c 'last-loaded-as-source))
768 (> (file-write-date (component-pathname c))
769 (component-property c 'last-loaded-as-source)))
773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
774 ;;; invoking operations
776 (defun operate (operation-class system &rest args)
777 (let* ((op (apply #'make-instance operation-class
778 :original-initargs args args))
779 (system (if (typep system 'component) system (find-system system)))
780 (steps (traverse op system)))
781 (with-compilation-unit ()
782 (loop for (op . component) in steps do
785 (progn (perform op component)
788 (skip-component () (return))))))))
790 (defun oos (&rest args)
791 "Alias of OPERATE function"
792 (apply #'operate args))
794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
797 (defun remove-keyword (key arglist)
798 (labels ((aux (key arglist)
799 (cond ((null arglist) nil)
800 ((eq key (car arglist)) (cddr arglist))
801 (t (cons (car arglist) (cons (cadr arglist)
803 key (cddr arglist))))))))
806 (defmacro defsystem (name &body options)
807 (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
808 (let ((component-options (remove-keyword :class options)))
810 ;; system must be registered before we parse the body, otherwise
811 ;; we recur when trying to find an existing system of the same name
812 ;; to reuse options (e.g. pathname) from
813 (let ((s (system-registered-p ',name)))
814 (cond ((and s (eq (type-of (cdr s)) ',class))
815 (setf (car s) (get-universal-time)))
818 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
820 (change-class (cdr s) ',class))
822 (register-system (quote ,name)
823 (make-instance ',class :name ',name)))))
824 (parse-component-form nil (apply
826 :module (coerce-name ',name)
829 (pathname-sans-name+type
830 (resolve-symlinks *load-truename*))
831 *default-pathname-defaults*)
832 ',component-options))))))
835 (defun class-for-type (parent type)
836 (let ((class (find-class
837 (or (find-symbol (symbol-name type) *package*)
838 (find-symbol (symbol-name type) #.*package*)) nil)))
841 (or (module-default-component-class parent)
842 (find-class 'cl-source-file)))
843 (sysdef-error (formatter "~@<don't recognize component type ~A~@:>")
846 (defun maybe-add-tree (tree op1 op2 c)
847 "Add the node C at /OP1/OP2 in TREE, unless it's there already.
848 Returns the new tree (which probably shares structure with the old one)"
849 (let ((first-op-tree (assoc op1 tree)))
852 (aif (assoc op2 (cdr first-op-tree))
853 (if (find c (cdr it))
855 (setf (cdr it) (cons c (cdr it))))
856 (setf (cdr first-op-tree)
857 (acons op2 (list c) (cdr first-op-tree))))
859 (acons op1 (list (list op2 c)) tree))))
861 (defun union-of-dependencies (&rest deps)
862 (let ((new-tree nil))
864 (dolist (op-tree dep)
865 (dolist (op (cdr op-tree))
868 (maybe-add-tree new-tree (car op-tree) (car op) c))))))
872 (defun remove-keys (key-names args)
873 (loop for ( name val ) on args by #'cddr
874 unless (member (symbol-name name) key-names
875 :key #'symbol-name :test 'equal)
876 append (list name val)))
878 (defvar *serial-depends-on*)
880 (defun parse-component-form (parent options)
882 (type name &rest rest &key
883 ;; the following list of keywords is reproduced below in the
884 ;; remove-keys form. important to keep them in sync
885 components pathname default-component-class
886 perform explain output-files operation-done-p
887 depends-on serial in-order-to
889 &allow-other-keys) options
890 (let* ((other-args (remove-keys
891 '(components pathname default-component-class
892 perform explain output-files operation-done-p
893 depends-on serial in-order-to)
896 (or (find-component parent name)
897 (make-instance (class-for-type parent type)))))
898 (when (boundp '*serial-depends-on*)
900 (concatenate 'list *serial-depends-on* depends-on)))
901 (apply #'reinitialize-instance
903 :name (coerce-name name)
907 (when (typep ret 'module)
908 (setf (module-default-component-class ret)
909 (or default-component-class
910 (and (typep parent 'module)
911 (module-default-component-class parent))))
912 (let ((*serial-depends-on* nil))
913 (setf (module-components ret)
914 (loop for c-form in components
915 for c = (parse-component-form ret c-form)
918 do (push (component-name c) *serial-depends-on*)))))
920 (setf (slot-value ret 'in-order-to)
921 (union-of-dependencies
923 `((compile-op (compile-op ,@depends-on))
924 (load-op (load-op ,@depends-on))))
925 (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
927 (loop for (n v) in `((perform ,perform) (explain ,explain)
928 (output-files ,output-files)
929 (operation-done-p ,operation-done-p))
931 ;; this is inefficient as most of the stored
932 ;; methods will not be for this particular gf n
933 ;; But this is hardly performance-critical
934 (lambda (m) (remove-method (symbol-function n) m))
935 (component-inline-methods ret))
937 do (destructuring-bind (op qual (o c) &body body) v
939 (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
941 (component-inline-methods ret))))
945 (defun resolve-symlinks (path)
946 #-allegro (truename path)
947 #+allegro (excl:pathname-resolve-symbolic-links path)
952 ;;; run-shell-command functions for other lisp implementations will be
953 ;;; gratefully accepted, if they do the same thing. If the docstring
954 ;;; is ambiguous, send a bug report
956 (defun run-shell-command (control-string &rest args)
957 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
958 synchronously execute the result using a Bourne-compatible shell, with
959 output to *trace-output*. Returns the shell's exit code."
960 (let ((command (apply #'format nil control-string args)))
961 (format *trace-output* "; $ ~A~%" command)
963 (sb-impl::process-exit-code
967 :input nil :output *trace-output*))
970 (ext:process-exit-code
974 :input nil :output *trace-output*))
977 (excl:run-shell-command command :input nil :output *trace-output*)
980 (system:call-system-showing-output
982 :shell-type "/bin/sh"
983 :output-stream *trace-output*)
985 #+clisp ;XXX not exactly *trace-output*, I know
986 (ext:run-shell-command command :output :terminal :wait t)
990 (ccl:external-process-status
991 (ccl:run-program "/bin/sh" (list "-c" command)
992 :input nil :output *trace-output*
995 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
996 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
1000 (defgeneric hyperdocumentation (package name doc-type))
1001 (defmethod hyperdocumentation ((package symbol) name doc-type)
1002 (hyperdocumentation (find-package package) name doc-type))
1004 (defun hyperdoc (name doc-type)
1005 (hyperdocumentation (symbol-package name) name doc-type))
1008 (pushnew :asdf *features*)
1011 (eval-when (:compile-toplevel :load-toplevel :execute)
1012 (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
1013 (pushnew :sbcl-hooks-require *features*)))
1015 #+(and sbcl sbcl-hooks-require)
1017 (defun module-provide-asdf (name)
1018 (let ((system (asdf:find-system name nil)))
1020 (asdf:operate 'asdf:load-op name)
1024 (merge-pathnames "systems/"
1025 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1029 (merge-pathnames "site-systems/"
1030 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1034 (merge-pathnames ".sbcl/systems/"
1035 (user-homedir-pathname))
1038 (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))