asdf.lisp 83.6 KB
Newer Older
<
1
;;; This is asdf: Another System Definition Facility.
2
;;; hash - $Format:%H$
3
;;;
Gary King's avatar
Gary King committed
4 5 6 7
;;; Local Variables:
;;; mode: lisp
;;; End:
;;;
8
;;; Feedback, bug reports, and patches are all welcome: please mail to
9 10 11
;;; <asdf-devel@common-lisp.net>.  But note first that the canonical
;;; source for asdf is presently on common-lisp.net at
;;; <URL:http://common-lisp.net/project/asdf/>
12 13 14 15 16
;;;
;;; If you obtained this copy from anywhere else, and you experience
;;; trouble using it, or find bugs, you may want to check at the
;;; location above for a more recent version (and for documentation
;;; and test files, if your copy came without them) before reporting
17
;;; bugs.  There are usually two "supported" revisions - the git HEAD
18 19 20
;;; is the latest development version, whereas the revision tagged
;;; RELEASE may be slightly older but is considered `stable'

21
;;; -- LICENSE START
22
;;; (This is the MIT / X Consortium license as taken from
23 24 25
;;;  http://www.opensource.org/licenses/mit-license.html on or about
;;;  Monday; July 13, 2009)
;;;
26
;;; Copyright (c) 2001-2009 Daniel Barlow and contributors
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining
;;; a copy of this software and associated documentation files (the
;;; "Software"), to deal in the Software without restriction, including
;;; without limitation the rights to use, copy, modify, merge, publish,
;;; distribute, sublicense, and/or sell copies of the Software, and to
;;; permit persons to whom the Software is furnished to do so, subject to
;;; the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
;;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
;;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
;;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 47
;;;
;;; -- LICENSE END
48

Daniel Barlow's avatar
Daniel Barlow committed
49 50 51
;;; the problem with writing a defsystem replacement is bootstrapping:
;;; we can't use defsystem to compile it.  Hence, all in one file

52 53
#+xcvb (module ())

Daniel Barlow's avatar
Daniel Barlow committed
54
(defpackage #:asdf
55
  (:documentation "Another System Definition Facility")
Daniel Barlow's avatar
Daniel Barlow committed
56
  (:export #:defsystem #:oos #:operate #:find-system #:run-shell-command
57
           #:system-definition-pathname #:find-component ; miscellaneous
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
58
           #:compile-system #:load-system #:test-system
Nikodemus Siivola's avatar
Nikodemus Siivola committed
59
           #:compile-op #:load-op #:load-source-op
60
           #:test-op
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
61 62 63
           #:operation                 ; operations
           #:feature                 ; sort-of operation
           #:version                 ; metaphorically sort-of an operation
64

65
           #:input-files #:output-files #:perform ; operation methods
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
           #:operation-done-p #:explain

           #:component #:source-file
           #:c-source-file #:cl-source-file #:java-source-file
           #:static-file
           #:doc-file
           #:html-file
           #:text-file
           #:source-file-type
           #:module                     ; components
           #:system
           #:unix-dso

           #:module-components          ; component accessors
           #:component-pathname
           #:component-relative-pathname
           #:component-name
           #:component-version
           #:component-parent
           #:component-property
           #:component-system

           #:component-depends-on

           #:system-description
           #:system-long-description
           #:system-author
           #:system-maintainer
           #:system-license
           #:system-licence
           #:system-source-file
           #:system-relative-pathname
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
98
           #:map-systems
99 100 101 102

           #:operation-on-warnings
           #:operation-on-failure

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
103
                                        ;#:*component-parent-pathname*
104 105 106 107 108
           #:*system-definition-search-functions*
           #:*central-registry*         ; variables
           #:*compile-file-warnings-behaviour*
           #:*compile-file-failure-behaviour*
           #:*asdf-revision*
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
109
           #:*resolve-symlinks*
110 111 112 113 114

           #:operation-error #:compile-failed #:compile-warned #:compile-error
           #:error-component #:error-operation
           #:system-definition-error
           #:missing-component
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
115
           #:missing-component-of-version
116
           #:missing-dependency
117
           #:missing-dependency-of-version
118 119 120
           #:circular-dependency        ; errors
           #:duplicate-names

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
121
           #:try-recompiling
122 123
           #:retry
           #:accept                     ; restarts
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
124 125
           #:coerce-entry-to-directory
           #:remove-entry-from-registry
126 127 128

           #:standard-asdf-method-combination
           #:around                     ; protocol assistants
129

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
130 131 132 133 134 135 136 137
           #:*source-to-target-mappings*
           #:*default-toplevel-directory*
           #:*centralize-lisp-binaries*
           #:*include-per-user-information*
           #:*map-all-source-files*
           #:output-files-for-system-and-operation
           #:*enable-asdf-binary-locations*
           #:implementation-specific-directory-name)
138
  (:intern #:coerce-name
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
139 140 141 142
           #:system-registered-p
           #:asdf-message
           #:resolve-symlinks
           #:pathname-sans-name+type)
Daniel Barlow's avatar
Daniel Barlow committed
143
  (:use :cl))
144

145 146 147
(defpackage #:asdf-extensions
  (:use #:common-lisp #:asdf)
  (:import-from #:asdf
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
148 149 150 151 152
                #:coerce-name
                #:system-registered-p
                #:asdf-message
                #:resolve-symlinks
                #:pathname-sans-name+type))
153

154
#+nil
155 156 157
(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")
158

Daniel Barlow's avatar
Daniel Barlow committed
159 160
(in-package #:asdf)

161 162 163
;;;; -------------------------------------------------------------------------
;;;; User-visible parameters
;;;;
164
(defvar *asdf-revision*
Gary King's avatar
Gary King committed
165
  ;; the 1+ hair is to ensure that we don't do an inadvertent find and replace
166
  (subseq "REVISION:1.373" (1+ (length "REVISION"))))
167

168 169 170 171 172
(defvar *resolve-symlinks* t
  "Determine whether or not ASDF resolves symlinks when defining systems.

Defaults to `t`.")

173
(defvar *compile-file-warnings-behaviour* :warn)
174

175
(defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
Daniel Barlow's avatar
 
Daniel Barlow committed
176

177
(defvar *verbose-out* nil)
178

179 180 181
(defparameter +asdf-methods+
  '(perform explain output-files operation-done-p))

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
;;;; -------------------------------------------------------------------------
;;;; Cleanups before hot-upgrade.
;;;; Things to do in case we're upgrading from a previous version of ASDF.
;;;; See https://bugs.launchpad.net/asdf/+bug/485687
;;;; * fmakunbound functions that once (in previous version of ASDF)
;;;;   were simple DEFUNs but now are generic functions.
;;;; * define methods on UPDATE-INSTANCE-FOR-REDEFINED-CLASS
;;;;   for each of the classes we define that has changed incompatibly.
(eval-when (:compile-toplevel :load-toplevel :execute)
  (fmakunbound 'system-source-file)
  #+ecl
  (when (find-class 'compile-op nil)
    (defmethod update-instance-for-redefined-class :after
        ((c compile-op) added deleted plist &key)
      (format *trace-output* "~&UI4RC:a ~S~%" (list c added deleted plist))
      (let ((system-p (getf plist 'system-p)))
        (when system-p (setf (getf (slot-value c 'flags) :system-p) system-p))))))

200 201 202
;;;; -------------------------------------------------------------------------
;;;; CLOS magic for asdf:around methods

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
(define-method-combination standard-asdf-method-combination ()
  ((around-asdf (around))
   (around (:around))
   (before (:before))
   (primary () :required t)
   (after (:after)))
  (flet ((call-methods (methods)
           (mapcar #'(lambda (method)
                       `(call-method ,method))
                   methods)))
    (let* ((form (if (or before after (rest primary))
                     `(multiple-value-prog1
                          (progn ,@(call-methods before)
                                 (call-method ,(first primary)
                                              ,(rest primary)))
                        ,@(call-methods (reverse after)))
                     `(call-method ,(first primary))))
           (standard-form (if around
                              `(call-method ,(first around)
                                            (,@(rest around)
                                               (make-method ,form)))
                              form)))
      (if around-asdf
          `(call-method ,(first around-asdf)
                        (,@(rest around-asdf) (make-method ,standard-form)))
          standard-form))))

230
(setf (documentation 'standard-asdf-method-combination
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
231
                     'method-combination)
232 233 234 235 236 237
      "This method combination is based on the standard method combination,
but defines a new method-qualifier, `asdf:around`.  `asdf:around`
methods will be run *around* any `:around` methods, so that the core
protocol may employ around methods and those around methods will not
be overridden by around methods added by a system developer.")

238 239 240
;;;; -------------------------------------------------------------------------
;;;; ASDF Interface, in terms of generic functions.

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
(defgeneric perform (operation component)
  (:method-combination standard-asdf-method-combination))
(defgeneric operation-done-p (operation component)
  (:method-combination standard-asdf-method-combination))
(defgeneric explain (operation component)
  (:method-combination standard-asdf-method-combination))
(defgeneric output-files (operation component)
  (:method-combination standard-asdf-method-combination))
(defgeneric input-files (operation component)
  (:method-combination standard-asdf-method-combination))

(defgeneric system-source-file (system)
  (:documentation "Return the source file in which system is defined."))

(defgeneric component-system (component)
  (:documentation "Find the top-level system containing COMPONENT"))

(defgeneric component-pathname (component)
  (:documentation "Extracts the pathname applicable for a particular component."))

(defgeneric component-relative-pathname (component)
  (:documentation "Extracts the relative pathname applicable for a particular component."))

(defgeneric component-property (component property))

(defgeneric (setf component-property) (new-value component property))

(defgeneric version-satisfies (component version))

(defgeneric find-component (module name &optional version)
  (:documentation "Finds the component with name NAME present in the
MODULE module; if MODULE is nil, then the component is assumed to be a
system."))

(defgeneric source-file-type (component system))

(defgeneric operation-ancestor (operation)
  (:documentation
   "Recursively chase the operation's parent pointer until we get to
the head of the tree"))

(defgeneric component-visited-p (operation component))

(defgeneric visit-component (operation component data))

(defgeneric (setf visiting-component) (new-value operation component))

(defgeneric component-visiting-p (operation component))

(defgeneric component-depends-on (operation component)
  (:documentation
   "Returns a list of dependencies needed by the component to perform
    the operation.  A dependency has one of the following forms:

      (<operation> <component>*), where <operation> is a class
        designator and each <component> is a component
        designator, which means that the component depends on
        <operation> having been performed on each <component>; or

      (FEATURE <feature>), which means that the component depends
        on <feature>'s presence in *FEATURES*.

    Methods specialized on subclasses of existing component types
    should usually append the results of CALL-NEXT-METHOD to the
    list."))

(defgeneric component-self-dependencies (operation component))

Gary King's avatar
Gary King committed
309
(defgeneric traverse (operation component)
310
  (:documentation
Gary King's avatar
Gary King committed
311 312 313
"Generate and return a plan for performing `operation` on `component`.

The plan returned is a list of dotted-pairs. Each pair is the `cons`
314
of ASDF operation object and a `component` object. The pairs will be
Gary King's avatar
Gary King committed
315
processed in order by `operate`."))
316

317
(defgeneric output-files-using-mappings (source possible-paths path-mappings)
318
  (:documentation
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
"Use the variable \\*source-to-target-mappings\\* to find
an output path for the source. The algorithm transforms each
entry in possible-paths as follows: If there is a mapping
whose source starts with the path of possible-path, then
replace possible-path with a pathname that starts with the
target of the mapping and continues with the rest of
possible-path. If no such mapping is found, then use the
default mapping.

If \\*centralize-lisp-binaries\\* is false, then the default
mapping is to place the output in a subdirectory of the
source. The subdirectory is named using the Lisp
implementation \(see
implementation-specific-directory-name\). If
\\*centralize-lisp-binaries\\* is true, then the default
mapping is to place the output in subdirectories of
\\*default-toplevel-directory\\* where the subdirectory
structure will mirror that of the source."))

338

339 340
;;;; -------------------------------------------------------------------------
;;;; General Purpose Utilities
341

Daniel Barlow's avatar
Daniel Barlow committed
342 343 344 345 346 347 348
(defmacro aif (test then &optional else)
  `(let ((it ,test)) (if it ,then ,else)))

(defun pathname-sans-name+type (pathname)
  "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
and NIL NAME and TYPE components"
  (make-pathname :name nil :type nil :defaults pathname))
349

350 351
(define-modify-macro appendf (&rest args)
  append "Append onto list")
Daniel Barlow's avatar
 
Daniel Barlow committed
352

353 354 355 356
(defun asdf-message (format-string &rest format-args)
  (declare (dynamic-extent format-args))
  (apply #'format *verbose-out* format-string format-args))

357 358 359 360 361 362 363 364 365 366 367 368 369 370
;;; with apologies to christophe rhodes ...
(defun split (string &optional max (ws '(#\Space #\Tab)))
  (flet ((is-ws (char) (find char ws)))
    (nreverse
     (let ((list nil) (start 0) (words 0) end)
       (loop
         (when (and max (>= words (1- max)))
           (return (cons (subseq string start) list)))
         (setf end (position-if #'is-ws string :start start))
         (push (subseq string start end) list)
         (incf words)
         (unless end (return list))
         (setf start (1+ end)))))))

371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
(defun split-path-string (s &optional force-directory)
  (check-type s string)
  (let* ((components (split s nil "/"))
         (last-comp (car (last components))))
    (multiple-value-bind (relative components)
        (if (equal (first components) "")
          (values :absolute (cdr components))
          (values :relative components))
      (cond
        ((equal last-comp "")
         (values relative (butlast components) nil))
        (force-directory
         (values relative components nil))
        (t
         (values relative (butlast components) last-comp))))))
386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
(defun remove-keys (key-names args)
  (loop for (name val) on args by #'cddr
        unless (member (symbol-name name) key-names
                       :key #'symbol-name :test 'equal)
        append (list name val)))

(defun remove-keyword (key arglist)
  (labels ((aux (key arglist)
             (cond ((null arglist) nil)
                   ((eq key (car arglist)) (cddr arglist))
                   (t (cons (car arglist) (cons (cadr arglist)
                                                (remove-keyword
                                                 key (cddr arglist))))))))
    (aux key arglist)))

(defun resolve-symlinks (path)
  #-allegro (truename path)
  #+allegro (excl:pathname-resolve-symbolic-links path))

406 407
;;;; -------------------------------------------------------------------------
;;;; Classes, Conditions
Daniel Barlow's avatar
Daniel Barlow committed
408

409 410 411 412 413 414 415 416 417
(define-condition system-definition-error (error) ()
  ;; [this use of :report should be redundant, but unfortunately it's not.
  ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
  ;; over print-object; this is always conditions::%print-condition for
  ;; condition objects, which in turn does inheritance of :report options at
  ;; run-time.  fortunately, inheritance means we only need this kludge here in
  ;; order to fix all conditions that build on it.  -- rgr, 28-Jul-02.]
  #+cmu (:report print-object))

Daniel Barlow's avatar
Daniel Barlow committed
418
(define-condition formatted-system-definition-error (system-definition-error)
419 420 421
  ((format-control :initarg :format-control :reader format-control)
   (format-arguments :initarg :format-arguments :reader format-arguments))
  (:report (lambda (c s)
422
             (apply #'format s (format-control c) (format-arguments c)))))
423

Daniel Barlow's avatar
Daniel Barlow committed
424
(define-condition circular-dependency (system-definition-error)
425
  ((components :initarg :components :reader circular-dependency-components)))
426

427 428 429
(define-condition duplicate-names (system-definition-error)
  ((name :initarg :name :reader duplicate-names-name)))

430 431 432 433
(define-condition missing-component (system-definition-error)
  ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
   (parent :initform nil :reader missing-parent :initarg :parent)))

434 435 436
(define-condition missing-component-of-version (missing-component)
  ((version :initform nil :reader missing-version :initarg :version)))

437 438 439
(define-condition missing-dependency (missing-component)
  ((required-by :initarg :required-by :reader missing-required-by)))

440
(define-condition missing-dependency-of-version (missing-dependency
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
441
                                                 missing-component-of-version)
442 443
  ())

Daniel Barlow's avatar
Daniel Barlow committed
444 445 446 447
(define-condition operation-error (error)
  ((component :reader error-component :initarg :component)
   (operation :reader error-operation :initarg :operation))
  (:report (lambda (c s)
448 449
             (format s "~@<erred while invoking ~A on ~A~@:>"
                     (error-operation c) (error-component c)))))
450 451 452
(define-condition compile-error (operation-error) ())
(define-condition compile-failed (compile-error) ())
(define-condition compile-warned (compile-error) ())
Daniel Barlow's avatar
Daniel Barlow committed
453 454

(defclass component ()
455
  ((name :accessor component-name :initarg :name :documentation
456
         "Component name: designator for a string composed of portable pathname characters")
Daniel Barlow's avatar
Daniel Barlow committed
457
   (version :accessor component-version :initarg :version)
458 459
   (in-order-to :initform nil :initarg :in-order-to
                :accessor component-in-order-to)
460
   ;; XXX crap name
461 462
   (do-first :initform nil :initarg :do-first
             :accessor component-do-first)
Daniel Barlow's avatar
Daniel Barlow committed
463 464 465 466
   ;; methods defined using the "inline" style inside a defsystem form:
   ;; need to store them somewhere so we can delete them when the system
   ;; is re-evaluated
   (inline-methods :accessor component-inline-methods :initform nil)
Daniel Barlow's avatar
Daniel Barlow committed
467
   (parent :initarg :parent :initform nil :reader component-parent)
Daniel Barlow's avatar
Daniel Barlow committed
468 469
   ;; no direct accessor for pathname, we do this as a method to allow
   ;; it to default in funky ways if not supplied
Daniel Barlow's avatar
 
Daniel Barlow committed
470
   (relative-pathname :initarg :pathname)
471
   (operation-times :initform (make-hash-table)
472
                    :accessor component-operation-times)
Daniel Barlow's avatar
 
Daniel Barlow committed
473 474
   ;; XXX we should provide some atomic interface for updating the
   ;; component properties
475
   (properties :accessor component-properties :initarg :properties
476
               :initform nil)))
Daniel Barlow's avatar
 
Daniel Barlow committed
477

Daniel Barlow's avatar
 
Daniel Barlow committed
478 479 480
;;;; methods: conditions

(defmethod print-object ((c missing-dependency) s)
481
  (format s "~@<~A, required by ~A~@:>"
482
          (call-next-method c nil) (missing-required-by c)))
Daniel Barlow's avatar
 
Daniel Barlow committed
483 484

(defun sysdef-error (format &rest arguments)
485
  (error 'formatted-system-definition-error :format-control
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
486
         format :format-arguments arguments))
Daniel Barlow's avatar
Daniel Barlow committed
487

Daniel Barlow's avatar
 
Daniel Barlow committed
488 489 490
;;;; methods: components

(defmethod print-object ((c missing-component) s)
491
   (format s "~@<component ~S not found~
492
             ~@[ in ~A~]~@:>"
493 494 495
          (missing-requires c)
          (when (missing-parent c)
            (component-name (missing-parent c)))))
Daniel Barlow's avatar
 
Daniel Barlow committed
496

497 498 499 500 501
(defmethod print-object ((c missing-component-of-version) s)
  (format s "~@<component ~S does not match version ~A~
              ~@[ in ~A~]~@:>"
           (missing-requires c)
           (missing-version c)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
502 503
           (when (missing-parent c)
             (component-name (missing-parent c)))))
504

Daniel Barlow's avatar
Daniel Barlow committed
505 506 507 508 509
(defmethod component-system ((component component))
  (aif (component-parent component)
       (component-system it)
       component))

510
(defmethod print-object ((c component) stream)
Daniel Barlow's avatar
Daniel Barlow committed
511
  (print-unreadable-object (c stream :type t :identity t)
Daniel Barlow's avatar
Daniel Barlow committed
512 513
    (ignore-errors
      (prin1 (component-name c) stream))))
Daniel Barlow's avatar
Daniel Barlow committed
514 515

(defclass module (component)
Daniel Barlow's avatar
 
Daniel Barlow committed
516
  ((components :initform nil :accessor module-components :initarg :components)
Daniel Barlow's avatar
Daniel Barlow committed
517 518 519
   ;; what to do if we can't satisfy a dependency of one of this module's
   ;; components.  This allows a limited form of conditional processing
   (if-component-dep-fails :initform :fail
520 521
                           :accessor module-if-component-dep-fails
                           :initarg :if-component-dep-fails)
Daniel Barlow's avatar
Daniel Barlow committed
522 523 524
   (default-component-class :accessor module-default-component-class
     :initform 'cl-source-file :initarg :default-component-class)))

Daniel Barlow's avatar
 
Daniel Barlow committed
525 526 527 528 529
(defun component-parent-pathname (component)
  (aif (component-parent component)
       (component-pathname it)
       *default-pathname-defaults*))

Daniel Barlow's avatar
Daniel Barlow committed
530
(defmethod component-relative-pathname ((component module))
Daniel Barlow's avatar
Daniel Barlow committed
531
  (or (slot-value component 'relative-pathname)
532
      (multiple-value-bind (relative path)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
533
          (split-path-string (component-name component) t)
534 535 536
        (make-pathname
         :directory `(,relative ,@path)
         :host (pathname-host (component-parent-pathname component))))))
Daniel Barlow's avatar
Daniel Barlow committed
537

Daniel Barlow's avatar
 
Daniel Barlow committed
538 539 540 541
(defmethod component-pathname ((component component))
  (let ((*default-pathname-defaults* (component-parent-pathname component)))
    (merge-pathnames (component-relative-pathname component))))

542
(defmethod component-property ((c component) property)
Daniel Barlow's avatar
Daniel Barlow committed
543
  (cdr (assoc property (slot-value c 'properties) :test #'equal)))
544 545

(defmethod (setf component-property) (new-value (c component) property)
Daniel Barlow's avatar
Daniel Barlow committed
546
  (let ((a (assoc property (slot-value c 'properties) :test #'equal)))
547
    (if a
548 549 550
        (setf (cdr a) new-value)
        (setf (slot-value c 'properties)
              (acons property new-value (slot-value c 'properties))))))
551

Daniel Barlow's avatar
 
Daniel Barlow committed
552 553
(defclass system (module)
  ((description :accessor system-description :initarg :description)
Daniel Barlow's avatar
Daniel Barlow committed
554 555
   (long-description
    :accessor system-long-description :initarg :long-description)
Daniel Barlow's avatar
 
Daniel Barlow committed
556 557
   (author :accessor system-author :initarg :author)
   (maintainer :accessor system-maintainer :initarg :maintainer)
558
   (licence :accessor system-licence :initarg :licence
559 560
            :accessor system-license :initarg :license)
   (source-file :reader system-source-file :initarg :source-file
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
561
                :writer %set-system-source-file)))
Daniel Barlow's avatar
 
Daniel Barlow committed
562

563 564
;;;; -------------------------------------------------------------------------
;;;; version-satisfies
Daniel Barlow's avatar
 
Daniel Barlow committed
565 566 567 568 569

(defmethod version-satisfies ((c component) version)
  (unless (and version (slot-boundp c 'version))
    (return-from version-satisfies t))
  (let ((x (mapcar #'parse-integer
570 571 572
                   (split (component-version c) nil '(#\.))))
        (y (mapcar #'parse-integer
                   (split version nil '(#\.)))))
Daniel Barlow's avatar
 
Daniel Barlow committed
573
    (labels ((bigger (x y)
574 575 576 577 578
               (cond ((not y) t)
                     ((not x) nil)
                     ((> (car x) (car y)) t)
                     ((= (car x) (car y))
                      (bigger (cdr x) (cdr y))))))
Daniel Barlow's avatar
 
Daniel Barlow committed
579
      (and (= (car x) (car y))
580
           (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
Daniel Barlow's avatar
 
Daniel Barlow committed
581

582 583
;;;; -------------------------------------------------------------------------
;;;; Finding systems
Daniel Barlow's avatar
 
Daniel Barlow committed
584

Gary King's avatar
Gary King committed
585 586 587 588 589
(defun make-defined-systems-table ()
  (make-hash-table :test 'equal))

(defvar *defined-systems* (make-defined-systems-table))

Daniel Barlow's avatar
 
Daniel Barlow committed
590
(defun coerce-name (name)
591 592 593 594 595
  (typecase name
    (component (component-name name))
    (symbol (string-downcase (symbol-name name)))
    (string name)
    (t (sysdef-error "~@<invalid component designator ~A~@:>" name))))
Daniel Barlow's avatar
 
Daniel Barlow committed
596

597 598 599
(defun system-registered-p (name)
  (gethash (coerce-name name) *defined-systems*))

Gary King's avatar
Gary King committed
600 601 602 603 604 605
(defun map-systems (fn)
  "Apply `fn` to each defined system.

`fn` should be a function of one argument. It will be
called with an object of type asdf:system."
  (maphash (lambda (_ datum)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
606 607 608 609 610
             (declare (ignore _))
             (destructuring-bind (_ . def) datum
               (declare (ignore _))
               (funcall fn def)))
           *defined-systems*))
611

612 613 614 615 616 617
;;; for the sake of keeping things reasonably neat, we adopt a
;;; convention that functions in this list are prefixed SYSDEF-

(defvar *system-definition-search-functions*
  '(sysdef-central-registry-search))

618
(defun system-definition-pathname (system)
619 620 621
  (let ((system-name (coerce-name system)))
    (or
     (some (lambda (x) (funcall x system-name))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
622
           *system-definition-search-functions*)
623
     (let ((system-pair (system-registered-p system-name)))
624
       (and system-pair
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
625
            (system-source-file (cdr system-pair)))))))
626

627
(defvar *central-registry*
Gary King's avatar
Gary King committed
628
  `((directory-namestring *default-pathname-defaults*))
629 630
"A list of 'system directory designators' ASDF uses to find systems.

631
A 'system directory designator' is a pathname or a function
632 633 634 635 636 637 638
which evaluates to a pathname. For example:

    (setf asdf:*central-registry*
          (list '*default-pathname-defaults*
                #p\"/home/me/cl/systems/\"
                #p\"/usr/share/common-lisp/systems/\"))
")
639

640
(defun directory-pathname-p (pathname)
Gary King's avatar
Gary King committed
641 642 643
  "Does `pathname` represent a directory?

A directory-pathname is a pathname _without_ a filename. The three
644
ways that the filename components can be missing are for it to be `nil`,
Gary King's avatar
Gary King committed
645 646 647 648
`:unspecific` or the empty string.

Note that this does _not_ check to see that `pathname` points to an
actually-existing directory."
649
  (flet ((check-one (x)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
650 651
           (not (null (member x '(nil :unspecific "")
                              :test 'equal)))))
652
    (and (check-one (pathname-name pathname))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
653
         (check-one (pathname-type pathname)))))
Gary King's avatar
Gary King committed
654

655 656 657 658
(defun ensure-directory-pathname (pathname)
  (if (directory-pathname-p pathname)
      pathname
      (make-pathname :defaults pathname
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
659 660 661 662
                     :directory (append
                                 (pathname-directory pathname)
                                 (list (file-namestring pathname)))
                     :name nil :type nil :version nil)))
663

664
(defun sysdef-central-registry-search (system)
665
  (let ((name (coerce-name system))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
666 667
        (to-remove nil)
        (to-replace nil))
668
    (block nil
669
      (unwind-protect
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
670 671 672 673 674 675 676 677
           (dolist (dir *central-registry*)
             (let ((defaults (eval dir)))
               (when defaults
                 (cond ((directory-pathname-p defaults)
                        (let ((file (and defaults
                                         (make-pathname
                                          :defaults defaults :version :newest
                                          :name name :type "asd" :case :local)))
678
                               #+(and (or win32 windows) (not :clisp))
679 680 681
                               (shortcut (make-pathname
                                          :defaults defaults :version :newest
                                          :name name :type "asd.lnk" :case :local)))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
682 683
                          (if (and file (probe-file file))
                              (return file))
684
                          #+(and (or win32 windows) (not :clisp))
685 686 687
                          (when (probe-file shortcut)
                            (let ((target (parse-windows-shortcut shortcut)))
                              (when target
688
                                (return (pathname target)))))))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
689 690 691 692 693 694
                       (t
                        (restart-case
                            (let* ((*print-circle* nil)
                                   (message
                                    (format nil
                                            "~@<While searching for system `~a`: `~a` evaluated ~
695
to `~a` which is not a directory.~@:>"
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
                                            system dir defaults)))
                              (error message))
                          (remove-entry-from-registry ()
                            :report "Remove entry from *central-registry* and continue"
                            (push dir to-remove))
                          (coerce-entry-to-directory ()
                            :report (lambda (s)
                                      (format s "Coerce entry to ~a, replace ~a and continue."
                                              (ensure-directory-pathname defaults) dir))
                            (push (cons dir (ensure-directory-pathname defaults)) to-replace))))))))
        ;; cleanup
        (dolist (dir to-remove)
          (setf *central-registry* (remove dir *central-registry*)))
        (dolist (pair to-replace)
          (let* ((current (car pair))
                 (new (cdr pair))
                 (position (position current *central-registry*)))
            (setf *central-registry*
                  (append (subseq *central-registry* 0 position)
                          (list new)
                          (subseq *central-registry* (1+ position))))))))))
717

Christophe Rhodes's avatar
Fixes  
Christophe Rhodes committed
718 719 720
(defun make-temporary-package ()
  (flet ((try (counter)
           (ignore-errors
721
             (make-package (format nil "~a~D" 'asdf counter)
722
                           :use '(:cl :asdf)))))
Christophe Rhodes's avatar
Fixes  
Christophe Rhodes committed
723 724 725
    (do* ((counter 0 (+ counter 1))
          (package (try counter) (try counter)))
         (package package))))
726

727 728 729 730 731 732 733 734
(defun safe-file-write-date (pathname)
           ;; if FILE-WRITE-DATE returns NIL, it's possible that the
           ;; user or some other agent has deleted an input file.  If
           ;; that's the case, well, that's not good, but as long as
           ;; the operation is otherwise considered to be done we
           ;; could continue and survive.
  (or (file-write-date pathname) 0))

Daniel Barlow's avatar
 
Daniel Barlow committed
735 736
(defun find-system (name &optional (error-p t))
  (let* ((name (coerce-name name))
737
         (in-memory (system-registered-p name))
738
         (on-disk (system-definition-pathname name)))
Daniel Barlow's avatar
 
Daniel Barlow committed
739
    (when (and on-disk
740
               (or (not in-memory)
741
                   (< (car in-memory) (safe-file-write-date on-disk))))
Christophe Rhodes's avatar
Fixes  
Christophe Rhodes committed
742 743 744
      (let ((package (make-temporary-package)))
        (unwind-protect
             (let ((*package* package))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
745
               (asdf-message
Christophe Rhodes's avatar
Fixes  
Christophe Rhodes committed
746 747 748
                "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%"
                ;; FIXME: This wants to be (ENOUGH-NAMESTRING
                ;; ON-DISK), but CMUCL barfs on that.
749 750
                on-disk
                *package*)
Christophe Rhodes's avatar
Fixes  
Christophe Rhodes committed
751 752
               (load on-disk))
          (delete-package package))))
753
    (let ((in-memory (system-registered-p name)))
Daniel Barlow's avatar
 
Daniel Barlow committed
754
      (if in-memory
755
          (progn (if on-disk (setf (car in-memory)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
756
                                   (safe-file-write-date on-disk)))
757 758
                 (cdr in-memory))
          (if error-p (error 'missing-component :requires name))))))
Daniel Barlow's avatar
 
Daniel Barlow committed
759 760

(defun register-system (name system)
761
  (asdf-message "~&~@<; ~@;registering ~A as ~A~@:>~%" system name)
762
  (setf (gethash (coerce-name name) *defined-systems*)
763
        (cons (get-universal-time) system)))
Daniel Barlow's avatar
 
Daniel Barlow committed
764

765

766 767
;;;; -------------------------------------------------------------------------
;;;; Finding components
Daniel Barlow's avatar
Daniel Barlow committed
768

Daniel Barlow's avatar
Daniel Barlow committed
769
(defmethod find-component ((module module) name &optional version)
Daniel Barlow's avatar
Daniel Barlow committed
770
  (if (slot-boundp module 'components)
771
      (let ((m (find name (module-components module)
772 773 774
                     :test #'equal :key #'component-name)))
        (if (and m (version-satisfies m version)) m))))

Daniel Barlow's avatar
Daniel Barlow committed
775 776

;;; a component with no parent is a system
Daniel Barlow's avatar
Daniel Barlow committed
777
(defmethod find-component ((module (eql nil)) name &optional version)
Daniel Barlow's avatar
 
Daniel Barlow committed
778
  (let ((m (find-system name nil)))
779
    (if (and m (version-satisfies m version)) m)))
Daniel Barlow's avatar
Daniel Barlow committed
780

Daniel Barlow's avatar
 
Daniel Barlow committed
781 782
;;; component subclasses

Daniel Barlow's avatar
Daniel Barlow committed
783 784 785
(defclass source-file (component) ())

(defclass cl-source-file (source-file) ())
Daniel Barlow's avatar
Daniel Barlow committed
786 787
(defclass c-source-file (source-file) ())
(defclass java-source-file (source-file) ())
788 789 790
(defclass static-file (source-file) ())
(defclass doc-file (static-file) ())
(defclass html-file (doc-file) ())
Daniel Barlow's avatar
Daniel Barlow committed
791

Daniel Barlow's avatar
Daniel Barlow committed
792 793 794
(defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
(defmethod source-file-type ((c c-source-file) (s module)) "c")
(defmethod source-file-type ((c java-source-file) (s module)) "java")
Daniel Barlow's avatar
 
Daniel Barlow committed
795
(defmethod source-file-type ((c html-file) (s module)) "html")
796 797
(defmethod source-file-type ((c static-file) (s module)) nil)

798 799 800 801 802 803 804 805
(defun merge-component-relative-pathname (pathname name type)
  (multiple-value-bind (relative path filename)
      (split-path-string name)
  (merge-pathnames
   (or pathname (make-pathname :directory `(,relative ,@path)))
   (if type
       (make-pathname :name filename :type type)
       filename))))
806 807

(defmethod component-relative-pathname ((component source-file))
808 809 810 811
  (merge-component-relative-pathname
   (slot-value component 'relative-pathname)
   (component-name component)
   (source-file-type component (component-system component))))
812

813 814
;;;; -------------------------------------------------------------------------
;;;; Operations
Daniel Barlow's avatar
Daniel Barlow committed
815

816
;;; one of these is instantiated whenever #'operate is called
Daniel Barlow's avatar
Daniel Barlow committed
817 818

(defclass operation ()
819
  ((forced :initform nil :initarg :force :accessor operation-forced)
820
   (original-initargs :initform nil :initarg :original-initargs
821
                      :accessor operation-original-initargs)
822 823 824 825
   (visited-nodes :initform nil :accessor operation-visited-nodes)
   (visiting-nodes :initform nil :accessor operation-visiting-nodes)
   (parent :initform nil :initarg :parent :accessor operation-parent)))

826 827 828 829 830
(defmethod print-object ((o operation) stream)
  (print-unreadable-object (o stream :type t :identity t)
    (ignore-errors
      (prin1 (operation-original-initargs o) stream))))

831
(defmethod shared-initialize :after ((operation operation) slot-names
832 833
                                     &key force
                                     &allow-other-keys)
834 835 836
  (declare (ignore slot-names force))
  ;; empty method to disable initarg validity checking
  )
Daniel Barlow's avatar
Daniel Barlow committed
837

838 839 840
(defun node-for (o c)
  (cons (class-name (class-of o)) c))

841 842 843 844 845
(defmethod operation-ancestor ((operation operation))
  (aif (operation-parent operation)
       (operation-ancestor it)
       operation))

846 847 848

(defun make-sub-operation (c o dep-c dep-o)
  (let* ((args (copy-list (operation-original-initargs o)))
849
         (force-p (getf args :force)))
850 851 852
    ;; note explicit comparison with T: any other non-NIL force value
    ;; (e.g. :recursive) will pass through
    (cond ((and (null (component-parent c))
853 854 855 856 857 858 859 860 861 862 863 864
                (null (component-parent dep-c))
                (not (eql c dep-c)))
           (when (eql force-p t)
             (setf (getf args :force) nil))
           (apply #'make-instance dep-o
                  :parent o
                  :original-initargs args args))
          ((subtypep (type-of o) dep-o)
           o)
          (t
           (apply #'make-instance dep-o
                  :parent o :original-initargs args args)))))
865

866

Daniel Barlow's avatar
 
Daniel Barlow committed
867 868 869
(defmethod visit-component ((o operation) (c component) data)
  (unless (component-visited-p o c)
    (push (cons (node-for o c) data)
870
          (operation-visited-nodes (operation-ancestor o)))))
Daniel Barlow's avatar
Daniel Barlow committed
871 872

(defmethod component-visited-p ((o operation) (c component))
Daniel Barlow's avatar
 
Daniel Barlow committed
873
  (assoc (node-for o c)
874 875
         (operation-visited-nodes (operation-ancestor o))
         :test 'equal))
Daniel Barlow's avatar
Daniel Barlow committed
876

877 878 879
(defmethod (setf visiting-component) (new-value operation component)
  ;; MCL complains about unused lexical variables
  (declare (ignorable new-value operation component)))
880

Daniel Barlow's avatar
Daniel Barlow committed
881
(defmethod (setf visiting-component) (new-value (o operation) (c component))
882
  (let ((node (node-for o c))
883
        (a (operation-ancestor o)))
884
    (if new-value
885 886 887
        (pushnew node (operation-visiting-nodes a) :test 'equal)
        (setf (operation-visiting-nodes a)
              (remove node  (operation-visiting-nodes a) :test 'equal)))))
Daniel Barlow's avatar
Daniel Barlow committed
888 889

(defmethod component-visiting-p ((o operation) (c component))
890
  (let ((node (node-for o c)))
891
    (member node (operation-visiting-nodes (operation-ancestor o))
892
            :test 'equal)))
Daniel Barlow's avatar
Daniel Barlow committed
893

894 895
(defmethod component-depends-on ((op-spec symbol) (c component))
  (component-depends-on (make-instance op-spec) c))
896 897

(defmethod component-depends-on ((o operation) (c component))
898
  (cdr (assoc (class-name (class-of o))
899
              (component-in-order-to c))))
900

Daniel Barlow's avatar
 
Daniel Barlow committed
901 902 903
(defmethod component-self-dependencies ((o operation) (c component))
  (let ((all-deps (component-depends-on o c)))
    (remove-if-not (lambda (x)
904 905 906
                     (member (component-name c) (cdr x) :test #'string=))
                   all-deps)))

Daniel Barlow's avatar
 
Daniel Barlow committed
907 908
(defmethod input-files ((operation operation) (c component))
  (let ((parent (component-parent c))
909
        (self-deps (component-self-dependencies operation c)))
Daniel Barlow's avatar
 
Daniel Barlow committed
910
    (if self-deps
911 912 913 914 915 916 917 918
        (mapcan (lambda (dep)
                  (destructuring-bind (op name) dep
                    (output-files (make-instance op)
                                  (find-component parent name))))
                self-deps)
        ;; no previous operations needed?  I guess we work with the
        ;; original source file, then
        (list (component-pathname c)))))
Daniel Barlow's avatar
 
Daniel Barlow committed
919

920
(defmethod input-files ((operation operation) (c module)) nil)
921

Daniel Barlow's avatar
 
Daniel Barlow committed
922
(defmethod operation-done-p ((o operation) (c component))
923
  (flet ((fwd-or-return-t (file)
924
           (let ((date (safe-file-write-date file)))
925 926
             (cond
               (date)
927
               (t
928
                (warn "~@<Missing FILE-WRITE-DATE for ~S: treating ~
929
                       operation ~S on component ~S as done.~@:>"
930 931 932 933 934 935
                      file o c)
                (return-from operation-done-p t))))))
    (let ((out-files (output-files o c))
          (in-files (input-files o c)))
      (cond ((and (not in-files) (not out-files))
             ;; arbitrary decision: an operation that uses nothing to
936
             ;; produce nothing probably isn't doing much
937
             t)
938
            ((not out-files)
939 940 941 942 943 944 945 946 947 948 949
             (let ((op-done
                    (gethash (type-of o)
                             (component-operation-times c))))
               (and op-done
                    (>= op-done
                        (apply #'max
                               (mapcar #'fwd-or-return-t in-files))))))
            ((not in-files) nil)
            (t
             (and
              (every #'probe-file out-files)
950
              (> (apply #'min (mapcar #'safe-file-write-date out-files))
951
                 (apply #'max (mapcar #'fwd-or-return-t in-files)))))))))
952

Daniel Barlow's avatar
Daniel Barlow committed
953 954 955
;;; So you look at this code and think "why isn't it a bunch of
;;; methods".  And the answer is, because standard method combination
;;; runs :before methods most->least-specific, which is back to front
956
;;; for our purposes.
Daniel Barlow's avatar
Daniel Barlow committed
957

Daniel Barlow's avatar
Daniel Barlow committed
958
(defmethod traverse ((operation operation) (c component))
Daniel Barlow's avatar
 
Daniel Barlow committed
959
  (let ((forced nil))
Gary King's avatar
Gary King committed
960
    (labels ((%do-one-dep (required-op required-c required-v)
961 962 963 964 965 966
               (let* ((dep-c (or (find-component
                                  (component-parent c)
                                  ;; XXX tacky.  really we should build the
                                  ;; in-order-to slot with canonicalized
                                  ;; names instead of coercing this late
                                  (coerce-name required-c) required-v)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
967 968 969 970 971 972 973 974
                                 (if required-v
                                     (error 'missing-dependency-of-version
                                            :required-by c
                                            :version required-v
                                            :requires required-c)
                                     (error 'missing-dependency
                                            :required-by c
                                            :requires required-c))))
975 976
                      (op (make-sub-operation c operation dep-c required-op)))
                 (traverse op dep-c)))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
977
             (do-one-dep (required-op required-c required-v)
Gary King's avatar
Gary King committed
978
               (loop
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
979 980 981 982 983 984 985 986
                  (restart-case
                      (return (%do-one-dep required-op required-c required-v))
                    (retry ()
                      :report (lambda (s)
                                (format s "~@<Retry loading component ~S.~@:>"
                                        required-c))
                      :test
                      (lambda (c)
Gary King's avatar
Gary King committed
987
#|
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
988 989 990 991 992
                        (print (list :c1 c (typep c 'missing-dependency)))
                        (when (typep c 'missing-dependency)
                          (print (list :c2 (missing-requires c) required-c
                                       (equalp (missing-requires c)
                                               required-c))))
Gary King's avatar
Gary King committed
993
|#
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
994 995 996
                        (and (typep c 'missing-dependency)
                             (equalp (missing-requires c)
                                     required-c)))))))
997 998 999
             (do-dep (op dep)
               (cond ((eq op 'feature)
                      (or (member (car dep) *features*)
Nikodemus Siivola's avatar
Nikodemus Siivola committed
1000
                          (error 'missing-dependency
1001
                                 :required-by c
1002
                                 :requires (car dep))))
1003 1004
                     (t
                      (dolist (d dep)
Daniel Barlow's avatar
 
Daniel Barlow committed
1005
                        (cond ((consp d)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
                               (cond ((string-equal
                                       (symbol-name (first d))
                                       "VERSION")
                                      (appendf
                                       forced
                                       (do-one-dep op (second d) (third d))))
                                     ((and (string-equal
                                            (symbol-name (first d))
                                            "FEATURE")
                                           (find (second d) *features*
                                                 :test 'string-equal))
                                      (appendf
                                       forced
                                       (do-one-dep op (second d) (third d))))
                                     (t
                                      (error "Bad dependency ~a.  Dependencies must be (:version <version>), (:feature <feature>), or a name" d))))
Daniel Barlow's avatar
 
Daniel Barlow committed
1022 1023 1024
                              (t
                               (appendf forced (do-one-dep op d nil)))))))))
      (aif (component-visited-p operation c)
1025 1026
           (return-from traverse
             (if (cdr it) (list (cons 'pruned-op c)) nil)))
Daniel Barlow's avatar
 
Daniel Barlow committed
1027 1028
      ;; dependencies
      (if (component-visiting-p operation c)
1029
          (error 'circular-dependency :components (list c)))
Daniel Barlow's avatar
 
Daniel Barlow committed
1030
      (setf (visiting-component operation c) t)
1031
      (unwind-protect
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
           (progn
             (loop for (required-op . deps) in
                  (component-depends-on operation c)
                  do (do-dep required-op deps))
             ;; constituent bits
             (let ((module-ops
                    (when (typep c 'module)
                      (let ((at-least-one nil)
                            (forced nil)
                            (error nil))
                        (loop for kid in (module-components c)
                           do (handler-case
                                  (appendf forced (traverse operation kid ))
                                (missing-dependency (condition)
                                  (if (eq (module-if-component-dep-fails c)
                                          :fail)
                                      (error condition))
                                  (setf error condition))
                                (:no-error (c)
                                  (declare (ignore c))
                                  (setf at-least-one t))))
                        (when (and (eq (module-if-component-dep-fails c)
                                       :try-next)
                                   (not at-least-one))
                          (error error))
                        forced))))
               ;; now the thing itself
               (when (or forced module-ops
                         (not (operation-done-p operation c))
                         (let ((f (operation-forced
                                   (operation-ancestor operation))))
                           (and f (or (not (consp f))
                                      (member (component-name
                                               (operation-ancestor operation))
                                              (mapcar #'coerce-name f)
                                              :test #'string=)))))
                 (let ((do-first (cdr (assoc (class-name (class-of operation))