1 ;;; This is asdf: Another System Definition Facility. 1.93
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
107 (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")
112 (defvar *asdf-revision* (let* ((v "1.93")
113 (colon (or (position #\: v) -1))
114 (dot (position #\. v)))
116 (list (parse-integer v :start (1+ colon)
118 (parse-integer v :start (1+ dot)
121 (defvar *compile-file-warnings-behaviour* :warn)
122 (defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
124 (defvar *verbose-out* nil)
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 (defmacro aif (test then &optional else)
130 `(let ((it ,test)) (if it ,then ,else)))
132 (defun pathname-sans-name+type (pathname)
133 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
134 and NIL NAME and TYPE components"
135 (make-pathname :name nil :type nil :defaults pathname))
137 (define-modify-macro appendf (&rest args)
138 append "Append onto list")
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;; classes, condiitons
143 (define-condition system-definition-error (error) ()
144 ;; [this use of :report should be redundant, but unfortunately it's not.
145 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
146 ;; over print-object; this is always conditions::%print-condition for
147 ;; condition objects, which in turn does inheritance of :report options at
148 ;; run-time. fortunately, inheritance means we only need this kludge here in
149 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
150 #+cmu (:report print-object))
152 (define-condition formatted-system-definition-error (system-definition-error)
153 ((format-control :initarg :format-control :reader format-control)
154 (format-arguments :initarg :format-arguments :reader format-arguments))
155 (:report (lambda (c s)
156 (apply #'format s (format-control c) (format-arguments c)))))
158 (define-condition circular-dependency (system-definition-error)
159 ((components :initarg :components :reader circular-dependency-components)))
161 (define-condition duplicate-names (system-definition-error)
162 ((name :initarg :name :reader duplicate-names-name)))
164 (define-condition missing-component (system-definition-error)
165 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
166 (version :initform nil :reader missing-version :initarg :version)
167 (parent :initform nil :reader missing-parent :initarg :parent)))
169 (define-condition missing-dependency (missing-component)
170 ((required-by :initarg :required-by :reader missing-required-by)))
172 (define-condition operation-error (error)
173 ((component :reader error-component :initarg :component)
174 (operation :reader error-operation :initarg :operation))
175 (:report (lambda (c s)
176 (format s "~@<erred while invoking ~A on ~A~@:>"
177 (error-operation c) (error-component c)))))
178 (define-condition compile-error (operation-error) ())
179 (define-condition compile-failed (compile-error) ())
180 (define-condition compile-warned (compile-error) ())
182 (defclass component ()
183 ((name :accessor component-name :initarg :name :documentation
184 "Component name: designator for a string composed of portable pathname characters")
185 (version :accessor component-version :initarg :version)
186 (in-order-to :initform nil :initarg :in-order-to)
188 (do-first :initform nil :initarg :do-first)
189 ;; methods defined using the "inline" style inside a defsystem form:
190 ;; need to store them somewhere so we can delete them when the system
192 (inline-methods :accessor component-inline-methods :initform nil)
193 (parent :initarg :parent :initform nil :reader component-parent)
194 ;; no direct accessor for pathname, we do this as a method to allow
195 ;; it to default in funky ways if not supplied
196 (relative-pathname :initarg :pathname)
197 (operation-times :initform (make-hash-table )
198 :accessor component-operation-times)
199 ;; XXX we should provide some atomic interface for updating the
200 ;; component properties
201 (properties :accessor component-properties :initarg :properties
204 ;;;; methods: conditions
206 (defmethod print-object ((c missing-dependency) s)
207 (format s "~@<~A, required by ~A~@:>"
208 (call-next-method c nil) (missing-required-by c)))
210 (defun sysdef-error (format &rest arguments)
211 (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
213 ;;;; methods: components
215 (defmethod print-object ((c missing-component) s)
216 (format s "~@<component ~S not found~
217 ~@[ or does not match version ~A~]~
221 (when (missing-parent c)
222 (component-name (missing-parent c)))))
224 (defgeneric component-system (component)
225 (:documentation "Find the top-level system containing COMPONENT"))
227 (defmethod component-system ((component component))
228 (aif (component-parent component)
229 (component-system it)
232 (defmethod print-object ((c component) stream)
233 (print-unreadable-object (c stream :type t :identity t)
235 (prin1 (component-name c) stream))))
237 (defclass module (component)
238 ((components :initform nil :accessor module-components :initarg :components)
239 ;; what to do if we can't satisfy a dependency of one of this module's
240 ;; components. This allows a limited form of conditional processing
241 (if-component-dep-fails :initform :fail
242 :accessor module-if-component-dep-fails
243 :initarg :if-component-dep-fails)
244 (default-component-class :accessor module-default-component-class
245 :initform 'cl-source-file :initarg :default-component-class)))
247 (defgeneric component-pathname (component)
248 (:documentation "Extracts the pathname applicable for a particular component."))
250 (defun component-parent-pathname (component)
251 (aif (component-parent component)
252 (component-pathname it)
253 *default-pathname-defaults*))
255 (defgeneric component-relative-pathname (component)
256 (:documentation "Extracts the relative pathname applicable for a particular component."))
258 (defmethod component-relative-pathname ((component module))
259 (or (slot-value component 'relative-pathname)
261 :directory `(:relative ,(component-name component))
262 :host (pathname-host (component-parent-pathname component)))))
264 (defmethod component-pathname ((component component))
265 (let ((*default-pathname-defaults* (component-parent-pathname component)))
266 (merge-pathnames (component-relative-pathname component))))
268 (defgeneric component-property (component property))
270 (defmethod component-property ((c component) property)
271 (cdr (assoc property (slot-value c 'properties) :test #'equal)))
273 (defgeneric (setf component-property) (new-value component property))
275 (defmethod (setf component-property) (new-value (c component) property)
276 (let ((a (assoc property (slot-value c 'properties) :test #'equal)))
278 (setf (cdr a) new-value)
279 (setf (slot-value c 'properties)
280 (acons property new-value (slot-value c 'properties))))))
282 (defclass system (module)
283 ((description :accessor system-description :initarg :description)
285 :accessor system-long-description :initarg :long-description)
286 (author :accessor system-author :initarg :author)
287 (maintainer :accessor system-maintainer :initarg :maintainer)
288 (licence :accessor system-licence :initarg :licence)))
290 ;;; version-satisfies
292 ;;; with apologies to christophe rhodes ...
293 (defun split (string &optional max (ws '(#\Space #\Tab)))
294 (flet ((is-ws (char) (find char ws)))
296 (let ((list nil) (start 0) (words 0) end)
298 (when (and max (>= words (1- max)))
299 (return (cons (subseq string start) list)))
300 (setf end (position-if #'is-ws string :start start))
301 (push (subseq string start end) list)
303 (unless end (return list))
304 (setf start (1+ end)))))))
306 (defgeneric version-satisfies (component version))
308 (defmethod version-satisfies ((c component) version)
309 (unless (and version (slot-boundp c 'version))
310 (return-from version-satisfies t))
311 (let ((x (mapcar #'parse-integer
312 (split (component-version c) nil '(#\.))))
313 (y (mapcar #'parse-integer
314 (split version nil '(#\.)))))
315 (labels ((bigger (x y)
318 ((> (car x) (car y)) t)
320 (bigger (cdr x) (cdr y))))))
321 (and (= (car x) (car y))
322 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327 (defvar *defined-systems* (make-hash-table :test 'equal))
328 (defun coerce-name (name)
330 (component (component-name name))
331 (symbol (string-downcase (symbol-name name)))
333 (t (sysdef-error "~@<invalid component designator ~A~@:>" name))))
335 ;;; for the sake of keeping things reasonably neat, we adopt a
336 ;;; convention that functions in this list are prefixed SYSDEF-
338 (defvar *system-definition-search-functions*
339 '(sysdef-central-registry-search))
341 (defun system-definition-pathname (system)
342 (some (lambda (x) (funcall x system))
343 *system-definition-search-functions*))
345 (defvar *central-registry*
346 '(*default-pathname-defaults*
347 #+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
348 #+nil "telent:asdf;systems;"))
350 (defun sysdef-central-registry-search (system)
351 (let ((name (coerce-name system)))
353 (dolist (dir *central-registry*)
354 (let* ((defaults (eval dir))
357 :defaults defaults :version :newest
358 :name name :type "asd" :case :local))))
359 (if (and file (probe-file file))
362 (defun make-temporary-package ()
363 (flet ((try (counter)
365 (make-package (format nil "ASDF~D" counter)
366 :use '(:cl :asdf)))))
367 (do* ((counter 0 (+ counter 1))
368 (package (try counter) (try counter)))
371 (defun find-system (name &optional (error-p t))
372 (let* ((name (coerce-name name))
373 (in-memory (gethash name *defined-systems*))
374 (on-disk (system-definition-pathname name)))
377 (< (car in-memory) (file-write-date on-disk))))
378 (let ((package (make-temporary-package)))
380 (let ((*package* package))
383 "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%"
384 ;; FIXME: This wants to be (ENOUGH-NAMESTRING
385 ;; ON-DISK), but CMUCL barfs on that.
389 (delete-package package))))
390 (let ((in-memory (gethash name *defined-systems*)))
392 (progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
394 (if error-p (error 'missing-component :requires name))))))
396 (defun register-system (name system)
397 (format *verbose-out* "~&~@<; ~@;registering ~A as ~A~@:>~%" system name)
398 (setf (gethash (coerce-name name) *defined-systems*)
399 (cons (get-universal-time) system)))
401 (defun system-registered-p (name)
402 (gethash (coerce-name name) *defined-systems*))
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
405 ;;; finding components
407 (defgeneric find-component (module name &optional version)
408 (:documentation "Finds the component with name NAME present in the
409 MODULE module; if MODULE is nil, then the component is assumed to be a
412 (defmethod find-component ((module module) name &optional version)
413 (if (slot-boundp module 'components)
414 (let ((m (find name (module-components module)
415 :test #'equal :key #'component-name)))
416 (if (and m (version-satisfies m version)) m))))
419 ;;; a component with no parent is a system
420 (defmethod find-component ((module (eql nil)) name &optional version)
421 (let ((m (find-system name nil)))
422 (if (and m (version-satisfies m version)) m)))
424 ;;; component subclasses
426 (defclass source-file (component) ())
428 (defclass cl-source-file (source-file) ())
429 (defclass c-source-file (source-file) ())
430 (defclass java-source-file (source-file) ())
431 (defclass static-file (source-file) ())
432 (defclass doc-file (static-file) ())
433 (defclass html-file (doc-file) ())
435 (defgeneric source-file-type (component system))
436 (defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
437 (defmethod source-file-type ((c c-source-file) (s module)) "c")
438 (defmethod source-file-type ((c java-source-file) (s module)) "java")
439 (defmethod source-file-type ((c html-file) (s module)) "html")
440 (defmethod source-file-type ((c static-file) (s module)) nil)
442 (defmethod component-relative-pathname ((component source-file))
443 (let ((relative-pathname (slot-value component 'relative-pathname)))
444 (if relative-pathname
446 (let* ((*default-pathname-defaults*
447 (component-parent-pathname component))
450 :name (component-name component)
451 :type (source-file-type component
452 (component-system component)))))
455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
458 ;;; one of these is instantiated whenever (operate ) is called
460 (defclass operation ()
461 ((forced :initform nil :initarg :force :accessor operation-forced)
462 (original-initargs :initform nil :initarg :original-initargs
463 :accessor operation-original-initargs)
464 (visited-nodes :initform nil :accessor operation-visited-nodes)
465 (visiting-nodes :initform nil :accessor operation-visiting-nodes)
466 (parent :initform nil :initarg :parent :accessor operation-parent)))
468 (defmethod print-object ((o operation) stream)
469 (print-unreadable-object (o stream :type t :identity t)
471 (prin1 (operation-original-initargs o) stream))))
473 (defmethod shared-initialize :after ((operation operation) slot-names
476 (declare (ignore slot-names force))
477 ;; empty method to disable initarg validity checking
480 (defgeneric perform (operation component))
481 (defgeneric operation-done-p (operation component))
482 (defgeneric explain (operation component))
483 (defgeneric output-files (operation component))
484 (defgeneric input-files (operation component))
486 (defun node-for (o c)
487 (cons (class-name (class-of o)) c))
489 (defgeneric operation-ancestor (operation)
490 (:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
492 (defmethod operation-ancestor ((operation operation))
493 (aif (operation-parent operation)
494 (operation-ancestor it)
498 (defun make-sub-operation (c o dep-c dep-o)
499 (let* ((args (copy-list (operation-original-initargs o)))
500 (force-p (getf args :force)))
501 ;; note explicit comparison with T: any other non-NIL force value
502 ;; (e.g. :recursive) will pass through
503 (cond ((and (null (component-parent c))
504 (null (component-parent dep-c))
506 (when (eql force-p t)
507 (setf (getf args :force) nil))
508 (apply #'make-instance dep-o
510 :original-initargs args args))
511 ((subtypep (type-of o) dep-o)
514 (apply #'make-instance dep-o
515 :parent o :original-initargs args args)))))
518 (defgeneric visit-component (operation component data))
520 (defmethod visit-component ((o operation) (c component) data)
521 (unless (component-visited-p o c)
522 (push (cons (node-for o c) data)
523 (operation-visited-nodes (operation-ancestor o)))))
525 (defgeneric component-visited-p (operation component))
527 (defmethod component-visited-p ((o operation) (c component))
528 (assoc (node-for o c)
529 (operation-visited-nodes (operation-ancestor o))
532 (defgeneric (setf visiting-component) (new-value operation component))
534 (defmethod (setf visiting-component) (new-value operation component)
535 ;; MCL complains about unused lexical variables
536 (declare (ignorable new-value operation component)))
538 (defmethod (setf visiting-component) (new-value (o operation) (c component))
539 (let ((node (node-for o c))
540 (a (operation-ancestor o)))
542 (pushnew node (operation-visiting-nodes a) :test 'equal)
543 (setf (operation-visiting-nodes a)
544 (remove node (operation-visiting-nodes a) :test 'equal)))))
546 (defgeneric component-visiting-p (operation component))
548 (defmethod component-visiting-p ((o operation) (c component))
549 (let ((node (cons o c)))
550 (member node (operation-visiting-nodes (operation-ancestor o))
553 (defgeneric component-depends-on (operation component))
555 (defmethod component-depends-on ((o operation) (c component))
556 (cdr (assoc (class-name (class-of o))
557 (slot-value c 'in-order-to))))
559 (defgeneric component-self-dependencies (operation component))
561 (defmethod component-self-dependencies ((o operation) (c component))
562 (let ((all-deps (component-depends-on o c)))
563 (remove-if-not (lambda (x)
564 (member (component-name c) (cdr x) :test #'string=))
567 (defmethod input-files ((operation operation) (c component))
568 (let ((parent (component-parent c))
569 (self-deps (component-self-dependencies operation c)))
571 (mapcan (lambda (dep)
572 (destructuring-bind (op name) dep
573 (output-files (make-instance op)
574 (find-component parent name))))
576 ;; no previous operations needed? I guess we work with the
577 ;; original source file, then
578 (list (component-pathname c)))))
580 (defmethod input-files ((operation operation) (c module)) nil)
582 (defmethod operation-done-p ((o operation) (c component))
583 (let ((out-files (output-files o c))
584 (in-files (input-files o c)))
585 (cond ((and (not in-files) (not out-files))
586 ;; arbitrary decision: an operation that uses nothing to
587 ;; produce nothing probably isn't doing much
592 (component-operation-times c))))
596 (mapcar #'file-write-date in-files)) 0)))))
600 (every #'probe-file out-files)
601 (> (apply #'min (mapcar #'file-write-date out-files))
602 (apply #'max (mapcar #'file-write-date in-files)) ))))))
604 ;;; So you look at this code and think "why isn't it a bunch of
605 ;;; methods". And the answer is, because standard method combination
606 ;;; runs :before methods most->least-specific, which is back to front
607 ;;; for our purposes. And CLISP doesn't have non-standard method
608 ;;; combinations, so let's keep it simple and aspire to portability
610 (defgeneric traverse (operation component))
611 (defmethod traverse ((operation operation) (c component))
613 (labels ((do-one-dep (required-op required-c required-v)
614 (let* ((dep-c (or (find-component
616 ;; XXX tacky. really we should build the
617 ;; in-order-to slot with canonicalized
618 ;; names instead of coercing this late
619 (coerce-name required-c) required-v)
620 (error 'missing-dependency :required-by c
622 :requires required-c)))
623 (op (make-sub-operation c operation dep-c required-op)))
624 (traverse op dep-c)))
626 (cond ((eq op 'feature)
627 (or (member (car dep) *features*)
628 (error 'missing-dependency :required-by c
629 :requires (car dep) :version nil)))
633 (assert (string-equal
634 (symbol-name (first d))
637 (do-one-dep op (second d) (third d))))
639 (appendf forced (do-one-dep op d nil)))))))))
640 (aif (component-visited-p operation c)
641 (return-from traverse
642 (if (cdr it) (list (cons 'pruned-op c)) nil)))
644 (if (component-visiting-p operation c)
645 (error 'circular-dependency :components (list c)))
646 (setf (visiting-component operation c) t)
647 (loop for (required-op . deps) in (component-depends-on operation c)
648 do (do-dep required-op deps))
651 (when (typep c 'module)
652 (let ((at-least-one nil)
655 (loop for kid in (module-components c)
657 (appendf forced (traverse operation kid ))
658 (missing-dependency (condition)
659 (if (eq (module-if-component-dep-fails c) :fail)
661 (setf error condition))
664 (setf at-least-one t))))
665 (when (and (eq (module-if-component-dep-fails c) :try-next)
669 ;; now the thing itself
670 (when (or forced module-ops
671 (not (operation-done-p operation c))
672 (let ((f (operation-forced (operation-ancestor operation))))
673 (and f (or (not (consp f))
674 (member (component-name
675 (operation-ancestor operation))
676 (mapcar #'coerce-name f)
678 (let ((do-first (cdr (assoc (class-name (class-of operation))
679 (slot-value c 'do-first)))))
680 (loop for (required-op . deps) in do-first
681 do (do-dep required-op deps)))
682 (setf forced (append (delete 'pruned-op forced :key #'car)
683 (delete 'pruned-op module-ops :key #'car)
684 (list (cons operation c))))))
685 (setf (visiting-component operation c) nil)
686 (visit-component operation c (and forced t))
690 (defmethod perform ((operation operation) (c source-file))
692 "~@<required method PERFORM not implemented ~
693 for operation ~A, component ~A~@:>"
694 (class-of operation) (class-of c)))
696 (defmethod perform ((operation operation) (c module))
699 (defmethod explain ((operation operation) (component component))
700 (format *verbose-out* "~&;;; ~A on ~A~%" operation component))
704 (defclass compile-op (operation)
705 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
706 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
707 :initform *compile-file-warnings-behaviour*)
708 (on-failure :initarg :on-failure :accessor operation-on-failure
709 :initform *compile-file-failure-behaviour*)))
711 (defmethod perform :before ((operation compile-op) (c source-file))
712 (map nil #'ensure-directories-exist (output-files operation c)))
714 (defmethod perform :after ((operation operation) (c component))
715 (setf (gethash (type-of operation) (component-operation-times c))
716 (get-universal-time)))
718 ;;; perform is required to check output-files to find out where to put
719 ;;; its answers, in case it has been overridden for site policy
720 (defmethod perform ((operation compile-op) (c cl-source-file))
721 #-:broken-fasl-loader
722 (let ((source-file (component-pathname c))
723 (output-file (car (output-files operation c))))
724 (multiple-value-bind (output warnings-p failure-p)
725 (compile-file source-file
726 :output-file output-file)
727 ;(declare (ignore output))
729 (case (operation-on-warnings operation)
731 "~@<COMPILE-FILE warned while performing ~A on ~A.~@:>"
733 (:error (error 'compile-warned :component c :operation operation))
736 (case (operation-on-failure operation)
738 "~@<COMPILE-FILE failed while performing ~A on ~A.~@:>"
740 (:error (error 'compile-failed :component c :operation operation))
743 (error 'compile-error :component c :operation operation)))))
745 (defmethod output-files ((operation compile-op) (c cl-source-file))
746 #-:broken-fasl-loader (list (compile-file-pathname (component-pathname c)))
747 #+:broken-fasl-loader (list (component-pathname c)))
749 (defmethod perform ((operation compile-op) (c static-file))
752 (defmethod output-files ((operation compile-op) (c static-file))
757 (defclass load-op (operation) ())
759 (defmethod perform ((o load-op) (c cl-source-file))
760 (mapcar #'load (input-files o c)))
762 (defmethod perform ((operation load-op) (c static-file))
764 (defmethod operation-done-p ((operation load-op) (c static-file))
767 (defmethod output-files ((o operation) (c component))
770 (defmethod component-depends-on ((operation load-op) (c component))
771 (cons (list 'compile-op (component-name c))
776 (defclass load-source-op (operation) ())
778 (defmethod perform ((o load-source-op) (c cl-source-file))
779 (let ((source (component-pathname c)))
780 (setf (component-property c 'last-loaded-as-source)
782 (get-universal-time)))))
784 (defmethod perform ((operation load-source-op) (c static-file))
787 (defmethod output-files ((operation load-source-op) (c component))
790 ;;; FIXME: we simply copy load-op's dependencies. this is Just Not Right.
791 (defmethod component-depends-on ((o load-source-op) (c component))
792 (let ((what-would-load-op-do (cdr (assoc 'load-op
793 (slot-value c 'in-order-to)))))
794 (mapcar (lambda (dep)
795 (if (eq (car dep) 'load-op)
796 (cons 'load-source-op (cdr dep))
798 what-would-load-op-do)))
800 (defmethod operation-done-p ((o load-source-op) (c source-file))
801 (if (or (not (component-property c 'last-loaded-as-source))
802 (> (file-write-date (component-pathname c))
803 (component-property c 'last-loaded-as-source)))
806 (defclass test-op (operation) ())
808 (defmethod perform ((operation test-op) (c component))
811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
812 ;;; invoking operations
814 (defun operate (operation-class system &rest args)
815 (let* ((op (apply #'make-instance operation-class
816 :original-initargs args args))
818 (if (getf args :verbose t)
820 (make-broadcast-stream)))
821 (system (if (typep system 'component) system (find-system system)))
822 (steps (traverse op system)))
823 (with-compilation-unit ()
824 (loop for (op . component) in steps do
827 (progn (perform op component)
832 (format s "~@<Retry performing ~S on ~S.~@:>"
838 "~@<Continue, treating ~S on ~S as ~
839 having been successful.~@:>"
841 (setf (gethash (type-of op)
842 (component-operation-times component))
843 (get-universal-time))
846 (defun oos (&rest args)
847 "Alias of OPERATE function"
848 (apply #'operate args))
850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
853 (defun remove-keyword (key arglist)
854 (labels ((aux (key arglist)
855 (cond ((null arglist) nil)
856 ((eq key (car arglist)) (cddr arglist))
857 (t (cons (car arglist) (cons (cadr arglist)
859 key (cddr arglist))))))))
862 (defmacro defsystem (name &body options)
863 (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
864 (let ((component-options (remove-keyword :class options)))
866 ;; system must be registered before we parse the body, otherwise
867 ;; we recur when trying to find an existing system of the same name
868 ;; to reuse options (e.g. pathname) from
869 (let ((s (system-registered-p ',name)))
870 (cond ((and s (eq (type-of (cdr s)) ',class))
871 (setf (car s) (get-universal-time)))
874 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
876 (change-class (cdr s) ',class))
878 (register-system (quote ,name)
879 (make-instance ',class :name ',name)))))
880 (parse-component-form nil (apply
882 :module (coerce-name ',name)
885 (pathname-sans-name+type
886 (resolve-symlinks *load-truename*))
887 *default-pathname-defaults*)
888 ',component-options))))))
891 (defun class-for-type (parent type)
894 (or (find-symbol (symbol-name type) *package*)
895 (find-symbol (symbol-name type) #.(package-name *package*)))
899 (or (module-default-component-class parent)
900 (find-class 'cl-source-file)))
901 (sysdef-error "~@<don't recognize component type ~A~@:>" type))))
903 (defun maybe-add-tree (tree op1 op2 c)
904 "Add the node C at /OP1/OP2 in TREE, unless it's there already.
905 Returns the new tree (which probably shares structure with the old one)"
906 (let ((first-op-tree (assoc op1 tree)))
909 (aif (assoc op2 (cdr first-op-tree))
910 (if (find c (cdr it))
912 (setf (cdr it) (cons c (cdr it))))
913 (setf (cdr first-op-tree)
914 (acons op2 (list c) (cdr first-op-tree))))
916 (acons op1 (list (list op2 c)) tree))))
918 (defun union-of-dependencies (&rest deps)
919 (let ((new-tree nil))
921 (dolist (op-tree dep)
922 (dolist (op (cdr op-tree))
925 (maybe-add-tree new-tree (car op-tree) (car op) c))))))
929 (defun remove-keys (key-names args)
930 (loop for ( name val ) on args by #'cddr
931 unless (member (symbol-name name) key-names
932 :key #'symbol-name :test 'equal)
933 append (list name val)))
935 (defvar *serial-depends-on*)
937 (defun parse-component-form (parent options)
939 (type name &rest rest &key
940 ;; the following list of keywords is reproduced below in the
941 ;; remove-keys form. important to keep them in sync
942 components pathname default-component-class
943 perform explain output-files operation-done-p
945 depends-on serial in-order-to
947 &allow-other-keys) options
948 (check-component-input type name weakly-depends-on depends-on components in-order-to)
951 (find-component parent name)
952 ;; ignore the same object when rereading the defsystem
954 (typep (find-component parent name)
955 (class-for-type parent type))))
956 (error 'duplicate-names :name name))
958 (let* ((other-args (remove-keys
959 '(components pathname default-component-class
960 perform explain output-files operation-done-p
962 depends-on serial in-order-to)
965 (or (find-component parent name)
966 (make-instance (class-for-type parent type)))))
967 (when weakly-depends-on
968 (setf depends-on (append depends-on (remove-if (complement #'find-system) weakly-depends-on))))
969 (when (boundp '*serial-depends-on*)
971 (concatenate 'list *serial-depends-on* depends-on)))
972 (apply #'reinitialize-instance
974 :name (coerce-name name)
978 (when (typep ret 'module)
979 (setf (module-default-component-class ret)
980 (or default-component-class
981 (and (typep parent 'module)
982 (module-default-component-class parent))))
983 (let ((*serial-depends-on* nil))
984 (setf (module-components ret)
985 (loop for c-form in components
986 for c = (parse-component-form ret c-form)
989 do (push (component-name c) *serial-depends-on*))))
991 ;; check for duplicate names
992 (let ((name-hash (make-hash-table :test #'equal)))
993 (loop for c in (module-components ret)
995 (if (gethash (component-name c)
997 (error 'duplicate-names
998 :name (component-name c))
999 (setf (gethash (component-name c)
1003 (setf (slot-value ret 'in-order-to)
1004 (union-of-dependencies
1006 `((compile-op (compile-op ,@depends-on))
1007 (load-op (load-op ,@depends-on))))
1008 (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
1010 (loop for (n v) in `((perform ,perform) (explain ,explain)
1011 (output-files ,output-files)
1012 (operation-done-p ,operation-done-p))
1014 ;; this is inefficient as most of the stored
1015 ;; methods will not be for this particular gf n
1016 ;; But this is hardly performance-critical
1017 (lambda (m) (remove-method (symbol-function n) m))
1018 (component-inline-methods ret))
1020 do (destructuring-bind (op qual (o c) &body body) v
1022 (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
1024 (component-inline-methods ret))))
1027 (defun check-component-input (type name weakly-depends-on depends-on components in-order-to)
1028 "A partial test of the values of a component."
1029 (when weakly-depends-on (warn "We got one! XXXXX"))
1030 (unless (listp depends-on)
1031 (sysdef-error-component ":depends-on must be a list."
1032 type name depends-on))
1033 (unless (listp weakly-depends-on)
1034 (sysdef-error-component ":weakly-depends-on must be a list."
1035 type name weakly-depends-on))
1036 (unless (listp components)
1037 (sysdef-error-component ":components must be NIL or a list of components."
1038 type name components))
1039 (unless (and (listp in-order-to) (listp (car in-order-to)))
1040 (sysdef-error-component ":in-order-to must be NIL or a list of components."
1041 type name in-order-to)))
1043 (defun sysdef-error-component (msg type name value)
1044 (sysdef-error (concatenate 'string msg
1045 "~&The value specified for ~(~A~) ~A is ~W")
1048 (defun resolve-symlinks (path)
1049 #-allegro (truename path)
1050 #+allegro (excl:pathname-resolve-symbolic-links path)
1055 ;;; run-shell-command functions for other lisp implementations will be
1056 ;;; gratefully accepted, if they do the same thing. If the docstring
1057 ;;; is ambiguous, send a bug report
1059 (defun run-shell-command (control-string &rest args)
1060 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
1061 synchronously execute the result using a Bourne-compatible shell, with
1062 output to *verbose-out*. Returns the shell's exit code."
1063 (let ((command (apply #'format nil control-string args)))
1064 (format *verbose-out* "; $ ~A~%" command)
1066 (sb-impl::process-exit-code
1070 :input nil :output *verbose-out*))
1073 (ext:process-exit-code
1077 :input nil :output *verbose-out*))
1080 (excl:run-shell-command command :input nil :output *verbose-out*)
1083 (system:call-system-showing-output
1085 :shell-type "/bin/sh"
1086 :output-stream *verbose-out*)
1088 #+clisp ;XXX not exactly *verbose-out*, I know
1089 (ext:run-shell-command command :output :terminal :wait t)
1093 (ccl:external-process-status
1094 (ccl:run-program "/bin/sh" (list "-c" command)
1095 :input nil :output *verbose-out*
1097 #+ecl ;; courtesy of Juan Jose Garcia Ripoll
1099 #-(or openmcl clisp lispworks allegro scl cmu sbcl ecl)
1100 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
1104 (defgeneric hyperdocumentation (package name doc-type))
1105 (defmethod hyperdocumentation ((package symbol) name doc-type)
1106 (hyperdocumentation (find-package package) name doc-type))
1108 (defun hyperdoc (name doc-type)
1109 (hyperdocumentation (symbol-package name) name doc-type))
1112 (pushnew :asdf *features*)
1115 (eval-when (:compile-toplevel :load-toplevel :execute)
1116 (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
1117 (pushnew :sbcl-hooks-require *features*)))
1119 #+(and sbcl sbcl-hooks-require)
1121 (defun module-provide-asdf (name)
1122 (handler-bind ((style-warning #'muffle-warning))
1123 (let* ((*verbose-out* (make-broadcast-stream))
1124 (system (asdf:find-system name nil)))
1126 (asdf:operate 'asdf:load-op name)
1129 (defun contrib-sysdef-search (system)
1130 (let* ((name (coerce-name system))
1131 (home (truename (sb-ext:posix-getenv "SBCL_HOME")))
1132 (contrib (merge-pathnames
1133 (make-pathname :directory `(:relative ,name)
1139 (probe-file contrib)))
1142 '(merge-pathnames "site-systems/"
1143 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1147 '(merge-pathnames ".sbcl/systems/"
1148 (user-homedir-pathname))
1151 (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*)
1152 (pushnew 'contrib-sysdef-search *system-definition-search-functions*))