1 ;;; This is asdf: Another System Definition Facility. 1.75
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
75 #:operation-on-warnings
76 #:operation-on-failure
78 ;#:*component-parent-pathname*
79 #:*central-registry* ; variables
80 #:*compile-file-warnings-behaviour*
81 #:*compile-file-failure-behaviour*
83 #:operation-error #:compile-failed #:compile-warned #:compile-error
84 #:system-definition-error
87 #:circular-dependency ; errors
92 (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")
97 (defvar *asdf-revision* (let* ((v "1.75")
98 (colon (or (position #\: v) -1))
99 (dot (position #\. v)))
101 (list (parse-integer v :start (1+ colon)
103 (parse-integer v :start (1+ dot)
106 (defvar *compile-file-warnings-behaviour* :warn)
107 (defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
109 (defvar *verbose-out* *trace-output*)
111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (defmacro aif (test then &optional else)
115 `(let ((it ,test)) (if it ,then ,else)))
117 (defun pathname-sans-name+type (pathname)
118 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
119 and NIL NAME and TYPE components"
120 (make-pathname :name nil :type nil :defaults pathname))
122 (define-modify-macro appendf (&rest args)
123 append "Append onto list")
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 ;; classes, condiitons
128 (define-condition system-definition-error (error) ()
129 ;; [this use of :report should be redundant, but unfortunately it's not.
130 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
131 ;; over print-object; this is always conditions::%print-condition for
132 ;; condition objects, which in turn does inheritance of :report options at
133 ;; run-time. fortunately, inheritance means we only need this kludge here in
134 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
135 #+cmu (:report print-object))
137 (define-condition formatted-system-definition-error (system-definition-error)
138 ((format-control :initarg :format-control :reader format-control)
139 (format-arguments :initarg :format-arguments :reader format-arguments))
140 (:report (lambda (c s)
141 (apply #'format s (format-control c) (format-arguments c)))))
143 (define-condition circular-dependency (system-definition-error)
144 ((components :initarg :components :reader circular-dependency-components)))
146 (define-condition missing-component (system-definition-error)
147 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
148 (version :initform nil :reader missing-version :initarg :version)
149 (parent :initform nil :reader missing-parent :initarg :parent)))
151 (define-condition missing-dependency (missing-component)
152 ((required-by :initarg :required-by :reader missing-required-by)))
154 (define-condition operation-error (error)
155 ((component :reader error-component :initarg :component)
156 (operation :reader error-operation :initarg :operation))
157 (:report (lambda (c s)
158 (format s (formatter "~@<erred while invoking ~A on ~A~@:>")
159 (error-operation c) (error-component c)))))
160 (define-condition compile-error (operation-error) ())
161 (define-condition compile-failed (compile-error) ())
162 (define-condition compile-warned (compile-error) ())
164 (defclass component ()
165 ((name :type string :accessor component-name :initarg :name :documentation
166 "Component name, restricted to portable pathname characters")
167 (version :accessor component-version :initarg :version)
168 (in-order-to :initform nil :initarg :in-order-to)
170 (do-first :initform nil :initarg :do-first)
171 ;; methods defined using the "inline" style inside a defsystem form:
172 ;; need to store them somewhere so we can delete them when the system
174 (inline-methods :accessor component-inline-methods :initform nil)
175 (parent :initarg :parent :initform nil :reader component-parent)
176 ;; no direct accessor for pathname, we do this as a method to allow
177 ;; it to default in funky ways if not supplied
178 (relative-pathname :initarg :pathname)
179 (operation-times :initform (make-hash-table )
180 :accessor component-operation-times)
181 ;; XXX we should provide some atomic interface for updating the
182 ;; component properties
183 (properties :accessor component-properties :initarg :properties
186 ;;;; methods: conditions
188 (defmethod print-object ((c missing-dependency) s)
189 (format s (formatter "~@<~A, required by ~A~@:>")
190 (call-next-method c nil)
191 (missing-required-by c)))
193 (defun sysdef-error (format &rest arguments)
194 (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
196 ;;;; methods: components
198 (defmethod print-object ((c missing-component) s)
199 (format s (formatter "~@<component ~S not found~
200 ~@[ or does not match version ~A~]~
204 (when (missing-parent c)
205 (component-name (missing-parent c)))))
207 (defgeneric component-system (component)
208 (:documentation "Find the top-level system containing COMPONENT"))
210 (defmethod component-system ((component component))
211 (aif (component-parent component)
212 (component-system it)
215 (defmethod print-object ((c component) stream)
216 (print-unreadable-object (c stream :type t :identity t)
218 (prin1 (component-name c) stream))))
220 (defclass module (component)
221 ((components :initform nil :accessor module-components :initarg :components)
222 ;; what to do if we can't satisfy a dependency of one of this module's
223 ;; components. This allows a limited form of conditional processing
224 (if-component-dep-fails :initform :fail
225 :accessor module-if-component-dep-fails
226 :initarg :if-component-dep-fails)
227 (default-component-class :accessor module-default-component-class
228 :initform 'cl-source-file :initarg :default-component-class)))
230 (defgeneric component-pathname (component)
231 (:documentation "Extracts the pathname applicable for a particular component."))
233 (defun component-parent-pathname (component)
234 (aif (component-parent component)
235 (component-pathname it)
236 *default-pathname-defaults*))
238 (defgeneric component-relative-pathname (component)
239 (:documentation "Extracts the relative pathname applicable for a particular component."))
241 (defmethod component-relative-pathname ((component module))
242 (or (slot-value component 'relative-pathname)
244 :directory `(:relative ,(component-name component))
245 :host (pathname-host (component-parent-pathname component)))))
247 (defmethod component-pathname ((component component))
248 (let ((*default-pathname-defaults* (component-parent-pathname component)))
249 (merge-pathnames (component-relative-pathname component))))
251 (defgeneric component-property (component property))
253 (defmethod component-property ((c component) property)
254 (cdr (assoc property (slot-value c 'properties))))
256 (defgeneric (setf component-property) (new-value component property))
258 (defmethod (setf component-property) (new-value (c component) property)
259 (let ((a (assoc property (slot-value c 'properties))))
261 (setf (cdr a) new-value)
262 (setf (slot-value c 'properties)
263 (acons property new-value (slot-value c 'properties))))))
267 (defclass system (module)
268 ((description :accessor system-description :initarg :description)
269 (long-description :accessor long-description :initarg :long-description)
270 (author :accessor system-author :initarg :author)
271 (maintainer :accessor system-maintainer :initarg :maintainer)
272 (licence :accessor system-licence :initarg :licence)))
274 ;;; version-satisfies
276 ;;; with apologies to christophe rhodes ...
277 (defun split (string &optional max (ws '(#\Space #\Tab)))
278 (flet ((is-ws (char) (find char ws)))
280 (let ((list nil) (start 0) (words 0) end)
282 (when (and max (>= words (1- max)))
283 (return (cons (subseq string start) list)))
284 (setf end (position-if #'is-ws string :start start))
285 (push (subseq string start end) list)
287 (unless end (return list))
288 (setf start (1+ end)))))))
290 (defgeneric version-satisfies (component version))
292 (defmethod version-satisfies ((c component) version)
293 (unless (and version (slot-boundp c 'version))
294 (return-from version-satisfies t))
295 (let ((x (mapcar #'parse-integer
296 (split (component-version c) nil '(#\.))))
297 (y (mapcar #'parse-integer
298 (split version nil '(#\.)))))
299 (labels ((bigger (x y)
302 ((> (car x) (car y)) t)
304 (bigger (cdr x) (cdr y))))))
305 (and (= (car x) (car y))
306 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
311 (defvar *defined-systems* (make-hash-table :test 'equal))
312 (defun coerce-name (name)
314 (component (component-name name))
315 (symbol (string-downcase (symbol-name name)))
317 (t (sysdef-error (formatter "~@<invalid component designator ~A~@:>")
320 ;;; for the sake of keeping things reasonably neat, we adopt a
321 ;;; convention that functions in this list are prefixed SYSDEF-
323 (defvar *system-definition-search-functions*
324 '(sysdef-central-registry-search))
326 (defun system-definition-pathname (system)
327 (some (lambda (x) (funcall x system))
328 *system-definition-search-functions*))
330 (defvar *central-registry*
331 '(*default-pathname-defaults*
332 #+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
333 #+nil "telent:asdf;systems;"))
335 (defun sysdef-central-registry-search (system)
336 (let ((name (coerce-name system)))
338 (dolist (dir *central-registry*)
339 (let* ((defaults (eval dir))
342 :defaults defaults :version :newest
343 :name name :type "asd" :case :local))))
344 (if (and file (probe-file file))
348 (defun find-system (name &optional (error-p t))
349 (let* ((name (coerce-name name))
350 (in-memory (gethash name *defined-systems*))
351 (on-disk (system-definition-pathname name)))
354 (< (car in-memory) (file-write-date on-disk))))
355 (let ((*package* (make-package (gensym (package-name #.*package*))
357 (format *verbose-out*
358 (formatter "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%")
359 ;; FIXME: This wants to be (ENOUGH-NAMESTRING
360 ;; ON-DISK), but CMUCL barfs on that.
364 (let ((in-memory (gethash name *defined-systems*)))
366 (progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
368 (if error-p (error 'missing-component :requires name))))))
370 (defun register-system (name system)
371 (format *verbose-out*
372 (formatter "~&~@<; ~@;registering ~A as ~A~@:>~%") system name)
373 (setf (gethash (coerce-name name) *defined-systems*)
374 (cons (get-universal-time) system)))
376 (defun system-registered-p (name)
377 (gethash (coerce-name name) *defined-systems*))
379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
380 ;;; finding components
382 (defgeneric find-component (module name &optional version)
383 (:documentation "Finds the component with name NAME present in the
384 MODULE module; if MODULE is nil, then the component is assumed to be a
387 (defmethod find-component ((module module) name &optional version)
388 (if (slot-boundp module 'components)
389 (let ((m (find name (module-components module)
390 :test #'equal :key #'component-name)))
391 (if (and m (version-satisfies m version)) m))))
394 ;;; a component with no parent is a system
395 (defmethod find-component ((module (eql nil)) name &optional version)
396 (let ((m (find-system name nil)))
397 (if (and m (version-satisfies m version)) m)))
399 ;;; component subclasses
401 (defclass source-file (component) ())
403 (defclass cl-source-file (source-file) ())
404 (defclass c-source-file (source-file) ())
405 (defclass java-source-file (source-file) ())
406 (defclass static-file (source-file) ())
407 (defclass doc-file (static-file) ())
408 (defclass html-file (doc-file) ())
410 (defgeneric source-file-type (component system))
411 (defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
412 (defmethod source-file-type ((c c-source-file) (s module)) "c")
413 (defmethod source-file-type ((c java-source-file) (s module)) "java")
414 (defmethod source-file-type ((c html-file) (s module)) "html")
415 (defmethod source-file-type ((c static-file) (s module)) nil)
417 (defmethod component-relative-pathname ((component source-file))
418 (let* ((*default-pathname-defaults* (component-parent-pathname component))
421 :name (component-name component)
422 :type (source-file-type component
423 (component-system component)))))
424 (if (slot-value component 'relative-pathname)
426 (slot-value component 'relative-pathname)
430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
433 ;;; one of these is instantiated whenever (operate ) is called
435 (defclass operation ()
436 ((forced :initform nil :initarg :force :accessor operation-forced)
437 (original-initargs :initform nil :initarg :original-initargs
438 :accessor operation-original-initargs)
439 (visited-nodes :initform nil :accessor operation-visited-nodes)
440 (visiting-nodes :initform nil :accessor operation-visiting-nodes)
441 (parent :initform nil :initarg :parent :accessor operation-parent)))
443 (defmethod print-object ((o operation) stream)
444 (print-unreadable-object (o stream :type t :identity t)
446 (prin1 (operation-original-initargs o) stream))))
448 (defmethod shared-initialize :after ((operation operation) slot-names
451 (declare (ignore slot-names force))
452 ;; empty method to disable initarg validity checking
455 (defgeneric perform (operation component))
456 (defgeneric operation-done-p (operation component))
457 (defgeneric explain (operation component))
458 (defgeneric output-files (operation component))
459 (defgeneric input-files (operation component))
461 (defun node-for (o c)
462 (cons (class-name (class-of o)) c))
464 (defgeneric operation-ancestor (operation)
465 (:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
467 (defmethod operation-ancestor ((operation operation))
468 (aif (operation-parent operation)
469 (operation-ancestor it)
473 (defun make-sub-operation (c o dep-c dep-o)
474 (let* ((args (copy-list (operation-original-initargs o)))
475 (force-p (getf args :force)))
476 ;; note explicit comparison with T: any other non-NIL force value
477 ;; (e.g. :recursive) will pass through
478 (cond ((and (null (component-parent c))
479 (null (component-parent dep-c))
481 (when (eql force-p t)
482 (setf (getf args :force) nil))
483 (apply #'make-instance dep-o
485 :original-initargs args args))
486 ((subtypep (type-of o) dep-o)
489 (apply #'make-instance dep-o
490 :parent o :original-initargs args args)))))
493 (defgeneric visit-component (operation component data))
495 (defmethod visit-component ((o operation) (c component) data)
496 (unless (component-visited-p o c)
497 (push (cons (node-for o c) data)
498 (operation-visited-nodes (operation-ancestor o)))))
500 (defgeneric component-visited-p (operation component))
502 (defmethod component-visited-p ((o operation) (c component))
503 (assoc (node-for o c)
504 (operation-visited-nodes (operation-ancestor o))
507 (defgeneric (setf visiting-component) (new-value operation component))
509 (defmethod (setf visiting-component) (new-value operation component)
510 ;; MCL complains about unused lexical variables
511 (declare (ignorable new-value operation component)))
513 (defmethod (setf visiting-component) (new-value (o operation) (c component))
514 (let ((node (node-for o c))
515 (a (operation-ancestor o)))
517 (pushnew node (operation-visiting-nodes a) :test 'equal)
518 (setf (operation-visiting-nodes a)
519 (remove node (operation-visiting-nodes a) :test 'equal)))))
521 (defgeneric component-visiting-p (operation component))
523 (defmethod component-visiting-p ((o operation) (c component))
524 (let ((node (cons o c)))
525 (member node (operation-visiting-nodes (operation-ancestor o))
528 (defgeneric component-depends-on (operation component))
530 (defmethod component-depends-on ((o operation) (c component))
531 (cdr (assoc (class-name (class-of o))
532 (slot-value c 'in-order-to))))
534 (defgeneric component-self-dependencies (operation component))
536 (defmethod component-self-dependencies ((o operation) (c component))
537 (let ((all-deps (component-depends-on o c)))
538 (remove-if-not (lambda (x)
539 (member (component-name c) (cdr x) :test #'string=))
542 (defmethod input-files ((operation operation) (c component))
543 (let ((parent (component-parent c))
544 (self-deps (component-self-dependencies operation c)))
546 (mapcan (lambda (dep)
547 (destructuring-bind (op name) dep
548 (output-files (make-instance op)
549 (find-component parent name))))
551 ;; no previous operations needed? I guess we work with the
552 ;; original source file, then
553 (list (component-pathname c)))))
555 (defmethod input-files ((operation operation) (c module)) nil)
557 (defmethod operation-done-p ((o operation) (c component))
558 (let ((out-files (output-files o c))
559 (in-files (input-files o c)))
560 (cond ((and (not in-files) (not out-files))
561 ;; arbitrary decision: an operation that uses nothing to
562 ;; produce nothing probably isn't doing much
567 (component-operation-times c))))
571 (mapcar #'file-write-date in-files)) 0)))))
575 (every #'probe-file out-files)
576 (> (apply #'min (mapcar #'file-write-date out-files))
577 (apply #'max (mapcar #'file-write-date in-files)) ))))))
579 ;;; So you look at this code and think "why isn't it a bunch of
580 ;;; methods". And the answer is, because standard method combination
581 ;;; runs :before methods most->least-specific, which is back to front
582 ;;; for our purposes. And CLISP doesn't have non-standard method
583 ;;; combinations, so let's keep it simple and aspire to portability
585 (defgeneric traverse (operation component))
586 (defmethod traverse ((operation operation) (c component))
588 (labels ((do-one-dep (required-op required-c required-v)
589 (let* ((dep-c (or (find-component
591 ;; XXX tacky. really we should build the
592 ;; in-order-to slot with canonicalized
593 ;; names instead of coercing this late
594 (coerce-name required-c) required-v)
595 (error 'missing-dependency :required-by c
597 :requires required-c)))
598 (op (make-sub-operation c operation dep-c required-op)))
599 (traverse op dep-c)))
601 (cond ((eq op 'feature)
602 (or (member (car dep) *features*)
603 (error 'missing-dependency :required-by c
604 :requires (car dep) :version nil)))
608 (assert (string-equal
609 (symbol-name (first d))
612 (do-one-dep op (second d) (third d))))
614 (appendf forced (do-one-dep op d nil)))))))))
615 (aif (component-visited-p operation c)
616 (return-from traverse
617 (if (cdr it) (list (cons 'pruned-op c)) nil)))
619 (if (component-visiting-p operation c)
620 (error 'circular-dependency :components (list c)))
621 (setf (visiting-component operation c) t)
622 (loop for (required-op . deps) in (component-depends-on operation c)
623 do (do-dep required-op deps))
626 (when (typep c 'module)
627 (let ((at-least-one nil)
630 (loop for kid in (module-components c)
632 (appendf forced (traverse operation kid ))
633 (missing-dependency (condition)
634 (if (eq (module-if-component-dep-fails c) :fail)
636 (setf error condition))
639 (setf at-least-one t))))
640 (when (and (eq (module-if-component-dep-fails c) :try-next)
644 ;; now the thing itself
645 (when (or forced module-ops
646 (not (operation-done-p operation c))
647 (let ((f (operation-forced (operation-ancestor operation))))
648 (and f (or (not (consp f))
649 (member (component-name
650 (operation-ancestor operation))
651 (mapcar #'coerce-name f)
653 (let ((do-first (cdr (assoc (class-name (class-of operation))
654 (slot-value c 'do-first)))))
655 (loop for (required-op . deps) in do-first
656 do (do-dep required-op deps)))
657 (setf forced (append (delete 'pruned-op forced :key #'car)
658 (delete 'pruned-op module-ops :key #'car)
659 (list (cons operation c))))))
660 (setf (visiting-component operation c) nil)
661 (visit-component operation c (and forced t))
665 (defmethod perform ((operation operation) (c source-file))
667 (formatter "~@<required method PERFORM not implemented~
668 for operation ~A, component ~A~@:>")
669 (class-of operation) (class-of c)))
671 (defmethod perform ((operation operation) (c module))
674 (defmethod explain ((operation operation) (component component))
675 (format *verbose-out* "~&;;; ~A on ~A~%"
676 operation component))
680 (defclass compile-op (operation)
681 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
682 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
683 :initform *compile-file-warnings-behaviour*)
684 (on-failure :initarg :on-failure :accessor operation-on-failure
685 :initform *compile-file-failure-behaviour*)))
687 (defmethod perform :before ((operation compile-op) (c source-file))
688 (map nil #'ensure-directories-exist (output-files operation c)))
690 (defmethod perform :after ((operation operation) (c component))
691 (setf (gethash (type-of operation) (component-operation-times c))
692 (get-universal-time)))
694 ;;; perform is required to check output-files to find out where to put
695 ;;; its answers, in case it has been overridden for site policy
696 (defmethod perform ((operation compile-op) (c cl-source-file))
697 (let ((source-file (component-pathname c))
698 (output-file (car (output-files operation c))))
699 (multiple-value-bind (output warnings-p failure-p)
700 (compile-file source-file
701 :output-file output-file)
702 ;(declare (ignore output))
704 (case (operation-on-warnings operation)
705 (:warn (warn "COMPILE-FILE warned while performing ~A on ~A"
707 (:error (error 'compile-warned :component c :operation operation))
710 (case (operation-on-failure operation)
711 (:warn (warn "COMPILE-FILE failed while performing ~A on ~A"
713 (:error (error 'compile-failed :component c :operation operation))
716 (error 'compile-error :component c :operation operation)))))
718 (defmethod output-files ((operation compile-op) (c cl-source-file))
719 (list (compile-file-pathname (component-pathname c))))
721 (defmethod perform ((operation compile-op) (c static-file))
724 (defmethod output-files ((operation compile-op) (c static-file))
729 (defclass load-op (operation) ())
731 (defmethod perform ((o load-op) (c cl-source-file))
732 (mapcar #'load (input-files o c)))
734 (defmethod perform ((operation load-op) (c static-file))
736 (defmethod operation-done-p ((operation load-op) (c static-file))
739 (defmethod output-files ((o operation) (c component))
742 (defmethod component-depends-on ((operation load-op) (c component))
743 (cons (list 'compile-op (component-name c))
748 (defclass load-source-op (operation) ())
750 (defmethod perform ((o load-source-op) (c cl-source-file))
751 (let ((source (component-pathname c)))
752 (setf (component-property c 'last-loaded-as-source)
754 (get-universal-time)))))
756 (defmethod perform ((operation load-source-op) (c static-file))
759 (defmethod output-files ((operation load-source-op) (c component))
762 ;;; FIXME: we simply copy load-op's dependencies. this is Just Not Right.
763 (defmethod component-depends-on ((o load-source-op) (c component))
764 (let ((what-would-load-op-do (cdr (assoc 'load-op
765 (slot-value c 'in-order-to)))))
766 (mapcar (lambda (dep)
767 (if (eq (car dep) 'load-op)
768 (cons 'load-source-op (cdr dep))
770 what-would-load-op-do)))
772 (defmethod operation-done-p ((o load-source-op) (c source-file))
773 (if (or (not (component-property c 'last-loaded-as-source))
774 (> (file-write-date (component-pathname c))
775 (component-property c 'last-loaded-as-source)))
778 (defclass test-op (operation) ())
780 (defmethod perform ((operation test-op) (c component))
783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
784 ;;; invoking operations
786 (defun operate (operation-class system &rest args)
787 (let* ((op (apply #'make-instance operation-class
788 :original-initargs args args))
790 (if (getf args :verbose t)
792 (make-broadcast-stream)))
793 (system (if (typep system 'component) system (find-system system)))
794 (steps (traverse op system)))
795 (with-compilation-unit ()
796 (loop for (op . component) in steps do
799 (progn (perform op component)
802 (skip-component () (return))))))))
804 (defun oos (&rest args)
805 "Alias of OPERATE function"
806 (apply #'operate args))
808 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
811 (defun remove-keyword (key arglist)
812 (labels ((aux (key arglist)
813 (cond ((null arglist) nil)
814 ((eq key (car arglist)) (cddr arglist))
815 (t (cons (car arglist) (cons (cadr arglist)
817 key (cddr arglist))))))))
820 (defmacro defsystem (name &body options)
821 (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
822 (let ((component-options (remove-keyword :class options)))
824 ;; system must be registered before we parse the body, otherwise
825 ;; we recur when trying to find an existing system of the same name
826 ;; to reuse options (e.g. pathname) from
827 (let ((s (system-registered-p ',name)))
828 (cond ((and s (eq (type-of (cdr s)) ',class))
829 (setf (car s) (get-universal-time)))
832 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
834 (change-class (cdr s) ',class))
836 (register-system (quote ,name)
837 (make-instance ',class :name ',name)))))
838 (parse-component-form nil (apply
840 :module (coerce-name ',name)
843 (pathname-sans-name+type
844 (resolve-symlinks *load-truename*))
845 *default-pathname-defaults*)
846 ',component-options))))))
849 (defun class-for-type (parent type)
850 (let ((class (find-class
851 (or (find-symbol (symbol-name type) *package*)
852 (find-symbol (symbol-name type) #.*package*)) nil)))
855 (or (module-default-component-class parent)
856 (find-class 'cl-source-file)))
857 (sysdef-error (formatter "~@<don't recognize component type ~A~@:>")
860 (defun maybe-add-tree (tree op1 op2 c)
861 "Add the node C at /OP1/OP2 in TREE, unless it's there already.
862 Returns the new tree (which probably shares structure with the old one)"
863 (let ((first-op-tree (assoc op1 tree)))
866 (aif (assoc op2 (cdr first-op-tree))
867 (if (find c (cdr it))
869 (setf (cdr it) (cons c (cdr it))))
870 (setf (cdr first-op-tree)
871 (acons op2 (list c) (cdr first-op-tree))))
873 (acons op1 (list (list op2 c)) tree))))
875 (defun union-of-dependencies (&rest deps)
876 (let ((new-tree nil))
878 (dolist (op-tree dep)
879 (dolist (op (cdr op-tree))
882 (maybe-add-tree new-tree (car op-tree) (car op) c))))))
886 (defun remove-keys (key-names args)
887 (loop for ( name val ) on args by #'cddr
888 unless (member (symbol-name name) key-names
889 :key #'symbol-name :test 'equal)
890 append (list name val)))
892 (defvar *serial-depends-on*)
894 (defun parse-component-form (parent options)
896 (type name &rest rest &key
897 ;; the following list of keywords is reproduced below in the
898 ;; remove-keys form. important to keep them in sync
899 components pathname default-component-class
900 perform explain output-files operation-done-p
901 depends-on serial in-order-to
903 &allow-other-keys) options
904 (check-component-input type name depends-on components in-order-to)
905 (let* ((other-args (remove-keys
906 '(components pathname default-component-class
907 perform explain output-files operation-done-p
908 depends-on serial in-order-to)
911 (or (find-component parent name)
912 (make-instance (class-for-type parent type)))))
913 (when (boundp '*serial-depends-on*)
915 (concatenate 'list *serial-depends-on* depends-on)))
916 (apply #'reinitialize-instance
918 :name (coerce-name name)
922 (when (typep ret 'module)
923 (setf (module-default-component-class ret)
924 (or default-component-class
925 (and (typep parent 'module)
926 (module-default-component-class parent))))
927 (let ((*serial-depends-on* nil))
928 (setf (module-components ret)
929 (loop for c-form in components
930 for c = (parse-component-form ret c-form)
933 do (push (component-name c) *serial-depends-on*)))))
935 (setf (slot-value ret 'in-order-to)
936 (union-of-dependencies
938 `((compile-op (compile-op ,@depends-on))
939 (load-op (load-op ,@depends-on))))
940 (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
942 (loop for (n v) in `((perform ,perform) (explain ,explain)
943 (output-files ,output-files)
944 (operation-done-p ,operation-done-p))
946 ;; this is inefficient as most of the stored
947 ;; methods will not be for this particular gf n
948 ;; But this is hardly performance-critical
949 (lambda (m) (remove-method (symbol-function n) m))
950 (component-inline-methods ret))
952 do (destructuring-bind (op qual (o c) &body body) v
954 (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
956 (component-inline-methods ret))))
959 (defun check-component-input (type name depends-on components in-order-to)
960 "A partial test of the values of a component."
961 (unless (listp depends-on)
962 (sysdef-error-component ":depends-on must be a list."
963 type name depends-on))
964 (unless (listp components)
965 (sysdef-error-component ":components must be NIL or a list of components."
966 type name components))
967 (unless (and (listp in-order-to) (listp (car in-order-to)))
968 (sysdef-error-component ":in-order-to must be NIL or a list of components."
969 type name in-order-to)))
971 (defun sysdef-error-component (msg type name value)
972 (sysdef-error (concatenate 'string msg
973 "~&The value specified for ~(~A~) ~A is ~W")
976 (defun resolve-symlinks (path)
977 #-allegro (truename path)
978 #+allegro (excl:pathname-resolve-symbolic-links path)
983 ;;; run-shell-command functions for other lisp implementations will be
984 ;;; gratefully accepted, if they do the same thing. If the docstring
985 ;;; is ambiguous, send a bug report
987 (defun run-shell-command (control-string &rest args)
988 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
989 synchronously execute the result using a Bourne-compatible shell, with
990 output to *verbose-out*. Returns the shell's exit code."
991 (let ((command (apply #'format nil control-string args)))
992 (format *verbose-out* "; $ ~A~%" command)
994 (sb-impl::process-exit-code
998 :input nil :output *verbose-out*))
1001 (ext:process-exit-code
1005 :input nil :output *verbose-out*))
1008 (excl:run-shell-command command :input nil :output *verbose-out*)
1011 (system:call-system-showing-output
1013 :shell-type "/bin/sh"
1014 :output-stream *verbose-out*)
1016 #+clisp ;XXX not exactly *verbose-out*, I know
1017 (ext:run-shell-command command :output :terminal :wait t)
1021 (ccl:external-process-status
1022 (ccl:run-program "/bin/sh" (list "-c" command)
1023 :input nil :output *verbose-out*
1026 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
1027 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
1031 (defgeneric hyperdocumentation (package name doc-type))
1032 (defmethod hyperdocumentation ((package symbol) name doc-type)
1033 (hyperdocumentation (find-package package) name doc-type))
1035 (defun hyperdoc (name doc-type)
1036 (hyperdocumentation (symbol-package name) name doc-type))
1039 (pushnew :asdf *features*)
1042 (eval-when (:compile-toplevel :load-toplevel :execute)
1043 (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
1044 (pushnew :sbcl-hooks-require *features*)))
1046 #+(and sbcl sbcl-hooks-require)
1048 (defun module-provide-asdf (name)
1049 (handler-bind ((style-warning #'muffle-warning))
1050 (let* ((*verbose-out* (make-broadcast-stream))
1051 (system (asdf:find-system name nil)))
1053 (asdf:operate 'asdf:load-op name)
1057 '(merge-pathnames "systems/"
1058 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1062 '(merge-pathnames "site-systems/"
1063 (truename (sb-ext:posix-getenv "SBCL_HOME")))
1067 '(merge-pathnames ".sbcl/systems/"
1068 (user-homedir-pathname))
1071 (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))