~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to contrib/asdf/asdf.lisp

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2006-05-17 02:46:26 UTC
  • Revision ID: james.westby@ubuntu.com-20060517024626-lljr08ftv9g9vefl
Tags: upstream-0.9h-20060510
ImportĀ upstreamĀ versionĀ 0.9h-20060510

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; This is asdf: Another System Definition Facility.  $Revision: 1.4 $
 
2
;;;
 
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/>
 
7
;;;
 
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'
 
15
 
 
16
;;; Copyright (c) 2001-2003 Daniel Barlow and contributors
 
17
;;;
 
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:
 
25
;;;
 
26
;;; The above copyright notice and this permission notice shall be
 
27
;;; included in all copies or substantial portions of the Software.
 
28
;;;
 
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.
 
36
 
 
37
;;; the problem with writing a defsystem replacement is bootstrapping:
 
38
;;; we can't use defsystem to compile it.  Hence, all in one file
 
39
 
 
40
(defpackage #:asdf
 
41
  (:export #:defsystem #:oos #:operate #:find-system #:run-shell-command
 
42
           #:system-definition-pathname #:find-component ; miscellaneous
 
43
           #:hyperdocumentation #:hyperdoc
 
44
           
 
45
           #:compile-op #:load-op #:load-source-op #:test-system-version
 
46
           #:test-op
 
47
           #:operation                  ; operations
 
48
           #:feature                    ; sort-of operation
 
49
           #:version                    ; metaphorically sort-of an operation
 
50
           
 
51
           #:input-files #:output-files #:perform       ; operation methods
 
52
           #:operation-done-p #:explain
 
53
           
 
54
           #:component #:source-file 
 
55
           #:c-source-file #:cl-source-file #:java-source-file
 
56
           #:static-file
 
57
           #:doc-file
 
58
           #:html-file
 
59
           #:text-file
 
60
           #:source-file-type
 
61
           #:module                     ; components
 
62
           #:system
 
63
           #:unix-dso
 
64
           
 
65
           #:module-components          ; component accessors
 
66
           #:component-pathname
 
67
           #:component-relative-pathname
 
68
           #:component-name
 
69
           #:component-version
 
70
           #:component-parent
 
71
           #:component-property
 
72
           #:component-system
 
73
           
 
74
           #:component-depends-on
 
75
 
 
76
           #:system-description
 
77
           #:system-long-description
 
78
           #:system-author
 
79
           #:system-maintainer
 
80
           #:system-license
 
81
           
 
82
           #:operation-on-warnings
 
83
           #:operation-on-failure
 
84
           
 
85
           ;#:*component-parent-pathname* 
 
86
           #:*system-definition-search-functions*
 
87
           #:*central-registry*         ; variables
 
88
           #:*compile-file-warnings-behaviour*
 
89
           #:*compile-file-failure-behaviour*
 
90
           #:*asdf-revision*
 
91
           
 
92
           #:operation-error #:compile-failed #:compile-warned #:compile-error
 
93
           #:error-component #:error-operation
 
94
           #:system-definition-error 
 
95
           #:missing-component
 
96
           #:missing-dependency
 
97
           #:circular-dependency        ; errors
 
98
 
 
99
           #:retry
 
100
           #:accept                     ; restarts
 
101
           
 
102
           )
 
103
  (:use :cl))
 
104
 
 
105
#+nil
 
106
(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")
 
107
 
 
108
 
 
109
(in-package #:asdf)
 
110
 
 
111
(defvar *asdf-revision* (let* ((v "$Revision: 1.4 $")
 
112
                               (colon (or (position #\: v) -1))
 
113
                               (dot (position #\. v)))
 
114
                          (and v colon dot 
 
115
                               (list (parse-integer v :start (1+ colon)
 
116
                                                    :junk-allowed t)
 
117
                                     (parse-integer v :start (1+ dot)
 
118
                                                    :junk-allowed t)))))
 
119
 
 
120
(defvar *compile-file-warnings-behaviour* :warn)
 
121
(defvar *compile-file-failure-behaviour* #+sbcl :error #-sbcl :warn)
 
122
 
 
123
(defvar *verbose-out* nil)
 
124
 
 
125
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
126
;; utility stuff
 
127
 
 
128
(defmacro aif (test then &optional else)
 
129
  `(let ((it ,test)) (if it ,then ,else)))
 
130
 
 
131
(defun pathname-sans-name+type (pathname)
 
132
  "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
 
133
and NIL NAME and TYPE components"
 
134
  (make-pathname :name nil :type nil :defaults pathname))
 
135
 
 
136
(define-modify-macro appendf (&rest args) 
 
137
                     append "Append onto list") 
 
138
 
 
139
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
140
;; classes, condiitons
 
141
 
 
142
(define-condition system-definition-error (error) ()
 
143
  ;; [this use of :report should be redundant, but unfortunately it's not.
 
144
  ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
 
145
  ;; over print-object; this is always conditions::%print-condition for
 
146
  ;; condition objects, which in turn does inheritance of :report options at
 
147
  ;; run-time.  fortunately, inheritance means we only need this kludge here in
 
148
  ;; order to fix all conditions that build on it.  -- rgr, 28-Jul-02.]
 
149
  #+cmu (:report print-object))
 
150
 
 
151
(define-condition formatted-system-definition-error (system-definition-error)
 
152
  ((format-control :initarg :format-control :reader format-control)
 
153
   (format-arguments :initarg :format-arguments :reader format-arguments))
 
154
  (:report (lambda (c s)
 
155
             (apply #'format s (format-control c) (format-arguments c)))))
 
156
 
 
157
(define-condition circular-dependency (system-definition-error)
 
158
  ((components :initarg :components :reader circular-dependency-components)))
 
159
 
 
160
(define-condition missing-component (system-definition-error)
 
161
  ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
 
162
   (version :initform nil :reader missing-version :initarg :version)
 
163
   (parent :initform nil :reader missing-parent :initarg :parent)))
 
164
 
 
165
(define-condition missing-dependency (missing-component)
 
166
  ((required-by :initarg :required-by :reader missing-required-by)))
 
167
 
 
168
(define-condition operation-error (error)
 
169
  ((component :reader error-component :initarg :component)
 
170
   (operation :reader error-operation :initarg :operation))
 
171
  (:report (lambda (c s)
 
172
             (format s "~@<erred while invoking ~A on ~A~@:>"
 
173
                     (error-operation c) (error-component c)))))
 
174
(define-condition compile-error (operation-error) ())
 
175
(define-condition compile-failed (compile-error) ())
 
176
(define-condition compile-warned (compile-error) ())
 
177
 
 
178
(defclass component ()
 
179
  ((name :accessor component-name :initarg :name :documentation
 
180
         "Component name: designator for a string composed of portable pathname characters")
 
181
   (version :accessor component-version :initarg :version)
 
182
   (original-depends-on :accessor component-original-depends-on :initarg :original-depends-on :initform nil)
 
183
   (in-order-to :initform nil :initarg :in-order-to)
 
184
   ;;; XXX crap name
 
185
   (do-first :initform nil :initarg :do-first)
 
186
   ;; methods defined using the "inline" style inside a defsystem form:
 
187
   ;; need to store them somewhere so we can delete them when the system
 
188
   ;; is re-evaluated
 
189
   (inline-methods :accessor component-inline-methods :initform nil)
 
190
   (parent :initarg :parent :initform nil :reader component-parent)
 
191
   ;; no direct accessor for pathname, we do this as a method to allow
 
192
   ;; it to default in funky ways if not supplied
 
193
   (relative-pathname :initarg :pathname)
 
194
   (operation-times :initform (make-hash-table )
 
195
                    :accessor component-operation-times)
 
196
   ;; XXX we should provide some atomic interface for updating the
 
197
   ;; component properties
 
198
   (properties :accessor component-properties :initarg :properties
 
199
               :initform nil)))
 
200
 
 
201
;;;; methods: conditions
 
202
 
 
203
(defmethod print-object ((c missing-dependency) s)
 
204
  (format s "~@<~A, required by ~A~@:>"
 
205
          (call-next-method c nil) (missing-required-by c)))
 
206
 
 
207
(defun sysdef-error (format &rest arguments)
 
208
  (error 'formatted-system-definition-error :format-control format :format-arguments arguments))
 
209
 
 
210
;;;; methods: components
 
211
 
 
212
(defmethod print-object ((c missing-component) s)
 
213
  (format s "~@<component ~S not found~
 
214
             ~@[ or does not match version ~A~]~
 
215
             ~@[ in ~A~]~@:>"
 
216
          (missing-requires c)
 
217
          (missing-version c)
 
218
          (when (missing-parent c)
 
219
            (component-name (missing-parent c)))))
 
220
 
 
221
(defgeneric component-system (component)
 
222
  (:documentation "Find the top-level system containing COMPONENT"))
 
223
  
 
224
(defmethod component-system ((component component))
 
225
  (aif (component-parent component)
 
226
       (component-system it)
 
227
       component))
 
228
 
 
229
(defmethod print-object ((c component) stream)
 
230
  (print-unreadable-object (c stream :type t :identity t)
 
231
    (ignore-errors
 
232
      (prin1 (component-name c) stream))))
 
233
 
 
234
(defclass module (component)
 
235
  ((components :initform nil :accessor module-components :initarg :components)
 
236
   ;; what to do if we can't satisfy a dependency of one of this module's
 
237
   ;; components.  This allows a limited form of conditional processing
 
238
   (if-component-dep-fails :initform :fail
 
239
                           :accessor module-if-component-dep-fails
 
240
                           :initarg :if-component-dep-fails)
 
241
   (default-component-class :accessor module-default-component-class
 
242
     :initform 'cl-source-file :initarg :default-component-class)))
 
243
 
 
244
(defgeneric component-pathname (component)
 
245
  (:documentation "Extracts the pathname applicable for a particular component."))
 
246
 
 
247
(defun component-parent-pathname (component)
 
248
  (aif (component-parent component)
 
249
       (component-pathname it)
 
250
       *default-pathname-defaults*))
 
251
 
 
252
(defgeneric component-relative-pathname (component)
 
253
  (:documentation "Extracts the relative pathname applicable for a particular component."))
 
254
   
 
255
(defmethod component-relative-pathname ((component module))
 
256
  (or (slot-value component 'relative-pathname)
 
257
      (make-pathname
 
258
       :directory `(:relative ,(component-name component))
 
259
       :host (pathname-host (component-parent-pathname component)))))
 
260
 
 
261
(defmethod component-pathname ((component component))
 
262
  (let ((*default-pathname-defaults* (component-parent-pathname component)))
 
263
    (merge-pathnames (component-relative-pathname component))))
 
264
 
 
265
(defgeneric component-property (component property))
 
266
 
 
267
(defmethod component-property ((c component) property)
 
268
  (cdr (assoc property (slot-value c 'properties) :test #'equal)))
 
269
 
 
270
(defgeneric (setf component-property) (new-value component property))
 
271
 
 
272
(defmethod (setf component-property) (new-value (c component) property)
 
273
  (let ((a (assoc property (slot-value c 'properties) :test #'equal)))
 
274
    (if a
 
275
        (setf (cdr a) new-value)
 
276
        (setf (slot-value c 'properties)
 
277
              (acons property new-value (slot-value c 'properties))))))
 
278
 
 
279
(defclass system (module)
 
280
  ((description :accessor system-description :initarg :description)
 
281
   (long-description
 
282
    :accessor system-long-description :initarg :long-description)
 
283
   (author :accessor system-author :initarg :author)
 
284
   (maintainer :accessor system-maintainer :initarg :maintainer)
 
285
   (licence :accessor system-licence :initarg :licence)))
 
286
 
 
287
;;; version-satisfies
 
288
 
 
289
;;; with apologies to christophe rhodes ...
 
290
(defun split (string &optional max (ws '(#\Space #\Tab)))
 
291
  (flet ((is-ws (char) (find char ws)))
 
292
    (nreverse
 
293
     (let ((list nil) (start 0) (words 0) end)
 
294
       (loop
 
295
        (when (and max (>= words (1- max)))
 
296
          (return (cons (subseq string start) list)))
 
297
        (setf end (position-if #'is-ws string :start start))
 
298
        (push (subseq string start end) list)
 
299
        (incf words)
 
300
        (unless end (return list))
 
301
        (setf start (1+ end)))))))
 
302
 
 
303
(defgeneric version-satisfies (component version))
 
304
 
 
305
(defmethod version-satisfies ((c component) version)
 
306
  (unless (and version (slot-boundp c 'version))
 
307
    (return-from version-satisfies t))
 
308
  (let ((x (mapcar #'parse-integer
 
309
                   (split (component-version c) nil '(#\.))))
 
310
        (y (mapcar #'parse-integer
 
311
                   (split version nil '(#\.)))))
 
312
    (labels ((bigger (x y)
 
313
               (cond ((not y) t)
 
314
                     ((not x) nil)
 
315
                     ((> (car x) (car y)) t)
 
316
                     ((= (car x) (car y))
 
317
                      (bigger (cdr x) (cdr y))))))
 
318
      (and (= (car x) (car y))
 
319
           (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
 
320
 
 
321
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
322
;;; finding systems
 
323
 
 
324
(defvar *defined-systems* (make-hash-table :test 'equal))
 
325
(defun coerce-name (name)
 
326
   (typecase name
 
327
     (component (component-name name))
 
328
     (symbol (string-downcase (symbol-name name)))
 
329
     (string name)
 
330
     (t (sysdef-error "~@<invalid component designator ~A~@:>" name))))
 
331
 
 
332
;;; for the sake of keeping things reasonably neat, we adopt a
 
333
;;; convention that functions in this list are prefixed SYSDEF-
 
334
 
 
335
(defvar *system-definition-search-functions*
 
336
  '(sysdef-central-registry-search))
 
337
 
 
338
(defun system-definition-pathname (system)
 
339
  (some (lambda (x) (funcall x system))
 
340
        *system-definition-search-functions*))
 
341
        
 
342
(defvar *central-registry*
 
343
  '(*default-pathname-defaults*
 
344
    #+nil "/home/dan/src/sourceforge/cclan/asdf/systems/"
 
345
    #+nil "telent:asdf;systems;"))
 
346
 
 
347
(defun sysdef-central-registry-search (system)
 
348
  (let ((name (coerce-name system)))
 
349
    (block nil
 
350
      (dolist (dir *central-registry*)
 
351
        (let* ((defaults (eval dir))
 
352
               (file (and defaults
 
353
                          (make-pathname
 
354
                           :defaults defaults :version :newest
 
355
                           :name name :type "asd" :case :local))))
 
356
          (if (and file (probe-file file))
 
357
              (return file)))))))
 
358
 
 
359
 
 
360
(defun find-system (name &optional (error-p t))
 
361
  (let* ((name (coerce-name name))
 
362
         (in-memory (gethash name *defined-systems*))
 
363
         (on-disk (system-definition-pathname name)))    
 
364
    (when (and on-disk
 
365
               (or (not in-memory)
 
366
                   (< (car in-memory) (file-write-date on-disk))))
 
367
      (let ((*package* (make-package (gensym #.(package-name *package*))
 
368
                                     :use '(:cl :asdf))))
 
369
        (format *verbose-out*
 
370
                "~&~@<; ~@;loading system definition from ~A into ~A~@:>~%"
 
371
                ;; FIXME: This wants to be (ENOUGH-NAMESTRING
 
372
                ;; ON-DISK), but CMUCL barfs on that.
 
373
                on-disk
 
374
                *package*)
 
375
        (load on-disk)))
 
376
    (let ((in-memory (gethash name *defined-systems*)))
 
377
      (if in-memory
 
378
          (progn (if on-disk (setf (car in-memory) (file-write-date on-disk)))
 
379
                 (cdr in-memory))
 
380
          (if error-p (error 'missing-component :requires name))))))
 
381
 
 
382
(defun register-system (name system)
 
383
  (format *verbose-out* "~&~@<; ~@;registering ~A as ~A~@:>~%" system name)
 
384
  (setf (gethash (coerce-name  name) *defined-systems*)
 
385
        (cons (get-universal-time) system)))
 
386
 
 
387
(defun system-registered-p (name)
 
388
  (gethash (coerce-name name) *defined-systems*))
 
389
 
 
390
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
391
;;; finding components
 
392
 
 
393
(defgeneric find-component (module name &optional version)
 
394
  (:documentation "Finds the component with name NAME present in the
 
395
MODULE module; if MODULE is nil, then the component is assumed to be a
 
396
system."))
 
397
 
 
398
(defmethod find-component ((module module) name &optional version)
 
399
  (if (slot-boundp module 'components)
 
400
      (let ((m (find name (module-components module)
 
401
                     :test #'equal :key #'component-name)))
 
402
        (if (and m (version-satisfies m version)) m))))
 
403
            
 
404
 
 
405
;;; a component with no parent is a system
 
406
(defmethod find-component ((module (eql nil)) name &optional version)
 
407
  (let ((m (find-system name nil)))
 
408
    (if (and m (version-satisfies m version)) m)))
 
409
 
 
410
;;; component subclasses
 
411
 
 
412
(defclass source-file (component) ())
 
413
 
 
414
(defclass cl-source-file (source-file) ())
 
415
(defclass c-source-file (source-file) ())
 
416
(defclass java-source-file (source-file) ())
 
417
(defclass static-file (source-file) ())
 
418
(defclass doc-file (static-file) ())
 
419
(defclass html-file (doc-file) ())
 
420
 
 
421
(defgeneric source-file-type (component system))
 
422
(defmethod source-file-type ((c cl-source-file) (s module)) "lisp")
 
423
(defmethod source-file-type ((c c-source-file) (s module)) "c")
 
424
(defmethod source-file-type ((c java-source-file) (s module)) "java")
 
425
(defmethod source-file-type ((c html-file) (s module)) "html")
 
426
(defmethod source-file-type ((c static-file) (s module)) nil)
 
427
 
 
428
(defmethod component-relative-pathname ((component source-file))
 
429
  (let* ((*default-pathname-defaults* (component-parent-pathname component))
 
430
         (name-type
 
431
          (make-pathname
 
432
           :name (component-name component)
 
433
           :type (source-file-type component
 
434
                                   (component-system component)))))
 
435
    (if (slot-value component 'relative-pathname)
 
436
        (merge-pathnames
 
437
         (slot-value component 'relative-pathname)
 
438
         name-type)
 
439
        name-type)))
 
440
 
 
441
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
442
;;; operations
 
443
 
 
444
;;; one of these is instantiated whenever (operate ) is called
 
445
 
 
446
(defclass operation ()
 
447
  ((forced :initform nil :initarg :force :accessor operation-forced)
 
448
   (original-initargs :initform nil :initarg :original-initargs
 
449
                      :accessor operation-original-initargs)
 
450
   (visited-nodes :initform nil :accessor operation-visited-nodes)
 
451
   (visiting-nodes :initform nil :accessor operation-visiting-nodes)
 
452
   (parent :initform nil :initarg :parent :accessor operation-parent)))
 
453
 
 
454
(defmethod print-object ((o operation) stream)
 
455
  (print-unreadable-object (o stream :type t :identity t)
 
456
    (ignore-errors
 
457
      (prin1 (operation-original-initargs o) stream))))
 
458
 
 
459
(defmethod shared-initialize :after ((operation operation) slot-names
 
460
                                     &key force 
 
461
                                     &allow-other-keys)
 
462
  (declare (ignore slot-names force))
 
463
  ;; empty method to disable initarg validity checking
 
464
  )
 
465
 
 
466
(defgeneric perform (operation component))
 
467
(defgeneric operation-done-p (operation component))
 
468
(defgeneric explain (operation component))
 
469
(defgeneric output-files (operation component))
 
470
(defgeneric input-files (operation component))
 
471
 
 
472
(defun node-for (o c)
 
473
  (cons (class-name (class-of o)) c))
 
474
 
 
475
(defgeneric operation-ancestor (operation)
 
476
  (:documentation   "Recursively chase the operation's parent pointer until we get to the head of the tree"))
 
477
 
 
478
(defmethod operation-ancestor ((operation operation))
 
479
  (aif (operation-parent operation)
 
480
       (operation-ancestor it)
 
481
       operation))
 
482
 
 
483
 
 
484
(defun make-sub-operation (c o dep-c dep-o)
 
485
  (let* ((args (copy-list (operation-original-initargs o)))
 
486
         (force-p (getf args :force)))
 
487
    ;; note explicit comparison with T: any other non-NIL force value
 
488
    ;; (e.g. :recursive) will pass through
 
489
    (cond ((and (null (component-parent c))
 
490
                (null (component-parent dep-c))
 
491
                (not (eql c dep-c)))
 
492
           (when (eql force-p t)
 
493
             (setf (getf args :force) nil))
 
494
           (apply #'make-instance dep-o
 
495
                  :parent o
 
496
                  :original-initargs args args))
 
497
          ((subtypep (type-of o) dep-o)
 
498
           o)
 
499
          (t 
 
500
           (apply #'make-instance dep-o
 
501
                  :parent o :original-initargs args args)))))
 
502
 
 
503
 
 
504
(defgeneric visit-component (operation component data))
 
505
 
 
506
(defmethod visit-component ((o operation) (c component) data)
 
507
  (unless (component-visited-p o c)
 
508
    (push (cons (node-for o c) data)
 
509
          (operation-visited-nodes (operation-ancestor o)))))
 
510
 
 
511
(defgeneric component-visited-p (operation component))
 
512
 
 
513
(defmethod component-visited-p ((o operation) (c component))
 
514
  (assoc (node-for o c)
 
515
         (operation-visited-nodes (operation-ancestor o))
 
516
         :test 'equal))
 
517
 
 
518
(defgeneric (setf visiting-component) (new-value operation component))
 
519
 
 
520
(defmethod (setf visiting-component) (new-value operation component)
 
521
  ;; MCL complains about unused lexical variables
 
522
  (declare (ignorable new-value operation component)))
 
523
 
 
524
(defmethod (setf visiting-component) (new-value (o operation) (c component))
 
525
  (let ((node (node-for o c))
 
526
        (a (operation-ancestor o)))
 
527
    (if new-value
 
528
        (pushnew node (operation-visiting-nodes a) :test 'equal)
 
529
        (setf (operation-visiting-nodes a)
 
530
              (remove node  (operation-visiting-nodes a) :test 'equal)))))
 
531
 
 
532
(defgeneric component-visiting-p (operation component))
 
533
 
 
534
(defmethod component-visiting-p ((o operation) (c component))
 
535
  (let ((node (cons o c)))
 
536
    (member node (operation-visiting-nodes (operation-ancestor o))
 
537
            :test 'equal)))
 
538
 
 
539
(defgeneric component-depends-on (operation component))
 
540
 
 
541
(defmethod component-depends-on ((o operation) (c component))
 
542
  (cdr (assoc (class-name (class-of o))
 
543
              (slot-value c 'in-order-to))))
 
544
 
 
545
(defgeneric component-self-dependencies (operation component))
 
546
 
 
547
(defmethod component-self-dependencies ((o operation) (c component))
 
548
  (let ((all-deps (component-depends-on o c)))
 
549
    (remove-if-not (lambda (x)
 
550
                     (member (component-name c) (cdr x) :test #'string=))
 
551
                   all-deps)))
 
552
    
 
553
(defmethod input-files ((operation operation) (c component))
 
554
  (let ((parent (component-parent c))
 
555
        (self-deps (component-self-dependencies operation c)))
 
556
    (if self-deps
 
557
        (mapcan (lambda (dep)
 
558
                  (destructuring-bind (op name) dep
 
559
                    (output-files (make-instance op)
 
560
                                  (find-component parent name))))
 
561
                self-deps)
 
562
        ;; no previous operations needed?  I guess we work with the 
 
563
        ;; original source file, then
 
564
        (list (component-pathname c)))))
 
565
 
 
566
(defmethod input-files ((operation operation) (c module)) nil)
 
567
 
 
568
(defmethod operation-done-p ((o operation) (c component))
 
569
  (let ((out-files (output-files o c))
 
570
        (in-files (input-files o c)))
 
571
    (cond ((and (not in-files) (not out-files))
 
572
           ;; arbitrary decision: an operation that uses nothing to
 
573
           ;; produce nothing probably isn't doing much 
 
574
           t)
 
575
          ((not out-files) 
 
576
           (let ((op-done
 
577
                  (gethash (type-of o)
 
578
                           (component-operation-times c))))
 
579
             (and op-done
 
580
                  (>= op-done
 
581
                      (or (apply #'max
 
582
                                 (mapcar #'file-write-date in-files)) 0)))))
 
583
          ((not in-files) nil)
 
584
          (t
 
585
           (and
 
586
            (every #'probe-file out-files)
 
587
            (> (apply #'min (mapcar #'file-write-date out-files))
 
588
               (apply #'max (mapcar #'file-write-date in-files)) ))))))
 
589
 
 
590
;;; So you look at this code and think "why isn't it a bunch of
 
591
;;; methods".  And the answer is, because standard method combination
 
592
;;; runs :before methods most->least-specific, which is back to front
 
593
;;; for our purposes.  And CLISP doesn't have non-standard method
 
594
;;; combinations, so let's keep it simple and aspire to portability
 
595
 
 
596
(defgeneric traverse (operation component))
 
597
(defmethod traverse ((operation operation) (c component))
 
598
  (let ((forced nil))
 
599
    (labels ((do-one-dep (required-op required-c required-v)
 
600
               (let* ((dep-c (or (find-component
 
601
                                  (component-parent c)
 
602
                                  ;; XXX tacky.  really we should build the
 
603
                                  ;; in-order-to slot with canonicalized
 
604
                                  ;; names instead of coercing this late
 
605
                                  (coerce-name required-c) required-v)
 
606
                                 (error 'missing-dependency :required-by c
 
607
                                        :version required-v
 
608
                                        :requires required-c)))
 
609
                      (op (make-sub-operation c operation dep-c required-op)))
 
610
                 (traverse op dep-c)))             
 
611
             (do-dep (op dep)
 
612
               (cond ((eq op 'feature)
 
613
                      (or (member (car dep) *features*)
 
614
                          (error 'missing-dependency :required-by c
 
615
                                 :requires (car dep) :version nil)))
 
616
                     (t
 
617
                      (dolist (d dep)
 
618
                        (cond ((consp d)
 
619
                               (assert (string-equal
 
620
                                        (symbol-name (first d))
 
621
                                        "VERSION"))
 
622
                               (appendf forced
 
623
                                        (do-one-dep op (second d) (third d))))
 
624
                              (t
 
625
                               (appendf forced (do-one-dep op d nil)))))))))
 
626
      (aif (component-visited-p operation c)
 
627
           (return-from traverse
 
628
             (if (cdr it) (list (cons 'pruned-op c)) nil)))
 
629
      ;; dependencies
 
630
      (if (component-visiting-p operation c)
 
631
          (error 'circular-dependency :components (list c)))
 
632
      (setf (visiting-component operation c) t)
 
633
      (loop for (required-op . deps) in (component-depends-on operation c)
 
634
            do (do-dep required-op deps))
 
635
      ;; constituent bits
 
636
      (let ((module-ops
 
637
             (when (typep c 'module)
 
638
               (let ((at-least-one nil)
 
639
                     (forced nil)
 
640
                     (error nil))
 
641
                 (loop for kid in (module-components c)
 
642
                       do (handler-case
 
643
                              (appendf forced (traverse operation kid ))
 
644
                            (missing-dependency (condition)
 
645
                              (if (eq (module-if-component-dep-fails c) :fail)
 
646
                                  (error condition))
 
647
                              (setf error condition))
 
648
                            (:no-error (c)
 
649
                              (declare (ignore c))
 
650
                              (setf at-least-one t))))
 
651
                 (when (and (eq (module-if-component-dep-fails c) :try-next)
 
652
                            (not at-least-one))
 
653
                   (error error))
 
654
                 forced))))
 
655
        ;; now the thing itself
 
656
        (when (or forced module-ops
 
657
                  (not (operation-done-p operation c))
 
658
                  (let ((f (operation-forced (operation-ancestor operation))))
 
659
                    (and f (or (not (consp f))
 
660
                               (member (component-name
 
661
                                        (operation-ancestor operation))
 
662
                                       (mapcar #'coerce-name f)
 
663
                                       :test #'string=)))))
 
664
          (let ((do-first (cdr (assoc (class-name (class-of operation))
 
665
                                      (slot-value c 'do-first)))))
 
666
            (loop for (required-op . deps) in do-first
 
667
                  do (do-dep required-op deps)))
 
668
          (setf forced (append (delete 'pruned-op forced :key #'car)
 
669
                               (delete 'pruned-op module-ops :key #'car)
 
670
                               (list (cons operation c))))))
 
671
      (setf (visiting-component operation c) nil)
 
672
      (visit-component operation c (and forced t))
 
673
      forced)))
 
674
  
 
675
 
 
676
(defmethod perform ((operation operation) (c source-file))
 
677
  (sysdef-error
 
678
   "~@<required method PERFORM not implemented ~
 
679
    for operation ~A, component ~A~@:>"
 
680
   (class-of operation) (class-of c)))
 
681
 
 
682
(defmethod perform ((operation operation) (c module))
 
683
  nil)
 
684
 
 
685
(defmethod explain ((operation operation) (component component))
 
686
  (format *verbose-out* "~&;;; ~A on ~A~%" operation component))
 
687
 
 
688
;;; compile-op
 
689
 
 
690
(defclass compile-op (operation)
 
691
  ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
 
692
   (system-p :initarg :system-p :accessor compile-op-system-p :initform nil)
 
693
   (on-warnings :initarg :on-warnings :accessor operation-on-warnings
 
694
                :initform *compile-file-warnings-behaviour*)
 
695
   (on-failure :initarg :on-failure :accessor operation-on-failure
 
696
               :initform *compile-file-failure-behaviour*)))
 
697
 
 
698
(defmethod perform :before ((operation compile-op) (c source-file))
 
699
  (map nil #'ensure-directories-exist (output-files operation c)))
 
700
 
 
701
(defmethod perform :after ((operation operation) (c component))
 
702
  (setf (gethash (type-of operation) (component-operation-times c))
 
703
        (get-universal-time)))
 
704
 
 
705
;;; perform is required to check output-files to find out where to put
 
706
;;; its answers, in case it has been overridden for site policy
 
707
(defmethod perform ((operation compile-op) (c cl-source-file))
 
708
  #-:broken-fasl-loader
 
709
  (let ((source-file (component-pathname c))
 
710
        (output-file (car (output-files operation c))))
 
711
    (multiple-value-bind (output warnings-p failure-p)
 
712
        (compile-file source-file
 
713
                      :output-file output-file
 
714
                      :system-p (compile-op-system-p operation))
 
715
      ;(declare (ignore output))
 
716
      (when warnings-p
 
717
        (case (operation-on-warnings operation)
 
718
          (:warn (warn
 
719
                  "~@<COMPILE-FILE warned while performing ~A on ~A.~@:>"
 
720
                  operation c))
 
721
          (:error (error 'compile-warned :component c :operation operation))
 
722
          (:ignore nil)))
 
723
      (when failure-p
 
724
        (case (operation-on-failure operation)
 
725
          (:warn (warn
 
726
                  "~@<COMPILE-FILE failed while performing ~A on ~A.~@:>"
 
727
                  operation c))
 
728
          (:error (error 'compile-failed :component c :operation operation))
 
729
          (:ignore nil)))
 
730
      (unless output
 
731
        (error 'compile-error :component c :operation operation)))))
 
732
 
 
733
(defmethod output-files ((operation compile-op) (c cl-source-file))
 
734
  #-:broken-fasl-loader (list (compile-file-pathname (component-pathname c)))
 
735
  #+:broken-fasl-loader (list (component-pathname c)))
 
736
 
 
737
(defmethod perform ((operation compile-op) (c static-file))
 
738
  nil)
 
739
 
 
740
(defmethod output-files ((operation compile-op) (c static-file))
 
741
  nil)
 
742
 
 
743
;;; load-op
 
744
 
 
745
(defclass load-op (operation) ())
 
746
 
 
747
(defmethod perform ((o load-op) (c cl-source-file))
 
748
  (mapcar #'load (input-files o c)))
 
749
 
 
750
(defmethod perform ((operation load-op) (c static-file))
 
751
  nil)
 
752
(defmethod operation-done-p ((operation load-op) (c static-file))
 
753
  t)
 
754
 
 
755
(defmethod output-files ((o operation) (c component))
 
756
  nil)
 
757
 
 
758
(defmethod component-depends-on ((operation load-op) (c component))
 
759
  (cons (list 'compile-op (component-name c))
 
760
        (call-next-method)))
 
761
 
 
762
;;; load-source-op
 
763
 
 
764
(defclass load-source-op (operation) ())
 
765
 
 
766
(defmethod perform ((o load-source-op) (c cl-source-file))
 
767
  (let ((source (component-pathname c)))
 
768
    (setf (component-property c 'last-loaded-as-source)
 
769
          (and (load source)
 
770
               (get-universal-time)))))
 
771
 
 
772
(defmethod perform ((operation load-source-op) (c static-file))
 
773
  nil)
 
774
 
 
775
(defmethod output-files ((operation load-source-op) (c component))
 
776
  nil)
 
777
 
 
778
;;; FIXME: we simply copy load-op's dependencies.  this is Just Not Right.
 
779
(defmethod component-depends-on ((o load-source-op) (c component))
 
780
  (let ((what-would-load-op-do (cdr (assoc 'load-op
 
781
                                           (slot-value c 'in-order-to)))))
 
782
    (mapcar (lambda (dep)
 
783
              (if (eq (car dep) 'load-op)
 
784
                  (cons 'load-source-op (cdr dep))
 
785
                  dep))
 
786
            what-would-load-op-do)))
 
787
 
 
788
(defmethod operation-done-p ((o load-source-op) (c source-file))
 
789
  (if (or (not (component-property c 'last-loaded-as-source))
 
790
          (> (file-write-date (component-pathname c))
 
791
             (component-property c 'last-loaded-as-source)))
 
792
      nil t))
 
793
 
 
794
(defclass test-op (operation) ())
 
795
 
 
796
(defmethod perform ((operation test-op) (c component))
 
797
  nil)
 
798
 
 
799
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
800
;;; invoking operations
 
801
 
 
802
(defun operate (operation-class system &rest args)
 
803
  (let* ((op (apply #'make-instance operation-class
 
804
                    :original-initargs args args))
 
805
         (*verbose-out*
 
806
          (if (getf args :verbose t)
 
807
              *trace-output*
 
808
              (make-broadcast-stream)))
 
809
         (system (if (typep system 'component) system (find-system system)))
 
810
         (steps (traverse op system)))
 
811
    (with-compilation-unit ()
 
812
      (loop for (op . component) in steps do
 
813
            (loop
 
814
             (restart-case 
 
815
                 (progn (perform op component)
 
816
                        (return))
 
817
               (retry ()
 
818
                 :report
 
819
                 (lambda (s)
 
820
                   (format s "~@<Retry performing ~S on ~S.~@:>"
 
821
                           op component)))
 
822
               (accept ()
 
823
                 :report
 
824
                 (lambda (s)
 
825
                   (format s
 
826
                           "~@<Continue, treating ~S on ~S as ~
 
827
                            having been successful.~@:>"
 
828
                           op component))
 
829
                 (setf (gethash (type-of op)
 
830
                                (component-operation-times component))
 
831
                       (get-universal-time))
 
832
                 (return))))))))
 
833
 
 
834
(defun oos (&rest args)
 
835
  "Alias of OPERATE function"
 
836
  (apply #'operate args))
 
837
 
 
838
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
839
;;; syntax
 
840
 
 
841
(defun remove-keyword (key arglist)
 
842
  (labels ((aux (key arglist)
 
843
             (cond ((null arglist) nil)
 
844
                   ((eq key (car arglist)) (cddr arglist))
 
845
                   (t (cons (car arglist) (cons (cadr arglist)
 
846
                                                (remove-keyword
 
847
                                                 key (cddr arglist))))))))
 
848
    (aux key arglist)))
 
849
 
 
850
(defmacro defsystem (name &body options)
 
851
  (destructuring-bind (&key pathname (class 'system) &allow-other-keys) options
 
852
    (let ((component-options (remove-keyword :class options)))
 
853
      `(progn
 
854
        ;; system must be registered before we parse the body, otherwise
 
855
        ;; we recur when trying to find an existing system of the same name
 
856
        ;; to reuse options (e.g. pathname) from
 
857
        (let ((s (system-registered-p ',name)))
 
858
          (cond ((and s (eq (type-of (cdr s)) ',class))
 
859
                 (setf (car s) (get-universal-time)))
 
860
                (s
 
861
                 #+clisp
 
862
                 (sysdef-error "Cannot redefine the existing system ~A with a different class" s)
 
863
                 #-clisp
 
864
                 (change-class (cdr s) ',class))
 
865
                (t
 
866
                 (register-system (quote ,name)
 
867
                                  (make-instance ',class :name ',name)))))
 
868
        (parse-component-form nil (apply
 
869
                                   #'list
 
870
                                   :module (coerce-name ',name)
 
871
                                   :pathname
 
872
                                   (or ,pathname
 
873
                                       (pathname-sans-name+type
 
874
                                        (resolve-symlinks  *load-truename*))
 
875
                                       *default-pathname-defaults*)
 
876
                                   ',component-options))))))
 
877
  
 
878
 
 
879
(defun class-for-type (parent type)
 
880
  (let ((class 
 
881
         (find-class
 
882
          (or (find-symbol (symbol-name type) *package*)
 
883
              (find-symbol (symbol-name type) #.(package-name *package*)))
 
884
          nil)))
 
885
    (or class
 
886
        (and (eq type :file)
 
887
             (or (module-default-component-class parent)
 
888
                 (find-class 'cl-source-file)))
 
889
        (sysdef-error "~@<don't recognize component type ~A~@:>" type))))
 
890
 
 
891
(defun maybe-add-tree (tree op1 op2 c)
 
892
  "Add the node C at /OP1/OP2 in TREE, unless it's there already.
 
893
Returns the new tree (which probably shares structure with the old one)"
 
894
  (let ((first-op-tree (assoc op1 tree)))
 
895
    (if first-op-tree
 
896
        (progn
 
897
          (aif (assoc op2 (cdr first-op-tree))
 
898
               (if (find c (cdr it))
 
899
                   nil
 
900
                   (setf (cdr it) (cons c (cdr it))))
 
901
               (setf (cdr first-op-tree)
 
902
                     (acons op2 (list c) (cdr first-op-tree))))
 
903
          tree)
 
904
        (acons op1 (list (list op2 c)) tree))))
 
905
                
 
906
(defun union-of-dependencies (&rest deps)
 
907
  (let ((new-tree nil))
 
908
    (dolist (dep deps)
 
909
      (dolist (op-tree dep)
 
910
        (dolist (op  (cdr op-tree))
 
911
          (dolist (c (cdr op))
 
912
            (setf new-tree
 
913
                  (maybe-add-tree new-tree (car op-tree) (car op) c))))))
 
914
    new-tree))
 
915
 
 
916
 
 
917
(defun remove-keys (key-names args)
 
918
  (loop for ( name val ) on args by #'cddr
 
919
        unless (member (symbol-name name) key-names 
 
920
                       :key #'symbol-name :test 'equal)
 
921
        append (list name val)))
 
922
 
 
923
(defvar *serial-depends-on*)
 
924
 
 
925
(defun parse-component-form (parent options)
 
926
  (destructuring-bind
 
927
        (type name &rest rest &key
 
928
              ;; the following list of keywords is reproduced below in the
 
929
              ;; remove-keys form.  important to keep them in sync
 
930
              components pathname default-component-class
 
931
              perform explain output-files operation-done-p
 
932
              depends-on serial in-order-to
 
933
              ;; list ends
 
934
              &allow-other-keys) options
 
935
    (check-component-input type name depends-on components in-order-to)
 
936
    (let* ((other-args (remove-keys
 
937
                        '(components pathname default-component-class
 
938
                          perform explain output-files operation-done-p
 
939
                          depends-on serial in-order-to)
 
940
                        rest))
 
941
           (ret
 
942
            (or (find-component parent name)
 
943
                (make-instance (class-for-type parent type)))))
 
944
      (when (boundp '*serial-depends-on*)
 
945
        (setf depends-on
 
946
              (concatenate 'list *serial-depends-on* depends-on)))
 
947
      (apply #'reinitialize-instance
 
948
             ret
 
949
             :name (coerce-name name)
 
950
             :pathname pathname
 
951
             :parent parent
 
952
             :original-depends-on depends-on
 
953
             other-args)
 
954
      (when (typep ret 'module)
 
955
        (setf (module-default-component-class ret)
 
956
              (or default-component-class
 
957
                  (and (typep parent 'module)
 
958
                       (module-default-component-class parent))))
 
959
        (let ((*serial-depends-on* nil))
 
960
          (setf (module-components ret)
 
961
                (loop for c-form in components
 
962
                      for c = (parse-component-form ret c-form)
 
963
                      collect c
 
964
                      if serial
 
965
                      do (push (component-name c) *serial-depends-on*)))))
 
966
      
 
967
      (setf (slot-value ret 'in-order-to)
 
968
            (union-of-dependencies
 
969
             in-order-to
 
970
             `((compile-op (compile-op ,@depends-on))
 
971
               (load-op (load-op ,@depends-on))))
 
972
            (slot-value ret 'do-first) `((compile-op (load-op ,@depends-on))))
 
973
      
 
974
      (loop for (n v) in `((perform ,perform) (explain ,explain)
 
975
                           (output-files ,output-files)
 
976
                           (operation-done-p ,operation-done-p))
 
977
            do (map 'nil
 
978
                    ;; this is inefficient as most of the stored
 
979
                    ;; methods will not be for this particular gf n
 
980
                    ;; But this is hardly performance-critical
 
981
                    (lambda (m) (remove-method (symbol-function n) m))
 
982
                    (component-inline-methods ret))
 
983
            when v
 
984
            do (destructuring-bind (op qual (o c) &body body) v
 
985
                 (pushnew
 
986
                  (eval `(defmethod ,n ,qual ((,o ,op) (,c (eql ,ret)))
 
987
                          ,@body))
 
988
                  (component-inline-methods ret))))
 
989
      ret)))
 
990
 
 
991
(defun check-component-input (type name depends-on components in-order-to)
 
992
  "A partial test of the values of a component."
 
993
  (unless (listp depends-on)
 
994
    (sysdef-error-component ":depends-on must be a list."
 
995
                            type name depends-on))
 
996
  (unless (listp components)
 
997
    (sysdef-error-component ":components must be NIL or a list of components."
 
998
                            type name components))
 
999
  (unless (and (listp in-order-to) (listp (car in-order-to)))
 
1000
    (sysdef-error-component ":in-order-to must be NIL or a list of components."
 
1001
                           type name in-order-to)))
 
1002
 
 
1003
(defun sysdef-error-component (msg type name value)
 
1004
  (sysdef-error (concatenate 'string msg
 
1005
                             "~&The value specified for ~(~A~) ~A is ~W")
 
1006
                type name value))
 
1007
 
 
1008
(defun resolve-symlinks (path)
 
1009
  #-allegro (truename path)
 
1010
  #+allegro (excl:pathname-resolve-symbolic-links path)
 
1011
  )
 
1012
 
 
1013
;;; optional extras
 
1014
 
 
1015
;;; run-shell-command functions for other lisp implementations will be
 
1016
;;; gratefully accepted, if they do the same thing.  If the docstring
 
1017
;;; is ambiguous, send a bug report
 
1018
 
 
1019
(defun run-shell-command (control-string &rest args)
 
1020
  "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
 
1021
synchronously execute the result using a Bourne-compatible shell, with
 
1022
output to *verbose-out*.  Returns the shell's exit code."
 
1023
  (let ((command (apply #'format nil control-string args)))
 
1024
    (format *verbose-out* "; $ ~A~%" command)
 
1025
    #+sbcl
 
1026
    (sb-impl::process-exit-code
 
1027
     (sb-ext:run-program  
 
1028
      "/bin/sh"
 
1029
      (list  "-c" command)
 
1030
      :input nil :output *verbose-out*))
 
1031
    
 
1032
    #+(or cmu scl)
 
1033
    (ext:process-exit-code
 
1034
     (ext:run-program  
 
1035
      "/bin/sh"
 
1036
      (list  "-c" command)
 
1037
      :input nil :output *verbose-out*))
 
1038
 
 
1039
    #+allegro
 
1040
    (excl:run-shell-command command :input nil :output *verbose-out*)
 
1041
    
 
1042
    #+lispworks
 
1043
    (system:call-system-showing-output
 
1044
     command
 
1045
     :shell-type "/bin/sh"
 
1046
     :output-stream *verbose-out*)
 
1047
    
 
1048
    #+clisp                             ;XXX not exactly *verbose-out*, I know
 
1049
    (ext:run-shell-command  command :output :terminal :wait t)
 
1050
 
 
1051
    #+openmcl
 
1052
    (nth-value 1
 
1053
               (ccl:external-process-status
 
1054
                (ccl:run-program "/bin/sh" (list "-c" command)
 
1055
                                 :input nil :output *verbose-out*
 
1056
                                 :wait t)))
 
1057
    #+ecl ;; courtesy of Juan Jose Garcia Ripoll
 
1058
    (si:system command)
 
1059
    #-(or openmcl clisp lispworks allegro scl cmu sbcl ecl)
 
1060
    (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
 
1061
    ))
 
1062
 
 
1063
 
 
1064
(defgeneric hyperdocumentation (package name doc-type))
 
1065
(defmethod hyperdocumentation ((package symbol) name doc-type)
 
1066
  (hyperdocumentation (find-package package) name doc-type))
 
1067
 
 
1068
(defun hyperdoc (name doc-type)
 
1069
  (hyperdocumentation (symbol-package name) name doc-type))
 
1070
 
 
1071
 
 
1072
(pushnew :asdf *features*)
 
1073
 
 
1074
#+sbcl
 
1075
(eval-when (:compile-toplevel :load-toplevel :execute)
 
1076
  (when (sb-ext:posix-getenv "SBCL_BUILDING_CONTRIB")
 
1077
    (pushnew :sbcl-hooks-require *features*)))
 
1078
 
 
1079
#+(and sbcl sbcl-hooks-require)
 
1080
(progn
 
1081
  (defun module-provide-asdf (name)
 
1082
    (handler-bind ((style-warning #'muffle-warning))
 
1083
      (let* ((*verbose-out* (make-broadcast-stream))
 
1084
             (system (asdf:find-system name nil)))
 
1085
        (when system
 
1086
          (asdf:operate 'asdf:load-op name)
 
1087
          t))))
 
1088
 
 
1089
  (pushnew
 
1090
   '(merge-pathnames "systems/"
 
1091
     (truename (sb-ext:posix-getenv "SBCL_HOME")))
 
1092
   *central-registry*)
 
1093
  
 
1094
  (pushnew
 
1095
   '(merge-pathnames "site-systems/"
 
1096
     (truename (sb-ext:posix-getenv "SBCL_HOME")))
 
1097
   *central-registry*)
 
1098
  
 
1099
  (pushnew
 
1100
   '(merge-pathnames ".sbcl/systems/"
 
1101
     (user-homedir-pathname))
 
1102
   *central-registry*)
 
1103
  
 
1104
  (pushnew 'module-provide-asdf sb-ext:*module-provider-functions*))
 
1105
 
 
1106
;; Hook into ECL's require/provide
 
1107
#+ecl
 
1108
(progn
 
1109
  (defun module-provide-asdf (name)
 
1110
    (handler-bind ((style-warning #'muffle-warning))
 
1111
      (let* ((*verbose-out* (make-broadcast-stream))
 
1112
             (system (asdf:find-system name nil)))
 
1113
        (when system
 
1114
          (asdf:operate 'asdf:load-op name)
 
1115
          t))))
 
1116
  #+win32 (push '("asd" . si::load-source) si::*load-hooks*)
 
1117
  (pushnew 'module-provide-asdf ext:*module-provider-functions*))
 
1118
 
 
1119
(provide 'asdf)