1 ;;; This is asdf: Another System Definition Facility. $\Revision: 1.62 $
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
44 #:compile-op #:load-op #:load-source-op #:test-system-version
45 #:operation ; operations
46 #:feature ; sort-of operation
47 #:version ; metaphorically sort-of an operation
49 #:output-files #:perform ; operation methods
50 #:operation-done-p #:explain
52 #:component #:source-file
53 #:c-source-file #:cl-source-file #:java-source-file
63 #:module-components ; component accessors
65 #:component-relative-pathname
71 #:component-depends-on
73 ;#:*component-parent-pathname*
74 #:*central-registry* ; variables
76 #:operation-error #:compile-failed #:compile-warned #:compile-error
77 #:system-definition-error
80 #:circular-dependency ; errors
85 (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")
90 (defvar *asdf-revision* (let* ((v "$\Revision: 1.62 $")
91 (colon (position #\: v))
92 (dot (position #\. v)))
94 (list (parse-integer v :start (1+ colon)
96 (parse-integer v :start (1+ dot)
99 (defvar *compile-file-warnings-behaviour* :warn)
100 (defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 (defmacro aif (test then &optional else)
106 `(let ((it ,test)) (if it ,then ,else)))
108 (defun pathname-sans-name+type (pathname)
109 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
110 and NIL NAME and TYPE components"
111 (make-pathname :name nil :type nil :defaults pathname))
113 (define-modify-macro appendf (&rest args)
114 append "Append onto list")
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117 ;; classes, condiitons
119 (define-condition system-definition-error (error) ()
120 ;; [this use of :report should be redundant, but unfortunately it's not.
121 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
122 ;; over print-object; this is always conditions::%print-condition for
123 ;; condition objects, which in turn does inheritance of :report options at
124 ;; run-time. fortunately, inheritance means we only need this kludge here in
125 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
126 #+cmu (:report print-object))
128 (define-condition formatted-system-definition-error (system-definition-error)
129 ((format-control :initarg :format-control :reader format-control)
130 (format-arguments :initarg :format-arguments :reader format-arguments))
131 (:report (lambda (c s)
132 (apply #'format s (format-control c) (format-arguments c)))))
134 (define-condition circular-dependency (system-definition-error)
135 ((components :initarg :components :reader circular-dependency-components)))
137 (define-condition missing-component (system-definition-error)
138 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
139 (version :initform nil :reader missing-version :initarg :version)
140 (parent :initform nil :reader missing-parent :initarg :parent)))
142 (define-condition missing-dependency (missing-component)
143 ((required-by :initarg :required-by :reader missing-required-by)))
145 (define-condition operation-error (error)
146 ((component :reader error-component :initarg :component)
147 (operation :reader error-operation :initarg :operation))
148 (:report (lambda (c s)
149 (format s (formatter "~@<erred while invoking ~A on ~A~@:>")
150 (error-operation c) (error-component c)))))
151 (define-condition compile-error (operation-error) ())
152 (define-condition compile-failed (compile-error) ())
153 (define-condition compile-warned (compile-error) ())
155 (defclass component ()
156 ((name :type string :accessor component-name :initarg :name :documentation
157 "Component name, restricted to portable pathname characters")
158 (version :accessor component-version :initarg :version)
159 (in-order-to :initform nil :initarg :in-order-to)
161 (do-first :initform nil :initarg :do-first)
162 ;; methods defined using the "inline" style inside a defsystem form:
163 ;; need to store them somewhere so we can delete them when the system
165 (inline-methods :accessor component-inline-methods :initform nil)
166 (parent :initarg :parent :initform nil :reader component-parent)
167 ;; no direct accessor for pathname, we do this as a method to allow
168 ;; it to default in funky ways if not supplied
169 (relative-pathname :initarg :pathname)
170 (operation-times :initform (make-hash-table )
171 :accessor component-operation-times)
172 ;; XXX we should provide some atomic interface for updating the
173 ;; component properties
174 (properties :accessor component-properties :initarg :properties
177 ;;;; methods: conditions
179 (defmethod print-object ((c missing-dependency) s)
180 (format s (formatter "~@<~A, required by ~A~@:>")
181 (call-next-method c nil)
182 (missing-required-by c)))
184 (defun sysdef-error (format &rest arguments)
185 (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
187 ;;;; methods: components
189 (defmethod print-object ((c missing-component) s)
190 (format s (formatter "~@<component ~S not found~
191 ~@[ or does not match version ~A~]~
195 (when (missing-parent c)
196 (component-name (missing-parent c)))))
198 (defgeneric component-system (component)
199 (:documentation "Find the top-level system containing COMPONENT"))
201 (defmethod component-system ((component component))
202 (aif (component-parent component)
203 (component-system it)
206 (defmethod print-object ((c component) stream)
207 (print-unreadable-object (c stream :type t :identity t)
209 (prin1 (component-name c) stream))))
211 (defclass module (component)
212 ((components :initform nil :accessor module-components :initarg :components)
213 ;; what to do if we can't satisfy a dependency of one of this module's
214 ;; components. This allows a limited form of conditional processing
215 (if-component-dep-fails :initform :fail
216 :accessor module-if-component-dep-fails
217 :initarg :if-component-dep-fails)
218 (default-component-class :accessor module-default-component-class
219 :initform 'cl-source-file :initarg :default-component-class)))
221 (defgeneric component-pathname (component)
222 (:documentation "Extracts the pathname applicable for a particular component."))
224 (defun component-parent-pathname (component)
225 (aif (component-parent component)
226 (component-pathname it)
227 *default-pathname-defaults*))
229 (defgeneric component-relative-pathname (component)
230 (:documentation "Extracts the relative pathname applicable for a particular component."))
232 (defmethod component-relative-pathname ((component module))
233 (or (slot-value component 'relative-pathname)
235 :directory `(:relative ,(component-name component))
236 :host (pathname-host (component-parent-pathname component)))))
238 (defmethod component-pathname ((component component))
239 (let ((*default-pathname-defaults* (component-parent-pathname component)))
240 (merge-pathnames (component-relative-pathname component))))
242 (defgeneric component-property (component property))
244 (defmethod component-property ((c component) property)
245 (cdr (assoc property (slot-value c 'properties))))
247 (defgeneric (setf component-property) (new-value component property))
249 (defmethod (setf component-property) (new-value (c component) property)
250 (let ((a (assoc property (slot-value c 'properties))))
252 (setf (cdr a) new-value)
253 (setf (slot-value c 'properties)
254 (acons property new-value (slot-value c 'properties))))))
258 (defclass system (module)
259 ((description :accessor system-description :initarg :description)
260 (long-description :accessor long-description :initarg :long-description)
261 (author :accessor system-author :initarg :author)
262 (maintainer :accessor system-maintainer :initarg :maintainer)
263 (licence :accessor system-licence :initarg :licence)))
265 ;;; version-satisfies
267 ;;; with apologies to christophe rhodes ...
268 (defun split (string &optional max (ws '(#\Space #\Tab)))
269 (flet ((is-ws (char) (find char ws)))
271 (let ((list nil) (start 0) (words 0) end)
273 (when (and max (>= words (1- max)))
274 (return (cons (subseq string start) list)))
275 (setf end (position-if #'is-ws string :start start))
276 (push (subseq string start end) list)
278 (unless end (return list))
279 (setf start (1+ end)))))))
281 (defgeneric version-satisfies (component version))
283 (defmethod version-satisfies ((c component) version)
284 (unless (and version (slot-boundp c 'version))
285 (return-from version-satisfies t))
286 (let ((x (mapcar #'parse-integer
287 (split (component-version c) nil '(#\.))))
288 (y (mapcar #'parse-integer
289 (split version nil '(#\.)))))
290 (labels ((bigger (x y)
293 ((> (car x) (car y)) t)
295 (bigger (cdr x) (cdr y))))))
296 (and (= (car x) (car y))
297 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
302 (defvar *defined-systems* (make-hash-table :test 'equal))
303 (defun coerce-name (name)
305 (component (component-name name))
306 (symbol (string-downcase (symbol-name name)))
308 (t (sysdef-error (formatter "~@<invalid component designator ~A~@:>")
311 (defun system-definition-pathname (system)
312 (some (lambda (x) (funcall x system))
313 *system-definition-search-functions*))
315 (defun sysdef-central-registry-search (system)
316 (let ((name (coerce-name system)))
318 (dolist (dir *central-registry*)
319 (let* ((defaults (eval dir))
322 :defaults defaults :version :newest
323 :name name :type "asd" :case :local))))
324 (if (and file (probe-file file))
328 (defvar *central-registry*
329 '(*default-pathname-defaults*
330 #+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
331 #+nil "telent:asdf;systems;"))
333 ;;; for the sake of keeping things reasonably neat, we adopt a
334 ;;; convention that functions in this list are prefixed SYSDEF-
336 (defvar *system-definition-search-functions*
337 '(sysdef-central-registry-search))
339 (defun find-system (name &optional (error-p t))
340 (let* ((name (coerce-name name))
341 (in-memory (gethash name *defined-systems*))
342 (on-disk (system-definition-pathname name)))
345 (< (car in-memory) (file-write-date on-disk))))
346 (let ((*package* (make-package (gensym (package-name #.*package*))
349 (formatter "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%")
350 ;; FIXME: This wants to be (ENOUGH-NAMESTRING
351 ;; ON-DISK), but CMUCL barfs on that.
355 (let ((in-memory (gethash name *defined-systems*)))
357 (progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
359 (if error-p (error 'missing-component :requires name))))))
361 (defun register-system (name system)
362 (format t (formatter "~&~@<; ~@;registering ~A as ~A~@:>~%") system name)
363 (setf (gethash (coerce-name name) *defined-systems*)
364 (cons (get-universal-time) system)))
366 (defun system-registered-p (name)
367 (gethash (coerce-name name) *defined-systems*))
369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
370 ;;; finding components
372 (defgeneric find-component (module name &optional version)
373 (:documentation "Finds the component with name NAME present in the
374 MODULE module; if MODULE is nil, then the component is assumed to be a
377 (defmethod find-component ((module module) name &optional version)
378 (if (slot-boundp module 'components)
379 (let ((m (find name (module-components module)
380 :test #'equal :key #'component-name)))
381 (if (and m (version-satisfies m version)) m))))
384 ;;; a component with no parent is a system
385 (defmethod find-component ((module (eql nil)) name &optional version)
386 (let ((m (find-system name nil)))
387 (if (and m (version-satisfies m version)) m)))
389 ;;; component subclasses
391 (defclass source-file (component) ())
393 (defclass cl-source-file (source-file) ())
394 (defclass c-source-file (source-file) ())
395 (defclass java-source-file (source-file) ())
396 (defclass static-file (source-file) ())
397 (defclass doc-file (static-file) ())
398 (defclass html-file (doc-file) ())
400 (defgeneric source-file-type (component system))
401 (defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
402 (defmethod source-file-type ((c c-source-file) (s module)) "c")
403 (defmethod source-file-type ((c java-source-file) (s module)) "java")
404 (defmethod source-file-type ((c html-file) (s module)) "html")
405 (defmethod source-file-type ((c static-file) (s module)) nil)
407 (defmethod component-relative-pathname ((component source-file))
408 (let ((*default-pathname-defaults* (component-parent-pathname component)))
409 (or (slot-value component 'relative-pathname)
410 (make-pathname :name (component-name component)
412 (source-file-type component
413 (component-system component))))))
416 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
419 ;;; one of these is instantiated whenever (operate ) is called
421 (defclass operation ()
422 ((forced-p :initform nil :initarg :force :accessor operation-forced-p )
423 (original-initargs :initform nil :initarg :original-initargs
424 :accessor operation-original-initargs)
425 (visited-nodes :initform nil :accessor operation-visited-nodes)
426 (visiting-nodes :initform nil :accessor operation-visiting-nodes)
427 (parent :initform nil :initarg :parent :accessor operation-parent)))
429 (defmethod shared-initialize :after ((operation operation) slot-names
432 (declare (ignore slot-names force))
433 ;; empty method to disable initarg validity checking
436 (defgeneric perform (operation component))
437 (defgeneric operation-done-p (operation component))
438 (defgeneric explain (operation component))
439 (defgeneric output-files (operation component))
440 (defgeneric input-files (operation component))
442 (defun node-for (o c)
443 (cons (class-name (class-of o)) c))
445 (defgeneric operation-ancestor (operation)
446 (:documentation "Recursively chase the operation's parent pointer until we get to the head of the tree"))
448 (defmethod operation-ancestor ((operation operation))
449 (aif (operation-parent operation)
450 (operation-ancestor it)
453 (defun make-sub-operation (o type)
454 (let ((args (operation-original-initargs o)))
455 (apply #'make-instance type :parent o :original-initargs args args)))
457 (defgeneric visit-component (operation component data))
459 (defmethod visit-component ((o operation) (c component) data)
460 (unless (component-visited-p o c)
461 (push (cons (node-for o c) data)
462 (operation-visited-nodes (operation-ancestor o)))))
464 (defgeneric component-visited-p (operation component))
466 (defmethod component-visited-p ((o operation) (c component))
467 (assoc (node-for o c)
468 (operation-visited-nodes (operation-ancestor o))
471 (defgeneric (setf visiting-component) (new-value operation component))
473 (defmethod (setf visiting-component) (new-value operation component)
474 ;; MCL complains about unused lexical variables
475 (declare (ignorable new-value operation component)))
477 (defmethod (setf visiting-component) (new-value (o operation) (c component))
478 (let ((node (node-for o c))
479 (a (operation-ancestor o)))
481 (pushnew node (operation-visiting-nodes a) :test 'equal)
482 (setf (operation-visiting-nodes a)
483 (remove node (operation-visiting-nodes a) :test 'equal)))))
485 (defgeneric component-visiting-p (operation component))
487 (defmethod component-visiting-p ((o operation) (c component))
488 (let ((node (cons o c)))
489 (member node (operation-visiting-nodes (operation-ancestor o))
492 (defgeneric component-depends-on (operation component))
494 (defmethod component-depends-on ((o operation) (c component))
495 (cdr (assoc (class-name (class-of o))
496 (slot-value c 'in-order-to))))
498 (defgeneric component-self-dependencies (operation component))
500 (defmethod component-self-dependencies ((o operation) (c component))
501 (let ((all-deps (component-depends-on o c)))
502 (remove-if-not (lambda (x)
503 (member (component-name c) (cdr x) :test #'string=))
506 (defmethod input-files ((operation operation) (c component))
507 (let ((parent (component-parent c))
508 (self-deps (component-self-dependencies operation c)))
510 (mapcan (lambda (dep)
511 (destructuring-bind (op name) dep
512 (output-files (make-instance op)
513 (find-component parent name))))
515 ;; no previous operations needed? I guess we work with the
516 ;; original source file, then
517 (list (component-pathname c)))))
519 (defmethod input-files ((operation operation) (c module)) nil)
521 (defmethod operation-done-p ((o operation) (c component))
522 (let ((out-files (output-files o c))
523 (in-files (input-files o c)))
524 (cond ((and (not in-files) (not out-files))
525 ;; arbitrary decision: an operation that uses nothing to
526 ;; produce nothing probably isn't doing much
531 (component-operation-times c))))
535 (mapcar #'file-write-date in-files)) 0)))))
539 (every #'probe-file out-files)
540 (> (apply #'min (mapcar #'file-write-date out-files))
541 (apply #'max (mapcar #'file-write-date in-files)) ))))))
543 ;;; So you look at this code and think "why isn't it a bunch of
544 ;;; methods". And the answer is, because standard method combination
545 ;;; runs :before methods most->least-specific, which is back to front
546 ;;; for our purposes. And CLISP doesn't have non-standard method
547 ;;; combinations, so let's keep it simple and aspire to portability
549 (defgeneric traverse (operation component))
550 (defmethod traverse ((operation operation) (c component))
552 (labels ((do-one-dep (required-op required-c required-v)
553 (let ((op (if (subtypep (type-of operation) required-op)
555 (make-sub-operation operation required-op)))
556 (dep-c (or (find-component
558 ;; XXX tacky. really we should build the
559 ;; in-order-to slot with canonicalized
560 ;; names instead of coercing this late
561 (coerce-name required-c) required-v)
562 (error 'missing-dependency :required-by c
564 :requires required-c))))
565 (traverse op dep-c)))
567 (cond ((eq op 'feature)
568 (or (member (car dep) *features*)
569 (error 'missing-dependency :required-by c
570 :requires (car dep) :version nil)))
574 (assert (string-equal
575 (symbol-name (first d))
578 (do-one-dep op (second d) (third d))))
580 (appendf forced (do-one-dep op d nil)))))))))
581 (aif (component-visited-p operation c)
582 (return-from traverse
583 (if (cdr it) (list (cons 'pruned-op c)) nil)))
585 (if (component-visiting-p operation c)
586 (error 'circular-dependency :components (list c)))
587 (setf (visiting-component operation c) t)
588 (loop for (required-op . deps) in (component-depends-on operation c)
589 do (do-dep required-op deps))
592 (when (typep c 'module)
593 (let ((at-least-one nil)
596 (loop for kid in (module-components c)
598 (appendf forced (traverse operation kid ))
599 (missing-dependency (condition)
600 (if (eq (module-if-component-dep-fails c) :fail)
602 (setf error condition))
605 (setf at-least-one t))))
606 (when (and (eq (module-if-component-dep-fails c) :try-next)
610 ;; now the thing itself
611 (when (or forced module-ops
612 (operation-forced-p (operation-ancestor operation))
613 (not (operation-done-p operation c)))
614 (let ((do-first (cdr (assoc (class-name (class-of operation))
615 (slot-value c 'do-first)))))
616 (loop for (required-op . deps) in do-first
617 do (do-dep required-op deps)))
618 (setf forced (append (delete 'pruned-op forced :key #'car)
619 (delete 'pruned-op module-ops :key #'car)
620 (list (cons operation c))))))
621 (setf (visiting-component operation c) nil)
622 (visit-component operation c (and forced t))
626 (defmethod perform ((operation operation) (c source-file))
628 (formatter "~@<required method PERFORM not implemented~
629 for operation ~A, component ~A~@:>")
630 (class-of operation) (class-of c)))
632 (defmethod perform ((operation operation) (c module))
635 (defmethod explain ((operation operation) (component component))
636 (format *trace-output* "~&;;; ~A on ~A~%"
637 operation component))
641 (defclass compile-op (operation)
642 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
643 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
644 :initform *compile-file-warnings-behaviour*)
645 (on-failure :initarg :on-failure :accessor operation-on-failure
646 :initform *compile-file-failure-behaviour*)))
648 (defmethod perform :before ((operation compile-op) (c source-file))
649 (map nil #'ensure-directories-exist (output-files operation c)))
651 (defmethod perform :after ((operation operation) (c component))
652 (setf (gethash (type-of operation) (component-operation-times c))
653 (get-universal-time)))
655 ;;; perform is required to check output-files to find out where to put
656 ;;; its answers, in case it has been overridden for site policy
657 (defmethod perform ((operation compile-op) (c cl-source-file))
658 (let ((source-file (component-pathname c))
659 (output-file (car (output-files operation c))))
660 (multiple-value-bind (output warnings-p failure-p)
661 (compile-file source-file
662 :output-file output-file)
663 ;(declare (ignore output))
665 (case (operation-on-warnings operation)
666 (:warn (warn "COMPILE-FILE warned while performing ~A on ~A"
668 (:error (error 'compile-warned :component c :operation operation))
671 (case (operation-on-failure operation)
672 (:warn (warn "COMPILE-FILE failed while performing ~A on ~A"
674 (:error (error 'compile-failed :component c :operation operation))
677 (error 'compile-error :component c :operation operation)))))
679 (defmethod output-files ((operation compile-op) (c cl-source-file))
680 (list (compile-file-pathname (component-pathname c))))
682 (defmethod perform ((operation compile-op) (c static-file))
685 (defmethod output-files ((operation compile-op) (c static-file))
690 (defclass load-op (operation) ())
692 (defmethod perform ((o load-op) (c cl-source-file))
693 (mapcar #'load (input-files o c)))
695 (defmethod perform ((operation load-op) (c static-file))
697 (defmethod operation-done-p ((operation load-op) (c static-file))
700 (defmethod output-files ((o operation) (c component))
703 (defmethod component-depends-on ((operation load-op) (c component))
704 (cons (list 'compile-op (component-name c))
709 (defclass load-source-op (operation) ())
711 (defmethod perform ((o load-source-op) (c cl-source-file))
712 (let ((source (component-pathname c)))
713 (setf (component-property c 'last-loaded-as-source)
715 (get-universal-time)))))
717 (defmethod perform ((operation load-source-op) (c static-file))
720 (defmethod output-files ((operation load-source-op) (c component))
723 ;;; FIXME: we simply copy load-op's dependencies. this is Just Not Right.
724 (defmethod component-depends-on ((o load-source-op) (c component))
725 (let ((what-would-load-op-do (cdr (assoc 'load-op
726 (slot-value c 'in-order-to)))))
727 (mapcar (lambda (dep)
728 (if (eq (car dep) 'load-op)
729 (cons 'load-source-op (cdr dep))
731 what-would-load-op-do)))
733 (defmethod operation-done-p ((o load-source-op) (c source-file))
734 (if (or (not (component-property c 'last-loaded-as-source))
735 (> (file-write-date (component-pathname c))
736 (component-property c 'last-loaded-as-source)))
740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
741 ;;; invoking operations
743 (defun operate (operation-class system &rest args)
744 (let* ((op (apply #'make-instance operation-class
745 :original-initargs args args))
746 (system (if (typep system 'component) system (find-system system)))
747 (steps (traverse op system)))
748 (with-compilation-unit ()
749 (loop for (op . component) in steps do
752 (progn (perform op component)
755 (skip-component () (return))))))))
757 (defun oos (&rest args)
758 "Alias of OPERATE function"
759 (apply #'operate args))
761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
764 (defun remove-keyword (key arglist)
765 (labels ((aux (key arglist)
766 (cond ((null arglist) nil)
767 ((eq key (car arglist)) (cddr arglist))
768 (t (cons (car arglist) (cons (cadr arglist)
770 key (cddr arglist))))))))
773 (defmacro defsystem (name &body options)
774 (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
775 (let ((component-options (remove-keyword :class options)))
777 ;; system must be registered before we parse the body, otherwise
778 ;; we recur when trying to find an existing system of the same name
779 ;; to reuse options (e.g. pathname) from
780 (let ((s (system-registered-p ',name)))
781 (cond ((and s (eq (type-of (cdr s)) ',class))
782 (setf (car s) (get-universal-time)))
785 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
787 (change-class (cdr s) ',class))
789 (register-system (quote ,name)
790 (make-instance ',class :name ',name)))))
791 (parse-component-form nil (apply
793 :module (coerce-name ',name)
796 (pathname-sans-name+type
797 (resolve-symlinks *load-truename*))
798 *default-pathname-defaults*)
799 ',component-options))))))
802 (defun class-for-type (parent type)
803 (let ((class (find-class
804 (or (find-symbol (symbol-name type) *package*)
805 (find-symbol (symbol-name type) #.*package*)) nil)))
808 (or (module-default-component-class parent)
809 (find-class 'cl-source-file)))
810 (sysdef-error (formatter "~@<don't recognize component type ~A~@:>")
813 (defun maybe-add-tree (tree op1 op2 c)
814 "Add the node C at /OP1/OP2 in TREE, unless it's there already.
815 Returns the new tree (which probably shares structure with the old one)"
816 (let ((first-op-tree (assoc op1 tree)))
819 (aif (assoc op2 (cdr first-op-tree))
820 (if (find c (cdr it))
822 (setf (cdr it) (cons c (cdr it))))
823 (setf (cdr first-op-tree)
824 (acons op2 (list c) (cdr first-op-tree))))
826 (acons op1 (list (list op2 c)) tree))))
828 (defun union-of-dependencies (&rest deps)
829 (let ((new-tree nil))
831 (dolist (op-tree dep)
832 (dolist (op (cdr op-tree))
835 (maybe-add-tree new-tree (car op-tree) (car op) c))))))
839 (defun remove-keys (key-names args)
840 (loop for ( name val ) on args by #'cddr
841 unless (member (symbol-name name) key-names
842 :key #'symbol-name :test 'equal)
843 append (list name val)))
845 (defvar *serial-depends-on*)
847 (defun parse-component-form (parent options)
849 (type name &rest rest &key
850 ;; the following list of keywords is reproduced below in the
851 ;; remove-keys form. important to keep them in sync
852 components pathname default-component-class
853 perform explain output-files operation-done-p
854 depends-on serial in-order-to
856 &allow-other-keys) options
857 (let* ((other-args (remove-keys
858 '(components pathname default-component-class
859 perform explain output-files operation-done-p
860 depends-on serial in-order-to)
863 (or (find-component parent name)
864 (make-instance (class-for-type parent type)))))
865 (when (boundp '*serial-depends-on*)
867 (concatenate 'list *serial-depends-on* depends-on)))
868 (apply #'reinitialize-instance
870 :name (coerce-name name)
874 (when (typep ret 'module)
875 (setf (module-default-component-class ret)
876 (or default-component-class
877 (and (typep parent 'module)
878 (module-default-component-class parent))))
879 (let ((*serial-depends-on* nil))
880 (setf (module-components ret)
881 (loop for c-form in components
882 for c = (parse-component-form ret c-form)
885 do (push (component-name c) *serial-depends-on*)))))
887 (setf (slot-value ret 'in-order-to)
888 (union-of-dependencies
890 `((compile-op (compile-op ,@depends-on))
891 (load-op (load-op ,@depends-on))))
892 (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
894 (loop for (n v) in `((perform ,perform) (explain ,explain)
895 (output-files ,output-files)
896 (operation-done-p ,operation-done-p))
898 ;; this is inefficient as most of the stored
899 ;; methods will not be for this particular gf n
900 ;; But this is hardly performance-critical
901 (lambda (m) (remove-method (symbol-function n) m))
902 (component-inline-methods ret))
904 do (destructuring-bind (op qual (o c) &body body) v
906 (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
908 (component-inline-methods ret))))
912 (defun resolve-symlinks (path)
913 #-allegro (truename path)
914 #+allegro (excl:pathname-resolve-symbolic-links path)
919 ;;; run-shell-command functions for other lisp implementations will be
920 ;;; gratefully accepted, if they do the same thing. If the docstring
921 ;;; is ambiguous, send a bug report
923 (defun run-shell-command (control-string &rest args)
924 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
925 synchronously execute the result using a Bourne-compatible shell, with
926 output to *trace-output*. Returns the shell's exit code."
927 (let ((command (apply #'format nil control-string args)))
928 (format *trace-output* "; $ ~A~%" command)
930 (sb-impl::process-exit-code
934 :input nil :output *trace-output*))
937 (ext:process-exit-code
941 :input nil :output *trace-output*))
944 (excl:run-shell-command command :input nil :output *trace-output*)
947 (system:call-system-showing-output
949 :shell-type "/bin/sh"
950 :output-stream *trace-output*)
952 #+clisp ;XXX not exactly *trace-output*, I know
953 (ext:run-shell-command command :output :terminal :wait t)
957 (ccl:external-process-status
958 (ccl:run-program "/bin/sh" (list "-c" command)
959 :input nil :output *trace-output*
962 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
963 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
966 (pushnew :asdf *features*)
969 (eval-when (:compile-toplevel :load-toplevel :execute)
970 (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
971 (pushnew :sbcl-hooks-require *features*)))
973 #+(and sbcl sbcl-hooks-require)
975 (defun module-provide-asdf (name)
976 (let ((system (asdf:find-system name nil)))
978 (asdf:operate 'asdf:load-op name)
982 (merge-pathnames "systems/"
983 (truename (sb-ext:posix-getenv "SBCL_HOME")))
987 (merge-pathnames "site-systems/"
988 (truename (sb-ext:posix-getenv "SBCL_HOME")))
992 (merge-pathnames ".sbcl/systems/"
993 (user-homedir-pathname))
996 (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))