1 ;;; This is asdf: Another System Definition Facility. 1.77
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 #:system-definition-error
95 #:circular-dependency ; errors
104 (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")
109 (defvar *asdf-revision* (let* ((v "1.77")
110 (colon (or (position #\: v) -1))
111 (dot (position #\. v)))
113 (list (parse-integer v :start (1+ colon)
115 (parse-integer v :start (1+ dot)
118 (defvar *compile-file-warnings-behaviour* :warn)
119 (defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
121 (defvar *verbose-out* *trace-output*)
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 (defmacro aif (test then &optional else)
127 `(let ((it ,test)) (if it ,then ,else)))
129 (defun pathname-sans-name+type (pathname)
130 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
131 and NIL NAME and TYPE components"
132 (make-pathname :name nil :type nil :defaults pathname))
134 (define-modify-macro appendf (&rest args)
135 append "Append onto list")
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 ;; classes, condiitons
140 (define-condition system-definition-error (error) ()
141 ;; [this use of :report should be redundant, but unfortunately it's not.
142 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
143 ;; over print-object; this is always conditions::%print-condition for
144 ;; condition objects, which in turn does inheritance of :report options at
145 ;; run-time. fortunately, inheritance means we only need this kludge here in
146 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
147 #+cmu (:report print-object))
149 (define-condition formatted-system-definition-error (system-definition-error)
150 ((format-control :initarg :format-control :reader format-control)
151 (format-arguments :initarg :format-arguments :reader format-arguments))
152 (:report (lambda (c s)
153 (apply #'format s (format-control c) (format-arguments c)))))
155 (define-condition circular-dependency (system-definition-error)
156 ((components :initarg :components :reader circular-dependency-components)))
158 (define-condition missing-component (system-definition-error)
159 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
160 (version :initform nil :reader missing-version :initarg :version)
161 (parent :initform nil :reader missing-parent :initarg :parent)))
163 (define-condition missing-dependency (missing-component)
164 ((required-by :initarg :required-by :reader missing-required-by)))
166 (define-condition operation-error (error)
167 ((component :reader error-component :initarg :component)
168 (operation :reader error-operation :initarg :operation))
169 (:report (lambda (c s)
170 (format s (formatter "~@<erred while invoking ~A on ~A~@:>")
171 (error-operation c) (error-component c)))))
172 (define-condition compile-error (operation-error) ())
173 (define-condition compile-failed (compile-error) ())
174 (define-condition compile-warned (compile-error) ())
176 (defclass component ()
177 ((name :type string :accessor component-name :initarg :name :documentation
178 "Component name, restricted to portable pathname characters")
179 (version :accessor component-version :initarg :version)
180 (in-order-to :initform nil :initarg :in-order-to)
182 (do-first :initform nil :initarg :do-first)
183 ;; methods defined using the "inline" style inside a defsystem form:
184 ;; need to store them somewhere so we can delete them when the system
186 (inline-methods :accessor component-inline-methods :initform nil)
187 (parent :initarg :parent :initform nil :reader component-parent)
188 ;; no direct accessor for pathname, we do this as a method to allow
189 ;; it to default in funky ways if not supplied
190 (relative-pathname :initarg :pathname)
191 (operation-times :initform (make-hash-table )
192 :accessor component-operation-times)
193 ;; XXX we should provide some atomic interface for updating the
194 ;; component properties
195 (properties :accessor component-properties :initarg :properties
198 ;;;; methods: conditions
200 (defmethod print-object ((c missing-dependency) s)
201 (format s (formatter "~@<~A, required by ~A~@:>")
202 (call-next-method c nil)
203 (missing-required-by c)))
205 (defun sysdef-error (format &rest arguments)
206 (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
208 ;;;; methods: components
210 (defmethod print-object ((c missing-component) s)
211 (format s (formatter "~@<component ~S not found~
212 ~@[ or does not match version ~A~]~
216 (when (missing-parent c)
217 (component-name (missing-parent c)))))
219 (defgeneric component-system (component)
220 (:documentation "Find the top-level system containing COMPONENT"))
222 (defmethod component-system ((component component))
223 (aif (component-parent component)
224 (component-system it)
227 (defmethod print-object ((c component) stream)
228 (print-unreadable-object (c stream :type t :identity t)
230 (prin1 (component-name c) stream))))
232 (defclass module (component)
233 ((components :initform nil :accessor module-components :initarg :components)
234 ;; what to do if we can't satisfy a dependency of one of this module's
235 ;; components. This allows a limited form of conditional processing
236 (if-component-dep-fails :initform :fail
237 :accessor module-if-component-dep-fails
238 :initarg :if-component-dep-fails)
239 (default-component-class :accessor module-default-component-class
240 :initform 'cl-source-file :initarg :default-component-class)))
242 (defgeneric component-pathname (component)
243 (:documentation "Extracts the pathname applicable for a particular component."))
245 (defun component-parent-pathname (component)
246 (aif (component-parent component)
247 (component-pathname it)
248 *default-pathname-defaults*))
250 (defgeneric component-relative-pathname (component)
251 (:documentation "Extracts the relative pathname applicable for a particular component."))
253 (defmethod component-relative-pathname ((component module))
254 (or (slot-value component 'relative-pathname)
256 :directory `(:relative ,(component-name component))
257 :host (pathname-host (component-parent-pathname component)))))
259 (defmethod component-pathname ((component component))
260 (let ((*default-pathname-defaults* (component-parent-pathname component)))
261 (merge-pathnames (component-relative-pathname component))))
263 (defgeneric component-property (component property))
265 (defmethod component-property ((c component) property)
266 (cdr (assoc property (slot-value c 'properties) :test #'equal)))
268 (defgeneric (setf component-property) (new-value component property))
270 (defmethod (setf component-property) (new-value (c component) property)
271 (let ((a (assoc property (slot-value c 'properties) :test #'equal)))
273 (setf (cdr a) new-value)
274 (setf (slot-value c 'properties)
275 (acons property new-value (slot-value c 'properties))))))
277 (defclass system (module)
278 ((description :accessor system-description :initarg :description)
280 :accessor system-long-description :initarg :long-description)
281 (author :accessor system-author :initarg :author)
282 (maintainer :accessor system-maintainer :initarg :maintainer)
283 (licence :accessor system-licence :initarg :licence)))
285 ;;; version-satisfies
287 ;;; with apologies to christophe rhodes ...
288 (defun split (string &optional max (ws '(#\Space #\Tab)))
289 (flet ((is-ws (char) (find char ws)))
291 (let ((list nil) (start 0) (words 0) end)
293 (when (and max (>= words (1- max)))
294 (return (cons (subseq string start) list)))
295 (setf end (position-if #'is-ws string :start start))
296 (push (subseq string start end) list)
298 (unless end (return list))
299 (setf start (1+ end)))))))
301 (defgeneric version-satisfies (component version))
303 (defmethod version-satisfies ((c component) version)
304 (unless (and version (slot-boundp c 'version))
305 (return-from version-satisfies t))
306 (let ((x (mapcar #'parse-integer
307 (split (component-version c) nil '(#\.))))
308 (y (mapcar #'parse-integer
309 (split version nil '(#\.)))))
310 (labels ((bigger (x y)
313 ((> (car x) (car y)) t)
315 (bigger (cdr x) (cdr y))))))
316 (and (= (car x) (car y))
317 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322 (defvar *defined-systems* (make-hash-table :test 'equal))
323 (defun coerce-name (name)
325 (component (component-name name))
326 (symbol (string-downcase (symbol-name name)))
328 (t (sysdef-error (formatter "~@<invalid component designator ~A~@:>")
331 ;;; for the sake of keeping things reasonably neat, we adopt a
332 ;;; convention that functions in this list are prefixed SYSDEF-
334 (defvar *system-definition-search-functions*
335 '(sysdef-central-registry-search))
337 (defun system-definition-pathname (system)
338 (some (lambda (x) (funcall x system))
339 *system-definition-search-functions*))
341 (defvar *central-registry*
342 '(*default-pathname-defaults*
343 #+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
344 #+nil "telent:asdf;systems;"))
346 (defun sysdef-central-registry-search (system)
347 (let ((name (coerce-name system)))
349 (dolist (dir *central-registry*)
350 (let* ((defaults (eval dir))
353 :defaults defaults :version :newest
354 :name name :type "asd" :case :local))))
355 (if (and file (probe-file file))
359 (defun find-system (name &optional (error-p t))
360 (let* ((name (coerce-name name))
361 (in-memory (gethash name *defined-systems*))
362 (on-disk (system-definition-pathname name)))
365 (< (car in-memory) (file-write-date on-disk))))
366 (let ((*package* (make-package (gensym (package-name #.*package*))
368 (format *verbose-out*
369 (formatter "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%")
370 ;; FIXME: This wants to be (ENOUGH-NAMESTRING
371 ;; ON-DISK), but CMUCL barfs on that.
375 (let ((in-memory (gethash name *defined-systems*)))
377 (progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
379 (if error-p (error 'missing-component :requires name))))))
381 (defun register-system (name system)
382 (format *verbose-out*
383 (formatter "~&~@<; ~@;registering ~A as ~A~@:>~%") system name)
384 (setf (gethash (coerce-name name) *defined-systems*)
385 (cons (get-universal-time) system)))
387 (defun system-registered-p (name)
388 (gethash (coerce-name name) *defined-systems*))
390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391 ;;; finding components
393 (defgeneric find-component (module name &optional version)
394 (:documentation "Finds the component with name NAME present in the
395 MODULE module; if MODULE is nil, then the component is assumed to be a
398 (defmethod find-component ((module module) name &optional version)
399 (if (slot-boundp module 'components)
400 (let ((m (find name (module-components module)
401 :test #'equal :key #'component-name)))
402 (if (and m (version-satisfies m version)) m))))
405 ;;; a component with no parent is a system
406 (defmethod find-component ((module (eql nil)) name &optional version)
407 (let ((m (find-system name nil)))
408 (if (and m (version-satisfies m version)) m)))
410 ;;; component subclasses
412 (defclass source-file (component) ())
414 (defclass cl-source-file (source-file) ())
415 (defclass c-source-file (source-file) ())
416 (defclass java-source-file (source-file) ())
417 (defclass static-file (source-file) ())
418 (defclass doc-file (static-file) ())
419 (defclass html-file (doc-file) ())
421 (defgeneric source-file-type (component system))
422 (defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
423 (defmethod source-file-type ((c c-source-file) (s module)) "c")
424 (defmethod source-file-type ((c java-source-file) (s module)) "java")
425 (defmethod source-file-type ((c html-file) (s module)) "html")
426 (defmethod source-file-type ((c static-file) (s module)) nil)
428 (defmethod component-relative-pathname ((component source-file))
429 (let* ((*default-pathname-defaults* (component-parent-pathname component))
432 :name (component-name component)
433 :type (source-file-type component
434 (component-system component)))))
435 (if (slot-value component 'relative-pathname)
437 (slot-value component 'relative-pathname)
441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
444 ;;; one of these is instantiated whenever (operate ) is called
446 (defclass operation ()
447 ((forced :initform nil :initarg :force :accessor operation-forced)
448 (original-initargs :initform nil :initarg :original-initargs
449 :accessor operation-original-initargs)
450 (visited-nodes :initform nil :accessor operation-visited-nodes)
451 (visiting-nodes :initform nil :accessor operation-visiting-nodes)
452 (parent :initform nil :initarg :parent :accessor operation-parent)))
454 (defmethod print-object ((o operation) stream)
455 (print-unreadable-object (o stream :type t :identity t)
457 (prin1 (operation-original-initargs o) stream))))
459 (defmethod shared-initialize :after ((operation operation) slot-names
462 (declare (ignore slot-names force))
463 ;; empty method to disable initarg validity checking
466 (defgeneric perform (operation component))
467 (defgeneric operation-done-p (operation component))
468 (defgeneric explain (operation component))
469 (defgeneric output-files (operation component))
470 (defgeneric input-files (operation component))
472 (defun node-for (o c)
473 (cons (class-name (class-of o)) c))
475 (defgeneric operation-ancestor (operation)
476 (:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
478 (defmethod operation-ancestor ((operation operation))
479 (aif (operation-parent operation)
480 (operation-ancestor it)
484 (defun make-sub-operation (c o dep-c dep-o)
485 (let* ((args (copy-list (operation-original-initargs o)))
486 (force-p (getf args :force)))
487 ;; note explicit comparison with T: any other non-NIL force value
488 ;; (e.g. :recursive) will pass through
489 (cond ((and (null (component-parent c))
490 (null (component-parent dep-c))
492 (when (eql force-p t)
493 (setf (getf args :force) nil))
494 (apply #'make-instance dep-o
496 :original-initargs args args))
497 ((subtypep (type-of o) dep-o)
500 (apply #'make-instance dep-o
501 :parent o :original-initargs args args)))))
504 (defgeneric visit-component (operation component data))
506 (defmethod visit-component ((o operation) (c component) data)
507 (unless (component-visited-p o c)
508 (push (cons (node-for o c) data)
509 (operation-visited-nodes (operation-ancestor o)))))
511 (defgeneric component-visited-p (operation component))
513 (defmethod component-visited-p ((o operation) (c component))
514 (assoc (node-for o c)
515 (operation-visited-nodes (operation-ancestor o))
518 (defgeneric (setf visiting-component) (new-value operation component))
520 (defmethod (setf visiting-component) (new-value operation component)
521 ;; MCL complains about unused lexical variables
522 (declare (ignorable new-value operation component)))
524 (defmethod (setf visiting-component) (new-value (o operation) (c component))
525 (let ((node (node-for o c))
526 (a (operation-ancestor o)))
528 (pushnew node (operation-visiting-nodes a) :test 'equal)
529 (setf (operation-visiting-nodes a)
530 (remove node (operation-visiting-nodes a) :test 'equal)))))
532 (defgeneric component-visiting-p (operation component))
534 (defmethod component-visiting-p ((o operation) (c component))
535 (let ((node (cons o c)))
536 (member node (operation-visiting-nodes (operation-ancestor o))
539 (defgeneric component-depends-on (operation component))
541 (defmethod component-depends-on ((o operation) (c component))
542 (cdr (assoc (class-name (class-of o))
543 (slot-value c 'in-order-to))))
545 (defgeneric component-self-dependencies (operation component))
547 (defmethod component-self-dependencies ((o operation) (c component))
548 (let ((all-deps (component-depends-on o c)))
549 (remove-if-not (lambda (x)
550 (member (component-name c) (cdr x) :test #'string=))
553 (defmethod input-files ((operation operation) (c component))
554 (let ((parent (component-parent c))
555 (self-deps (component-self-dependencies operation c)))
557 (mapcan (lambda (dep)
558 (destructuring-bind (op name) dep
559 (output-files (make-instance op)
560 (find-component parent name))))
562 ;; no previous operations needed? I guess we work with the
563 ;; original source file, then
564 (list (component-pathname c)))))
566 (defmethod input-files ((operation operation) (c module)) nil)
568 (defmethod operation-done-p ((o operation) (c component))
569 (let ((out-files (output-files o c))
570 (in-files (input-files o c)))
571 (cond ((and (not in-files) (not out-files))
572 ;; arbitrary decision: an operation that uses nothing to
573 ;; produce nothing probably isn't doing much
578 (component-operation-times c))))
582 (mapcar #'file-write-date in-files)) 0)))))
586 (every #'probe-file out-files)
587 (> (apply #'min (mapcar #'file-write-date out-files))
588 (apply #'max (mapcar #'file-write-date in-files)) ))))))
590 ;;; So you look at this code and think "why isn't it a bunch of
591 ;;; methods". And the answer is, because standard method combination
592 ;;; runs :before methods most->least-specific, which is back to front
593 ;;; for our purposes. And CLISP doesn't have non-standard method
594 ;;; combinations, so let's keep it simple and aspire to portability
596 (defgeneric traverse (operation component))
597 (defmethod traverse ((operation operation) (c component))
599 (labels ((do-one-dep (required-op required-c required-v)
600 (let* ((dep-c (or (find-component
602 ;; XXX tacky. really we should build the
603 ;; in-order-to slot with canonicalized
604 ;; names instead of coercing this late
605 (coerce-name required-c) required-v)
606 (error 'missing-dependency :required-by c
608 :requires required-c)))
609 (op (make-sub-operation c operation dep-c required-op)))
610 (traverse op dep-c)))
612 (cond ((eq op 'feature)
613 (or (member (car dep) *features*)
614 (error 'missing-dependency :required-by c
615 :requires (car dep) :version nil)))
619 (assert (string-equal
620 (symbol-name (first d))
623 (do-one-dep op (second d) (third d))))
625 (appendf forced (do-one-dep op d nil)))))))))
626 (aif (component-visited-p operation c)
627 (return-from traverse
628 (if (cdr it) (list (cons 'pruned-op c)) nil)))
630 (if (component-visiting-p operation c)
631 (error 'circular-dependency :components (list c)))
632 (setf (visiting-component operation c) t)
633 (loop for (required-op . deps) in (component-depends-on operation c)
634 do (do-dep required-op deps))
637 (when (typep c 'module)
638 (let ((at-least-one nil)
641 (loop for kid in (module-components c)
643 (appendf forced (traverse operation kid ))
644 (missing-dependency (condition)
645 (if (eq (module-if-component-dep-fails c) :fail)
647 (setf error condition))
650 (setf at-least-one t))))
651 (when (and (eq (module-if-component-dep-fails c) :try-next)
655 ;; now the thing itself
656 (when (or forced module-ops
657 (not (operation-done-p operation c))
658 (let ((f (operation-forced (operation-ancestor operation))))
659 (and f (or (not (consp f))
660 (member (component-name
661 (operation-ancestor operation))
662 (mapcar #'coerce-name f)
664 (let ((do-first (cdr (assoc (class-name (class-of operation))
665 (slot-value c 'do-first)))))
666 (loop for (required-op . deps) in do-first
667 do (do-dep required-op deps)))
668 (setf forced (append (delete 'pruned-op forced :key #'car)
669 (delete 'pruned-op module-ops :key #'car)
670 (list (cons operation c))))))
671 (setf (visiting-component operation c) nil)
672 (visit-component operation c (and forced t))
676 (defmethod perform ((operation operation) (c source-file))
678 (formatter "~@<required method PERFORM not implemented~
679 for operation ~A, component ~A~@:>")
680 (class-of operation) (class-of c)))
682 (defmethod perform ((operation operation) (c module))
685 (defmethod explain ((operation operation) (component component))
686 (format *verbose-out* "~&;;; ~A on ~A~%"
687 operation component))
691 (defclass compile-op (operation)
692 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
693 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
694 :initform *compile-file-warnings-behaviour*)
695 (on-failure :initarg :on-failure :accessor operation-on-failure
696 :initform *compile-file-failure-behaviour*)))
698 (defmethod perform :before ((operation compile-op) (c source-file))
699 (map nil #'ensure-directories-exist (output-files operation c)))
701 (defmethod perform :after ((operation operation) (c component))
702 (setf (gethash (type-of operation) (component-operation-times c))
703 (get-universal-time)))
705 ;;; perform is required to check output-files to find out where to put
706 ;;; its answers, in case it has been overridden for site policy
707 (defmethod perform ((operation compile-op) (c cl-source-file))
708 (let ((source-file (component-pathname c))
709 (output-file (car (output-files operation c))))
710 (multiple-value-bind (output warnings-p failure-p)
711 (compile-file source-file
712 :output-file output-file)
713 ;(declare (ignore output))
715 (case (operation-on-warnings operation)
717 (formatter "~@<COMPILE-FILE warned while ~
718 performing ~A on ~A.~@:>")
720 (:error (error 'compile-warned :component c :operation operation))
723 (case (operation-on-failure operation)
725 (formatter "~@<COMPILE-FILE failed while ~
726 performing ~A on ~A.~@:>")
728 (:error (error 'compile-failed :component c :operation operation))
731 (error 'compile-error :component c :operation operation)))))
733 (defmethod output-files ((operation compile-op) (c cl-source-file))
734 (list (compile-file-pathname (component-pathname c))))
736 (defmethod perform ((operation compile-op) (c static-file))
739 (defmethod output-files ((operation compile-op) (c static-file))
744 (defclass load-op (operation) ())
746 (defmethod perform ((o load-op) (c cl-source-file))
747 (mapcar #'load (input-files o c)))
749 (defmethod perform ((operation load-op) (c static-file))
751 (defmethod operation-done-p ((operation load-op) (c static-file))
754 (defmethod output-files ((o operation) (c component))
757 (defmethod component-depends-on ((operation load-op) (c component))
758 (cons (list 'compile-op (component-name c))
763 (defclass load-source-op (operation) ())
765 (defmethod perform ((o load-source-op) (c cl-source-file))
766 (let ((source (component-pathname c)))
767 (setf (component-property c 'last-loaded-as-source)
769 (get-universal-time)))))
771 (defmethod perform ((operation load-source-op) (c static-file))
774 (defmethod output-files ((operation load-source-op) (c component))
777 ;;; FIXME: we simply copy load-op's dependencies. this is Just Not Right.
778 (defmethod component-depends-on ((o load-source-op) (c component))
779 (let ((what-would-load-op-do (cdr (assoc 'load-op
780 (slot-value c 'in-order-to)))))
781 (mapcar (lambda (dep)
782 (if (eq (car dep) 'load-op)
783 (cons 'load-source-op (cdr dep))
785 what-would-load-op-do)))
787 (defmethod operation-done-p ((o load-source-op) (c source-file))
788 (if (or (not (component-property c 'last-loaded-as-source))
789 (> (file-write-date (component-pathname c))
790 (component-property c 'last-loaded-as-source)))
793 (defclass test-op (operation) ())
795 (defmethod perform ((operation test-op) (c component))
798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
799 ;;; invoking operations
801 (defun operate (operation-class system &rest args)
802 (let* ((op (apply #'make-instance operation-class
803 :original-initargs args args))
805 (if (getf args :verbose t)
807 (make-broadcast-stream)))
808 (system (if (typep system 'component) system (find-system system)))
809 (steps (traverse op system)))
810 (with-compilation-unit ()
811 (loop for (op . component) in steps do
814 (progn (perform op component)
820 (formatter "~@<Retry performing ~S on ~S.~@:>")
826 (formatter "~@<Continue, treating ~S on ~S as ~
827 having been successful.~@:>")
829 (setf (gethash (type-of op)
830 (component-operation-times component))
831 (get-universal-time))
834 (defun oos (&rest args)
835 "Alias of OPERATE function"
836 (apply #'operate args))
838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841 (defun remove-keyword (key arglist)
842 (labels ((aux (key arglist)
843 (cond ((null arglist) nil)
844 ((eq key (car arglist)) (cddr arglist))
845 (t (cons (car arglist) (cons (cadr arglist)
847 key (cddr arglist))))))))
850 (defmacro defsystem (name &body options)
851 (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
852 (let ((component-options (remove-keyword :class options)))
854 ;; system must be registered before we parse the body, otherwise
855 ;; we recur when trying to find an existing system of the same name
856 ;; to reuse options (e.g. pathname) from
857 (let ((s (system-registered-p ',name)))
858 (cond ((and s (eq (type-of (cdr s)) ',class))
859 (setf (car s) (get-universal-time)))
862 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
864 (change-class (cdr s) ',class))
866 (register-system (quote ,name)
867 (make-instance ',class :name ',name)))))
868 (parse-component-form nil (apply
870 :module (coerce-name ',name)
873 (pathname-sans-name+type
874 (resolve-symlinks *load-truename*))
875 *default-pathname-defaults*)
876 ',component-options))))))
879 (defun class-for-type (parent type)
880 (let ((class (find-class
881 (or (find-symbol (symbol-name type) *package*)
882 (find-symbol (symbol-name type) #.*package*)) nil)))
885 (or (module-default-component-class parent)
886 (find-class 'cl-source-file)))
887 (sysdef-error (formatter "~@<don't recognize component type ~A~@:>")
890 (defun maybe-add-tree (tree op1 op2 c)
891 "Add the node C at /OP1/OP2 in TREE, unless it's there already.
892 Returns the new tree (which probably shares structure with the old one)"
893 (let ((first-op-tree (assoc op1 tree)))
896 (aif (assoc op2 (cdr first-op-tree))
897 (if (find c (cdr it))
899 (setf (cdr it) (cons c (cdr it))))
900 (setf (cdr first-op-tree)
901 (acons op2 (list c) (cdr first-op-tree))))
903 (acons op1 (list (list op2 c)) tree))))
905 (defun union-of-dependencies (&rest deps)
906 (let ((new-tree nil))
908 (dolist (op-tree dep)
909 (dolist (op (cdr op-tree))
912 (maybe-add-tree new-tree (car op-tree) (car op) c))))))
916 (defun remove-keys (key-names args)
917 (loop for ( name val ) on args by #'cddr
918 unless (member (symbol-name name) key-names
919 :key #'symbol-name :test 'equal)
920 append (list name val)))
922 (defvar *serial-depends-on*)
924 (defun parse-component-form (parent options)
926 (type name &rest rest &key
927 ;; the following list of keywords is reproduced below in the
928 ;; remove-keys form. important to keep them in sync
929 components pathname default-component-class
930 perform explain output-files operation-done-p
931 depends-on serial in-order-to
933 &allow-other-keys) options
934 (check-component-input type name depends-on components in-order-to)
935 (let* ((other-args (remove-keys
936 '(components pathname default-component-class
937 perform explain output-files operation-done-p
938 depends-on serial in-order-to)
941 (or (find-component parent name)
942 (make-instance (class-for-type parent type)))))
943 (when (boundp '*serial-depends-on*)
945 (concatenate 'list *serial-depends-on* depends-on)))
946 (apply #'reinitialize-instance
948 :name (coerce-name name)
952 (when (typep ret 'module)
953 (setf (module-default-component-class ret)
954 (or default-component-class
955 (and (typep parent 'module)
956 (module-default-component-class parent))))
957 (let ((*serial-depends-on* nil))
958 (setf (module-components ret)
959 (loop for c-form in components
960 for c = (parse-component-form ret c-form)
963 do (push (component-name c) *serial-depends-on*)))))
965 (setf (slot-value ret 'in-order-to)
966 (union-of-dependencies
968 `((compile-op (compile-op ,@depends-on))
969 (load-op (load-op ,@depends-on))))
970 (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
972 (loop for (n v) in `((perform ,perform) (explain ,explain)
973 (output-files ,output-files)
974 (operation-done-p ,operation-done-p))
976 ;; this is inefficient as most of the stored
977 ;; methods will not be for this particular gf n
978 ;; But this is hardly performance-critical
979 (lambda (m) (remove-method (symbol-function n) m))
980 (component-inline-methods ret))
982 do (destructuring-bind (op qual (o c) &body body) v
984 (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
986 (component-inline-methods ret))))
989 (defun check-component-input (type name depends-on components in-order-to)
990 "A partial test of the values of a component."
991 (unless (listp depends-on)
992 (sysdef-error-component ":depends-on must be a list."
993 type name depends-on))
994 (unless (listp components)
995 (sysdef-error-component ":components must be NIL or a list of components."
996 type name components))
997 (unless (and (listp in-order-to) (listp (car in-order-to)))
998 (sysdef-error-component ":in-order-to must be NIL or a list of components."
999 type name in-order-to)))
1001 (defun sysdef-error-component (msg type name value)
1002 (sysdef-error (concatenate 'string msg
1003 "~&The value specified for ~(~A~) ~A is ~W")
1006 (defun resolve-symlinks (path)
1007 #-allegro (truename path)
1008 #+allegro (excl:pathname-resolve-symbolic-links path)
1013 ;;; run-shell-command functions for other lisp implementations will be
1014 ;;; gratefully accepted, if they do the same thing. If the docstring
1015 ;;; is ambiguous, send a bug report
1017 (defun run-shell-command (control-string &rest args)
1018 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
1019 synchronously execute the result using a Bourne-compatible shell, with
1020 output to *verbose-out*. Returns the shell's exit code."
1021 (let ((command (apply #'format nil control-string args)))
1022 (format *verbose-out* "; $ ~A~%" command)
1024 (sb-impl::process-exit-code
1028 :input nil :output *verbose-out*))
1031 (ext:process-exit-code
1035 :input nil :output *verbose-out*))
1038 (excl:run-shell-command command :input nil :output *verbose-out*)
1041 (system:call-system-showing-output
1043 :shell-type "/bin/sh"
1044 :output-stream *verbose-out*)
1046 #+clisp ;XXX not exactly *verbose-out*, I know
1047 (ext:run-shell-command command :output :terminal :wait t)
1051 (ccl:external-process-status
1052 (ccl:run-program "/bin/sh" (list "-c" command)
1053 :input nil :output *verbose-out*
1056 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
1057 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
1061 (defgeneric hyperdocumentation (package name doc-type))
1062 (defmethod hyperdocumentation ((package symbol) name doc-type)
1063 (hyperdocumentation (find-package package) name doc-type))
1065 (defun hyperdoc (name doc-type)
1066 (hyperdocumentation (symbol-package name) name doc-type))
1069 (pushnew :asdf *features*)
1072 (eval-when (:compile-toplevel :load-toplevel :execute)
1073 (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
1074 (pushnew :sbcl-hooks-require *features*)))
1076 #+(and sbcl sbcl-hooks-require)
1078 (defun module-provide-asdf (name)
1079 (handler-bind ((style-warning #'muffle-warning))
1080 (let* ((*verbose-out* (make-broadcast-stream))
1081 (system (asdf:find-system name nil)))
1083 (asdf:operate 'asdf:load-op name)
1087 '(merge-pathnames "systems/"
1088 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1092 '(merge-pathnames "site-systems/"
1093 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1097 '(merge-pathnames ".sbcl/systems/"
1098 (user-homedir-pathname))
1101 (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))