1 ;;; -*- mode: Common-Lisp; Base: 10 ; Syntax: ANSI-Common-Lisp ; coding: utf-8 -*-
2 ;;; This is ASDF 2.24: Another System Definition Facility.
4 ;;; Feedback, bug reports, and patches are all welcome:
5 ;;; please mail to <asdf-devel@common-lisp.net>.
6 ;;; Note first that the canonical source for ASDF is presently
7 ;;; <URL:http://common-lisp.net/project/asdf/>.
9 ;;; If you obtained this copy from anywhere else, and you experience
10 ;;; trouble using it, or find bugs, you may want to check at the
11 ;;; location above for a more recent version (and for documentation
12 ;;; and test files, if your copy came without them) before reporting
13 ;;; bugs. There are usually two "supported" revisions - the git master
14 ;;; branch is the latest development version, whereas the git release
15 ;;; branch may be slightly older but is considered `stable'
18 ;;; (This is the MIT / X Consortium license as taken from
19 ;;; http://www.opensource.org/licenses/mit-license.html on or about
20 ;;; Monday; July 13, 2009)
22 ;;; Copyright (c) 2001-2012 Daniel Barlow and contributors
24 ;;; Permission is hereby granted, free of charge, to any person obtaining
25 ;;; a copy of this software and associated documentation files (the
26 ;;; "Software"), to deal in the Software without restriction, including
27 ;;; without limitation the rights to use, copy, modify, merge, publish,
28 ;;; distribute, sublicense, and/or sell copies of the Software, and to
29 ;;; permit persons to whom the Software is furnished to do so, subject to
30 ;;; the following conditions:
32 ;;; The above copyright notice and this permission notice shall be
33 ;;; included in all copies or substantial portions of the Software.
35 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39 ;;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
40 ;;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41 ;;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 ;;; The problem with writing a defsystem replacement is bootstrapping:
46 ;;; we can't use defsystem to compile it. Hence, all in one file.
50 (cl:in-package :common-lisp-user)
51 #+genera (in-package :future-common-lisp-user)
53 #-(or abcl allegro clisp clozure cmu cormanlisp ecl gcl genera lispworks mcl mkcl sbcl scl xcl)
54 (error "ASDF is not supported on your implementation. Please help us port it.")
56 ;;;; Create and setup packages in a way that is compatible with hot-upgrade.
57 ;;;; See https://bugs.launchpad.net/asdf/+bug/485687
58 ;;;; See these two eval-when forms, and more near the end of the file.
60 #+gcl (defpackage :asdf (:use :cl)) ;; GCL treats defpackage magically and needs this
62 (eval-when (:load-toplevel :compile-toplevel :execute)
63 ;;; Before we do anything, some implementation-dependent tweaks
64 ;; (declaim (optimize (speed 1) (debug 3) (safety 3))) ; NO: trust implementation defaults.
66 (setf excl::*autoload-package-name-alist*
67 (remove "asdf" excl::*autoload-package-name-alist*
68 :test 'equalp :key 'car)) ; need that BEFORE any mention of package ASDF as below
69 #+gcl ;; Debian's GCL 2.7 has bugs with compiling multiple-value stuff, but can run ASDF 2.011
70 (when (or (< system::*gcl-major-version* 2) ;; GCL 2.6 fails to fully compile ASDF at all
71 (and (= system::*gcl-major-version* 2)
72 (< system::*gcl-minor-version* 7)))
73 (pushnew :gcl-pre2.7 *features*))
74 #+(or abcl (and allegro ics) (and (or clisp cmu ecl mkcl) unicode)
75 clozure lispworks (and sbcl sb-unicode) scl)
76 (pushnew :asdf-unicode *features*)
77 ;;; make package if it doesn't exist yet.
78 ;;; DEFPACKAGE may cause errors on discrepancies, so we avoid it.
79 (unless (find-package :asdf)
80 (make-package :asdf :use '(:common-lisp))))
84 (eval-when (:load-toplevel :compile-toplevel :execute)
85 ;;; This would belong amongst implementation-dependent tweaks above,
86 ;;; except that the defun has to be in package asdf.
87 #+ecl (defun use-ecl-byte-compiler-p () (and (member :ecl-bytecmp *features*) t))
88 #+ecl (unless (use-ecl-byte-compiler-p) (require :cmp))
90 #+mkcl (setq clos::*redefine-class-in-place* t) ;; Make sure we have strict ANSI class redefinition semantics
92 ;;; Package setup, step 2.
93 (defvar *asdf-version* nil)
94 (defvar *upgraded-p* nil)
95 (defvar *asdf-verbose* nil) ; was t from 2.000 to 2.014.12.
96 (defun find-symbol* (s p)
97 (find-symbol (string s) p))
98 ;; Strip out formatting that is not supported on Genera.
99 ;; Has to be inside the eval-when to make Lispworks happy (!)
100 (defun strcat (&rest strings)
101 (apply 'concatenate 'string strings))
102 (defmacro compatfmt (format)
103 #-(or gcl genera) format
105 (loop :for (unsupported . replacement) :in
108 #+genera '(("~@<" . "") ("; ~@;" . "; ") ("~@:>" . "") ("~:>" . ""))) :do
109 (loop :for found = (search unsupported format) :while found :do
110 (setf format (strcat (subseq format 0 found) replacement
111 (subseq format (+ found (length unsupported)))))))
113 (let* (;; For bug reporting sanity, please always bump this version when you modify this file.
114 ;; Please also modify asdf.asd to reflect this change. The script bin/bump-version
115 ;; can help you do these changes in synch (look at the source for documentation).
116 ;; Relying on its automation, the version is now redundantly present on top of this file.
117 ;; "2.345" would be an official release
118 ;; "2.345.6" would be a development version in the official upstream
119 ;; "2.345.0.7" would be your seventh local modification of official release 2.345
120 ;; "2.345.6.7" would be your seventh local modification of development version 2.345.6
121 (asdf-version "2.24")
122 (existing-asdf (find-class 'component nil))
123 (existing-version *asdf-version*)
124 (already-there (equal asdf-version existing-version)))
125 (unless (and existing-asdf already-there)
126 (when (and existing-asdf *asdf-verbose*)
127 (format *trace-output*
128 (compatfmt "~&~@<; ~@;Upgrading ASDF ~@[from version ~A ~]to version ~A~@:>~%")
129 existing-version asdf-version))
131 ((present-symbol-p (symbol package)
132 (member (nth-value 1 (find-symbol* symbol package)) '(:internal :external)))
133 (present-symbols (package)
134 ;; #-genera (loop :for s :being :the :present-symbols :in package :collect s) #+genera
136 (do-symbols (s package)
137 (when (present-symbol-p s package) (push s l)))
139 (unlink-package (package)
140 (let ((u (find-package package)))
142 (ensure-unintern u (present-symbols u))
143 (loop :for p :in (package-used-by-list u) :do
145 (delete-package u))))
146 (ensure-exists (name nicknames use)
149 (mapcar #'find-package (cons name nicknames))
151 ;; do away with packages with conflicting (nick)names
152 (map () #'unlink-package (cdr previous))
153 ;; reuse previous package with same name
154 (let ((p (car previous)))
157 (rename-package p name nicknames)
161 (make-package name :nicknames nicknames :use use))))))
162 (intern* (symbol package)
163 (intern (string symbol) package))
164 (remove-symbol (symbol package)
165 (let ((sym (find-symbol* symbol package)))
167 #-cormanlisp (unexport sym package)
168 (unintern sym package)
170 (ensure-unintern (package symbols)
171 (loop :with packages = (list-all-packages)
173 :for removed = (remove-symbol sym package)
175 (loop :for p :in packages :do
176 (when (eq removed (find-symbol* sym p))
177 (unintern removed p)))))
178 (ensure-shadow (package symbols)
179 (shadow symbols package))
180 (ensure-use (package use)
181 (dolist (used (package-use-list package))
182 (unless (member (package-name used) use :test 'string=)
184 (do-external-symbols (sym used)
185 (when (eq sym (find-symbol* sym package))
186 (remove-symbol sym package)))))
187 (dolist (used (reverse use))
188 (do-external-symbols (sym used)
189 (unless (eq sym (find-symbol* sym package))
190 (remove-symbol sym package)))
191 (use-package used package)))
192 (ensure-fmakunbound (package symbols)
193 (loop :for name :in symbols
194 :for sym = (find-symbol* name package)
195 :when sym :do (fmakunbound sym)))
196 (ensure-export (package export)
197 (let ((formerly-exported-symbols nil)
198 (bothly-exported-symbols nil)
199 (newly-exported-symbols nil))
200 (do-external-symbols (sym package)
201 (if (member sym export :test 'string-equal)
202 (push sym bothly-exported-symbols)
203 (push sym formerly-exported-symbols)))
204 (loop :for sym :in export :do
205 (unless (member sym bothly-exported-symbols :test 'equal)
206 (push sym newly-exported-symbols)))
207 (loop :for user :in (package-used-by-list package)
208 :for shadowing = (package-shadowing-symbols user) :do
209 (loop :for new :in newly-exported-symbols
210 :for old = (find-symbol* new user)
211 :when (and old (not (member old shadowing)))
212 :do (unintern old user)))
213 (loop :for x :in newly-exported-symbols :do
214 (export (intern* x package)))))
215 (ensure-package (name &key nicknames use unintern
216 shadow export redefined-functions)
217 (let* ((p (ensure-exists name nicknames use)))
218 (ensure-unintern p (append unintern #+cmu redefined-functions))
219 (ensure-shadow p shadow)
220 (ensure-export p export)
221 #-cmu (ensure-fmakunbound p redefined-functions)
224 ((pkgdcl (name &key nicknames use export
225 redefined-functions unintern shadow)
227 ',name :nicknames ',nicknames :use ',use :export ',export
230 :redefined-functions ',redefined-functions)))
233 :nicknames (:asdf-utilities) ;; DEPRECATED! Do not use, for backward compatibility only.
236 (#:perform #:explain #:output-files #:operation-done-p
237 #:perform-with-restarts #:component-relative-pathname
238 #:system-source-file #:operate #:find-component #:find-system
239 #:apply-output-translations #:translate-pathname* #:resolve-location
240 #:system-relative-pathname
241 #:inherit-source-registry #:process-source-registry
242 #:process-source-registry-directive
243 #:compile-file* #:source-file-type)
245 (#:*asdf-revision* #:around #:asdf-method-combination
246 #:split #:make-collector #:do-dep #:do-one-dep
247 #:resolve-relative-location-component #:resolve-absolute-location-component
248 #:output-files-for-system-and-operation) ; obsolete ASDF-BINARY-LOCATION function
250 (#:defsystem #:oos #:operate #:find-system #:locate-system #:run-shell-command
251 #:system-definition-pathname #:with-system-definitions
252 #:search-for-system-definition #:find-component #:component-find-path
253 #:compile-system #:load-system #:load-systems
254 #:require-system #:test-system #:clear-system
255 #:operation #:compile-op #:load-op #:load-source-op #:test-op
256 #:feature #:version #:version-satisfies
258 #:implementation-identifier #:implementation-type #:hostname
259 #:input-files #:output-files #:output-file #:perform
260 #:operation-done-p #:explain
262 #:component #:source-file
263 #:c-source-file #:cl-source-file #:java-source-file
264 #:cl-source-file.cl #:cl-source-file.lsp
270 #:module ; components
274 #:module-components ; component accessors
275 #:module-components-by-name
277 #:component-relative-pathname
283 #:component-depends-on
285 #:component-external-format
288 #:system-long-description
294 #:system-source-directory
295 #:system-relative-pathname
298 #:operation-description
299 #:operation-on-warnings
300 #:operation-on-failure
301 #:component-visited-p
303 #:*system-definition-search-functions* ; variables
305 #:*compile-file-warnings-behaviour*
306 #:*compile-file-failure-behaviour*
308 #:*load-system-operation*
314 #:operation-error #:compile-failed #:compile-warned #:compile-error
317 #:load-system-definition-error
318 #:error-component #:error-operation
319 #:system-definition-error
321 #:missing-component-of-version
323 #:missing-dependency-of-version
324 #:circular-dependency ; errors
330 #:coerce-entry-to-directory
331 #:remove-entry-from-registry
333 #:*encoding-detection-hook*
334 #:*encoding-external-format-hook*
336 #:*utf-8-external-format*
338 #:clear-configuration
339 #:*output-translations-parameter*
340 #:initialize-output-translations
341 #:disable-output-translations
342 #:clear-output-translations
343 #:ensure-output-translations
344 #:apply-output-translations
346 #:compile-file-pathname*
347 #:enable-asdf-binary-locations-compatibility
348 #:*default-source-registries*
349 #:*source-registry-parameter*
350 #:initialize-source-registry
351 #:compute-source-registry
352 #:clear-source-registry
353 #:ensure-source-registry
354 #:process-source-registry
355 #:system-registered-p #:registered-systems #:loaded-systems
358 #:user-output-translations-pathname
359 #:system-output-translations-pathname
360 #:user-output-translations-directory-pathname
361 #:system-output-translations-directory-pathname
362 #:user-source-registry
363 #:system-source-registry
364 #:user-source-registry-directory
365 #:system-source-registry-directory
371 #:remove-keys #:remove-keyword
372 #:first-char #:last-char #:string-suffix-p
374 #:directory-pathname-p #:ensure-directory-pathname
375 #:absolute-pathname-p #:ensure-pathname-absolute #:pathname-root
376 #:getenv #:getenv-pathname #:getenv-pathnames
377 #:getenv-absolute-directory #:getenv-absolute-directories
379 #:find-symbol* #:strcat
380 #:make-pathname-component-logical #:make-pathname-logical
381 #:merge-pathnames* #:coerce-pathname #:subpathname #:subpathname*
382 #:pathname-directory-pathname #:pathname-parent-directory-pathname
384 #:resolve-symlinks #:truenamize
386 #:component-name-to-pathname-components
388 #:subdirectories #:directory-files
390 #:*wild* #:*wild-file* #:*wild-directory* #:*wild-inferiors*
391 #:*wild-path* #:wilden
392 #:directorize-pathname-host-device
394 #+genera (import 'scl:boolean :asdf)
395 (setf *asdf-version* asdf-version
396 *upgraded-p* (if existing-version
397 (cons existing-version *upgraded-p*)
400 ;;;; -------------------------------------------------------------------------
401 ;;;; User-visible parameters
403 (defvar *resolve-symlinks* t
404 "Determine whether or not ASDF resolves symlinks when defining systems.
408 (defvar *compile-file-warnings-behaviour*
409 (or #+clisp :ignore :warn)
410 "How should ASDF react if it encounters a warning when compiling a file?
411 Valid values are :error, :warn, and :ignore.")
413 (defvar *compile-file-failure-behaviour*
414 (or #+sbcl :error #+clisp :ignore :warn)
415 "How should ASDF react if it encounters a failure (per the ANSI spec of COMPILE-FILE)
416 when compiling a file? Valid values are :error, :warn, and :ignore.
417 Note that ASDF ALWAYS raises an error if it fails to create an output file when compiling.")
419 (defvar *verbose-out* nil)
421 (defparameter +asdf-methods+
422 '(perform-with-restarts perform explain output-files operation-done-p))
424 (defvar *load-system-operation* 'load-op
425 "Operation used by ASDF:LOAD-SYSTEM. By default, ASDF:LOAD-OP.
426 You may override it with e.g. ASDF:LOAD-FASL-OP from asdf-bundle,
427 or ASDF:LOAD-SOURCE-OP if your fasl loading is somehow broken.")
429 (defvar *compile-op-compile-file-function* 'compile-file*
430 "Function used to compile lisp files.")
435 (eval-when (:compile-toplevel :execute)
436 (defparameter *acl-warn-save*
437 (when (boundp 'excl:*warn-on-nested-reader-conditionals*)
438 excl:*warn-on-nested-reader-conditionals*))
439 (when (boundp 'excl:*warn-on-nested-reader-conditionals*)
440 (setf excl:*warn-on-nested-reader-conditionals* nil)))
442 ;;;; -------------------------------------------------------------------------
443 ;;;; Resolve forward references
445 (declaim (ftype (function (t) t)
446 format-arguments format-control
447 error-name error-pathname error-condition
449 error-component error-operation
450 module-components module-components-by-name
451 circular-dependency-components
452 condition-arguments condition-form
453 condition-format condition-location
455 (ftype (function (&optional t) (values)) initialize-source-registry)
456 #-(or cormanlisp gcl-pre2.7)
457 (ftype (function (t t) t) (setf module-components-by-name)))
459 ;;;; -------------------------------------------------------------------------
460 ;;;; Compatibility various implementations
463 (deftype logical-pathname () nil)
464 (defun make-broadcast-stream () *error-output*)
465 (defun file-namestring (p)
466 (setf p (pathname p))
467 (format nil "~@[~A~]~@[.~A~]" (pathname-name p) (pathname-type p))))
469 #.(or #+mcl ;; the #$ doesn't work on other lisps, even protected by #+mcl
471 "(eval-when (:compile-toplevel :load-toplevel :execute)
472 (ccl:define-entry-point (_getenv \"getenv\") ((name :string)) :string)
473 (ccl:define-entry-point (_system \"system\") ((name :string)) :int)
474 ;; Note: ASDF may expect user-homedir-pathname to provide
475 ;; the pathname of the current user's home directory, whereas
476 ;; MCL by default provides the directory from which MCL was started.
477 ;; See http://code.google.com/p/mcl/wiki/Portability
478 (defun current-user-homedir-pathname ()
479 (ccl::findfolder #$kuserdomain #$kCurrentUserFolderType))
480 (defun probe-posix (posix-namestring)
481 \"If a file exists for the posix namestring, return the pathname\"
482 (ccl::with-cstrs ((cpath posix-namestring))
483 (ccl::rlet ((is-dir :boolean)
485 (when (eq #$noerr (#_fspathmakeref cpath fsref is-dir))
486 (ccl::%path-from-fsref fsref is-dir))))))"))
488 ;;;; -------------------------------------------------------------------------
489 ;;;; General Purpose Utilities
493 `(defmacro ,def* (name formals &rest rest)
495 #+(or ecl (and gcl (not gcl-pre2.7))) (fmakunbound ',name)
496 #-gcl ; gcl 2.7.0 notinline functions lose secondary return values :-(
497 ,(when (and #+ecl (symbolp name)) ; fails for setf functions on ecl
498 `(declaim (notinline ,name)))
499 (,',def ,name ,formals ,@rest)))))
500 (defdef defgeneric* defgeneric)
501 (defdef defun* defun))
503 (defmacro while-collecting ((&rest collectors) &body body)
504 "COLLECTORS should be a list of names for collections. A collector
505 defines a function that, when applied to an argument inside BODY, will
506 add its argument to the corresponding collection. Returns multiple values,
507 a list for each collection, in order.
509 \(while-collecting \(foo bar\)
510 \(dolist \(x '\(\(a 1\) \(b 2\) \(c 3\)\)\)
512 \(bar \(second x\)\)\)\)
513 Returns two values: \(A B C\) and \(1 2 3\)."
514 (let ((vars (mapcar #'(lambda (x) (gensym (symbol-name x))) collectors))
515 (initial-values (mapcar (constantly nil) collectors)))
516 `(let ,(mapcar #'list vars initial-values)
517 (flet ,(mapcar #'(lambda (c v) `(,c (x) (push x ,v) (values))) collectors vars)
519 (values ,@(mapcar #'(lambda (v) `(reverse ,v)) vars))))))
521 (defmacro aif (test then &optional else)
522 "Anaphoric version of IF, On Lisp style"
523 `(let ((it ,test)) (if it ,then ,else)))
525 (defun* pathname-directory-pathname (pathname)
526 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
527 and NIL NAME, TYPE and VERSION components"
529 (make-pathname :name nil :type nil :version nil :defaults pathname)))
531 (defun* normalize-pathname-directory-component (directory)
532 "Given a pathname directory component, return an equivalent form that is a list"
534 #-(or cmu sbcl scl) ;; these implementations already normalize directory components.
535 ((stringp directory) `(:absolute ,directory) directory)
537 ((and (consp directory) (stringp (first directory)))
538 `(:absolute ,@directory))
539 ((or (null directory)
540 (and (consp directory) (member (first directory) '(:absolute :relative))))
543 (error (compatfmt "~@<Unrecognized pathname directory component ~S~@:>") directory))))
545 (defun* merge-pathname-directory-components (specified defaults)
546 ;; Helper for merge-pathnames* that handles directory components.
547 (let ((directory (normalize-pathname-directory-component specified)))
548 (ecase (first directory)
550 (:absolute specified)
552 (let ((defdir (normalize-pathname-directory-component defaults))
553 (reldir (cdr directory)))
557 ((not (eq :back (first reldir)))
558 (append defdir reldir))
560 (loop :with defabs = (first defdir)
561 :with defrev = (reverse (rest defdir))
562 :while (and (eq :back (car reldir))
563 (or (and (eq :absolute defabs) (null defrev))
564 (stringp (car defrev))))
565 :do (pop reldir) (pop defrev)
566 :finally (return (cons defabs (append (reverse defrev) reldir)))))))))))
568 (defun* make-pathname-component-logical (x)
569 "Make a pathname component suitable for use in a logical-pathname"
571 ((eql :unspecific) nil)
572 #+clisp (string (string-upcase x))
573 #+clisp (cons (mapcar 'make-pathname-component-logical x))
576 (defun* make-pathname-logical (pathname host)
577 "Take a PATHNAME's directory, name, type and version components,
578 and make a new pathname with corresponding components and specified logical HOST"
581 :directory (make-pathname-component-logical (pathname-directory pathname))
582 :name (make-pathname-component-logical (pathname-name pathname))
583 :type (make-pathname-component-logical (pathname-type pathname))
584 :version (make-pathname-component-logical (pathname-version pathname))))
586 (defun* merge-pathnames* (specified &optional (defaults *default-pathname-defaults*))
587 "MERGE-PATHNAMES* is like MERGE-PATHNAMES except that
588 if the SPECIFIED pathname does not have an absolute directory,
589 then the HOST and DEVICE both come from the DEFAULTS, whereas
590 if the SPECIFIED pathname does have an absolute directory,
591 then the HOST and DEVICE both come from the SPECIFIED.
592 Also, if either argument is NIL, then the other argument is returned unmodified."
593 (when (null specified) (return-from merge-pathnames* defaults))
594 (when (null defaults) (return-from merge-pathnames* specified))
596 (ext:resolve-pathname specified defaults)
598 (let* ((specified (pathname specified))
599 (defaults (pathname defaults))
600 (directory (normalize-pathname-directory-component (pathname-directory specified)))
601 (name (or (pathname-name specified) (pathname-name defaults)))
602 (type (or (pathname-type specified) (pathname-type defaults)))
603 (version (or (pathname-version specified) (pathname-version defaults))))
604 (labels ((unspecific-handler (p)
605 (if (typep p 'logical-pathname) #'make-pathname-component-logical #'identity)))
606 (multiple-value-bind (host device directory unspecific-handler)
607 (ecase (first directory)
609 (values (pathname-host specified)
610 (pathname-device specified)
612 (unspecific-handler specified)))
614 (values (pathname-host defaults)
615 (pathname-device defaults)
616 (merge-pathname-directory-components directory (pathname-directory defaults))
617 (unspecific-handler defaults))))
618 (make-pathname :host host :device device :directory directory
619 :name (funcall unspecific-handler name)
620 :type (funcall unspecific-handler type)
621 :version (funcall unspecific-handler version))))))
623 (defun* pathname-parent-directory-pathname (pathname)
624 "Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
625 and NIL NAME, TYPE and VERSION components"
627 (make-pathname :name nil :type nil :version nil
628 :directory (merge-pathname-directory-components
629 '(:relative :back) (pathname-directory pathname))
630 :defaults pathname)))
632 (define-modify-macro appendf (&rest args)
633 append "Append onto list") ;; only to be used on short lists.
635 (define-modify-macro orf (&rest args)
638 (defun* first-char (s)
639 (and (stringp s) (plusp (length s)) (char s 0)))
641 (defun* last-char (s)
642 (and (stringp s) (plusp (length s)) (char s (1- (length s)))))
645 (defun* asdf-message (format-string &rest format-args)
646 (declare (dynamic-extent format-args))
647 (apply 'format *verbose-out* format-string format-args))
649 (defun* split-string (string &key max (separator '(#\Space #\Tab)))
650 "Split STRING into a list of components separated by
651 any of the characters in the sequence SEPARATOR.
652 If MAX is specified, then no more than max(1,MAX) components will be returned,
653 starting the separation from the end, e.g. when called with arguments
654 \"a.b.c.d.e\" :max 3 :separator \".\" it will return (\"a.b.c\" \"d\" \"e\")."
656 (let ((list nil) (words 0) (end (length string)))
657 (flet ((separatorp (char) (find char separator))
658 (done () (throw nil (cons (subseq string 0 end) list))))
660 :for start = (if (and max (>= words (1- max)))
662 (position-if #'separatorp string :end end :from-end t)) :do
665 (push (subseq string (1+ start) end) list)
667 (setf end start))))))
669 (defun* split-name-type (filename)
671 ;; Giving :unspecific as argument to make-pathname is not portable.
672 ;; See CLHS make-pathname and 19.2.2.2.3.
673 ;; We only use it on implementations that support it,
674 #+(or abcl allegro clozure cmu gcl genera lispworks mkcl sbcl scl xcl) :unspecific
675 #+(or clisp ecl #|These haven't been tested:|# cormanlisp mcl) nil))
676 (destructuring-bind (name &optional (type unspecific))
677 (split-string filename :max 2 :separator ".")
679 (values filename unspecific)
680 (values name type)))))
682 (defun* component-name-to-pathname-components (s &key force-directory force-relative)
683 "Splits the path string S, returning three values:
684 A flag that is either :absolute or :relative, indicating
685 how the rest of the values are to be interpreted.
686 A directory path --- a list of strings, suitable for
687 use with MAKE-PATHNAME when prepended with the flag
689 A filename with type extension, possibly NIL in the
690 case of a directory pathname.
691 FORCE-DIRECTORY forces S to be interpreted as a directory
692 pathname \(third return value will be NIL, final component
693 of S will be treated as part of the directory path.
695 The intention of this function is to support structured component names,
696 e.g., \(:file \"foo/bar\"\), which will be unpacked to relative
698 (check-type s string)
700 (error (compatfmt "~@<A portable ASDF pathname designator cannot include a #\: character: ~3i~_~S~@:>") s))
701 (let* ((components (split-string s :separator "/"))
702 (last-comp (car (last components))))
703 (multiple-value-bind (relative components)
704 (if (equal (first components) "")
705 (if (equal (first-char s) #\/)
708 (error (compatfmt "~@<Absolute pathname designator not allowed: ~3i~_~S~@:>") s))
709 (values :absolute (cdr components)))
710 (values :relative nil))
711 (values :relative components))
712 (setf components (remove-if #'(lambda (x) (member x '("" ".") :test #'equal)) components))
713 (setf components (substitute :back ".." components :test #'equal))
715 ((equal last-comp "")
716 (values relative components nil)) ; "" already removed
718 (values relative components nil))
720 (values relative (butlast components) last-comp))))))
722 (defun* remove-keys (key-names args)
723 (loop :for (name val) :on args :by #'cddr
724 :unless (member (symbol-name name) key-names
725 :key #'symbol-name :test 'equal)
726 :append (list name val)))
728 (defun* remove-keyword (key args)
729 (loop :for (k v) :on args :by #'cddr
734 (declare (ignorable x))
735 #+(or abcl clisp ecl xcl) (ext:getenv x)
736 #+allegro (sys:getenv x)
737 #+clozure (ccl:getenv x)
738 #+(or cmu scl) (cdr (assoc x ext:*environment-list* :test #'string=))
740 (let* ((buffer (ct:malloc 1))
741 (cname (ct:lisp-string-to-c-string x))
742 (needed-size (win:getenvironmentvariable cname buffer 0))
743 (buffer1 (ct:malloc (1+ needed-size))))
744 (prog1 (if (zerop (win:getenvironmentvariable cname buffer1 needed-size))
746 (ct:c-string-to-lisp-string buffer1))
749 #+gcl (system:getenv x)
751 #+lispworks (lispworks:environment-variable x)
752 #+mcl (ccl:with-cstrs ((name x))
753 (let ((value (_getenv name)))
754 (unless (ccl:%null-ptr-p value)
755 (ccl:%get-cstring value))))
756 #+mkcl (#.(or (find-symbol* 'getenv :si) (find-symbol* 'getenv :mk-ext)) x)
757 #+sbcl (sb-ext:posix-getenv x)
758 #-(or abcl allegro clisp clozure cmu cormanlisp ecl gcl genera lispworks mcl mkcl sbcl scl xcl)
759 (error "~S is not supported on your implementation" 'getenv))
761 (defun* directory-pathname-p (pathname)
762 "Does PATHNAME represent a directory?
764 A directory-pathname is a pathname _without_ a filename. The three
765 ways that the filename components can be missing are for it to be NIL,
766 :UNSPECIFIC or the empty string.
768 Note that this does _not_ check to see that PATHNAME points to an
769 actually-existing directory."
771 (let ((pathname (pathname pathname)))
772 (flet ((check-one (x)
773 (member x '(nil :unspecific "") :test 'equal)))
774 (and (not (wild-pathname-p pathname))
775 (check-one (pathname-name pathname))
776 (check-one (pathname-type pathname))
779 (defun* ensure-directory-pathname (pathspec)
780 "Converts the non-wild pathname designator PATHSPEC to directory form."
783 (ensure-directory-pathname (pathname pathspec)))
784 ((not (pathnamep pathspec))
785 (error (compatfmt "~@<Invalid pathname designator ~S~@:>") pathspec))
786 ((wild-pathname-p pathspec)
787 (error (compatfmt "~@<Can't reliably convert wild pathname ~3i~_~S~@:>") pathspec))
788 ((directory-pathname-p pathspec)
791 (make-pathname :directory (append (or (pathname-directory pathspec)
793 (list (file-namestring pathspec)))
794 :name nil :type nil :version nil
795 :defaults pathspec))))
798 (unless (fboundp 'ensure-directories-exist)
799 (defun* ensure-directories-exist (path)
800 (fs:create-directories-recursively (pathname path))))
802 (defun* absolute-pathname-p (pathspec)
803 (and (typep pathspec '(or pathname string))
804 (eq :absolute (car (pathname-directory (pathname pathspec))))))
806 (defun* coerce-pathname (name &key type defaults)
807 "coerce NAME into a PATHNAME.
808 When given a string, portably decompose it into a relative pathname:
809 #\\/ separates subdirectories. The last #\\/-separated string is as follows:
810 if TYPE is NIL, its last #\\. if any separates name and type from from type;
811 if TYPE is a string, it is the type, and the whole string is the name;
812 if TYPE is :DIRECTORY, the string is a directory component;
813 if the string is empty, it's a directory.
814 Any directory named .. is read as :BACK.
815 Host, device and version components are taken from DEFAULTS."
816 ;; The defaults are required notably because they provide the default host
817 ;; to the below make-pathname, which may crucially matter to people using
818 ;; merge-pathnames with non-default hosts, e.g. for logical-pathnames.
819 ;; NOTE that the host and device slots will be taken from the defaults,
820 ;; but that should only matter if you later merge relative pathnames with
821 ;; CL:MERGE-PATHNAMES instead of ASDF:MERGE-PATHNAMES*
826 (coerce-pathname (string-downcase name) :type type :defaults defaults))
828 (multiple-value-bind (relative path filename)
829 (component-name-to-pathname-components name :force-directory (eq type :directory)
831 (multiple-value-bind (name type)
833 ((or (eq type :directory) (null filename))
836 (values filename type))
838 (split-name-type filename)))
839 (apply 'make-pathname :directory (cons relative path) :name name :type type
840 (when defaults `(:defaults ,defaults))))))))
842 (defun* merge-component-name-type (name &key type defaults)
843 ;; For backwards compatibility only, for people using internals.
844 ;; Will be removed in a future release, e.g. 2.016.
845 (warn "Please don't use ASDF::MERGE-COMPONENT-NAME-TYPE. Use ASDF:COERCE-PATHNAME.")
846 (coerce-pathname name :type type :defaults defaults))
848 (defun* subpathname (pathname subpath &key type)
849 (and pathname (merge-pathnames* (coerce-pathname subpath :type type)
850 (pathname-directory-pathname pathname))))
852 (defun subpathname* (pathname subpath &key type)
854 (subpathname (ensure-directory-pathname pathname) subpath :type type)))
856 (defun* length=n-p (x n) ;is it that (= (length x) n) ?
857 (check-type n (integer 0 *))
859 :for l = x :then (cdr l)
860 :for i :downfrom n :do
862 ((zerop i) (return (null l)))
863 ((not (consp l)) (return nil)))))
865 (defun* string-suffix-p (s suffix)
866 (check-type s string)
867 (check-type suffix string)
868 (let ((start (- (length s) (length suffix))))
870 (string-equal s suffix :start1 start))))
872 (defun* read-file-forms (file)
873 (with-open-file (in file)
874 (loop :with eof = (list nil)
875 :for form = (read in nil eof)
879 (defun* pathname-root (pathname)
880 (make-pathname :directory '(:absolute)
881 :name nil :type nil :version nil
882 :defaults pathname ;; host device, and on scl, *some*
883 ;; scheme-specific parts: port username password, not others:
884 . #.(or #+scl '(:parameters nil :query nil :fragment nil))))
886 (defun* probe-file* (p)
887 "when given a pathname P, probes the filesystem for a file or directory
888 with given pathname and if it exists return its truename."
891 (string (probe-file* (parse-namestring p)))
892 (pathname (unless (wild-pathname-p p)
893 #.(or #+(or allegro clozure cmu cormanlisp ecl lispworks mkcl sbcl scl)
895 #+clisp (aif (find-symbol* '#:probe-pathname :ext)
896 `(ignore-errors (,it p)))
897 '(ignore-errors (truename p)))))))
899 (defun* truenamize (pathname &optional (defaults *default-pathname-defaults*))
900 "Resolve as much of a pathname as possible"
902 (when (typep pathname '(or null logical-pathname)) (return pathname))
903 (let ((p (merge-pathnames* pathname defaults)))
904 (when (typep p 'logical-pathname) (return p))
905 (let ((found (probe-file* p)))
906 (when found (return found)))
907 (unless (absolute-pathname-p p)
908 (let ((true-defaults (ignore-errors (truename defaults))))
910 (setf p (merge-pathnames pathname true-defaults)))))
911 (unless (absolute-pathname-p p) (return p))
912 (let ((sofar (probe-file* (pathname-root p))))
913 (unless sofar (return p))
914 (flet ((solution (directories)
916 (make-pathname :host nil :device nil
917 :directory `(:relative ,@directories)
918 :name (pathname-name p)
919 :type (pathname-type p)
920 :version (pathname-version p))
922 (loop :with directory = (normalize-pathname-directory-component
923 (pathname-directory p))
924 :for component :in (cdr directory)
925 :for rest :on (cdr directory)
926 :for more = (probe-file*
928 (make-pathname :directory `(:relative ,component))
932 (return (solution rest)))
934 (return (solution nil))))))))
936 (defun* resolve-symlinks (path)
937 #-allegro (truenamize path)
938 #+allegro (if (typep path 'logical-pathname)
940 (excl:pathname-resolve-symbolic-links path)))
942 (defun* resolve-symlinks* (path)
943 (if *resolve-symlinks*
944 (and path (resolve-symlinks path))
947 (defun* ensure-pathname-absolute (path)
949 ((absolute-pathname-p path) path)
950 ((stringp path) (ensure-pathname-absolute (pathname path)))
951 ((not (pathnamep path)) (error "not a valid pathname designator ~S" path))
952 (t (let ((resolved (resolve-symlinks path)))
953 (assert (absolute-pathname-p resolved))
956 (defun* default-directory ()
957 (truenamize (pathname-directory-pathname *default-pathname-defaults*)))
959 (defun* lispize-pathname (input-file)
960 (make-pathname :type "lisp" :defaults input-file))
962 (defparameter *wild* #-cormanlisp :wild #+cormanlisp "*")
963 (defparameter *wild-file*
964 (make-pathname :name *wild* :type *wild*
965 :version (or #-(or abcl xcl) *wild*) :directory nil))
966 (defparameter *wild-directory*
967 (make-pathname :directory `(:relative ,*wild*) :name nil :type nil :version nil))
968 (defparameter *wild-inferiors*
969 (make-pathname :directory '(:relative :wild-inferiors) :name nil :type nil :version nil))
970 (defparameter *wild-path*
971 (merge-pathnames *wild-file* *wild-inferiors*))
973 (defun* wilden (path)
974 (merge-pathnames* *wild-path* path))
977 (defun* directory-separator-for-host (&optional (pathname *default-pathname-defaults*))
978 (let ((foo (make-pathname :directory '(:absolute "FOO") :defaults pathname)))
979 (last-char (namestring foo))))
982 (defun* directorize-pathname-host-device (pathname)
983 (let* ((root (pathname-root pathname))
984 (wild-root (wilden root))
985 (absolute-pathname (merge-pathnames* pathname root))
986 (separator (directory-separator-for-host root))
987 (root-namestring (namestring root))
990 #'(lambda (x) (or (eql x #\:)
993 (multiple-value-bind (relative path filename)
994 (component-name-to-pathname-components root-string :force-directory t)
995 (declare (ignore relative filename))
997 (make-pathname :defaults root
998 :directory `(:absolute ,@path))))
999 (translate-pathname absolute-pathname wild-root (wilden new-base))))))
1002 (defun* directorize-pathname-host-device (pathname)
1003 (let ((scheme (ext:pathname-scheme pathname))
1004 (host (pathname-host pathname))
1005 (port (ext:pathname-port pathname))
1006 (directory (pathname-directory pathname)))
1007 (flet ((specificp (x) (and x (not (eq x :unspecific)))))
1008 (if (or (specificp port)
1009 (and (specificp host) (plusp (length host)))
1012 (when (specificp port)
1013 (setf prefix (format nil ":~D" port)))
1014 (when (and (specificp host) (plusp (length host)))
1015 (setf prefix (strcat host prefix)))
1016 (setf prefix (strcat ":" prefix))
1017 (when (specificp scheme)
1018 (setf prefix (strcat scheme prefix)))
1019 (assert (and directory (eq (first directory) :absolute)))
1020 (make-pathname :directory `(:absolute ,prefix ,@(rest directory))
1021 :defaults pathname)))
1024 ;;;; -------------------------------------------------------------------------
1025 ;;;; ASDF Interface, in terms of generic functions.
1026 (defgeneric* find-system (system &optional error-p))
1027 (defgeneric* perform-with-restarts (operation component))
1028 (defgeneric* perform (operation component))
1029 (defgeneric* operation-done-p (operation component))
1030 (defgeneric* mark-operation-done (operation component))
1031 (defgeneric* explain (operation component))
1032 (defgeneric* output-files (operation component))
1033 (defgeneric* input-files (operation component))
1034 (defgeneric* component-operation-time (operation component))
1035 (defgeneric* operation-description (operation component)
1036 (:documentation "returns a phrase that describes performing this operation
1037 on this component, e.g. \"loading /a/b/c\".
1038 You can put together sentences using this phrase."))
1040 (defgeneric* system-source-file (system)
1041 (:documentation "Return the source file in which system is defined."))
1043 (defgeneric* component-system (component)
1044 (:documentation "Find the top-level system containing COMPONENT"))
1046 (defgeneric* component-pathname (component)
1047 (:documentation "Extracts the pathname applicable for a particular component."))
1049 (defgeneric* component-relative-pathname (component)
1050 (:documentation "Returns a pathname for the component argument intended to be
1051 interpreted relative to the pathname of that component's parent.
1052 Despite the function's name, the return value may be an absolute
1053 pathname, because an absolute pathname may be interpreted relative to
1054 another pathname in a degenerate way."))
1056 (defgeneric* component-property (component property))
1058 (defgeneric* (setf component-property) (new-value component property))
1060 (defgeneric* component-external-format (component))
1062 (defgeneric* component-encoding (component))
1064 (eval-when (#-gcl :compile-toplevel :load-toplevel :execute)
1065 (defgeneric* (setf module-components-by-name) (new-value module)))
1067 (defgeneric* version-satisfies (component version))
1069 (defgeneric* find-component (base path)
1070 (:documentation "Finds the component with PATH starting from BASE module;
1071 if BASE is nil, then the component is assumed to be a system."))
1073 (defgeneric* source-file-type (component system))
1075 (defgeneric* operation-ancestor (operation)
1077 "Recursively chase the operation's parent pointer until we get to
1078 the head of the tree"))
1080 (defgeneric* component-visited-p (operation component)
1081 (:documentation "Returns the value stored by a call to
1082 VISIT-COMPONENT, if that has been called, otherwise NIL.
1083 This value stored will be a cons cell, the first element
1084 of which is a computed key, so not interesting. The
1085 CDR wil be the DATA value stored by VISIT-COMPONENT; recover
1086 it as (cdr (component-visited-p op c)).
1087 In the current form of ASDF, the DATA value retrieved is
1088 effectively a boolean, indicating whether some operations are
1089 to be performed in order to do OPERATION X COMPONENT. If the
1090 data value is NIL, the combination had been explored, but no
1091 operations needed to be performed."))
1093 (defgeneric* visit-component (operation component data)
1094 (:documentation "Record DATA as being associated with OPERATION
1095 and COMPONENT. This is a side-effecting function: the association
1096 will be recorded on the ROOT OPERATION \(OPERATION-ANCESTOR of the
1098 No evidence that DATA is ever interesting, beyond just being
1099 non-NIL. Using the data field is probably very risky; if there is
1100 already a record for OPERATION X COMPONENT, DATA will be quietly
1101 discarded instead of recorded.
1102 Starting with 2.006, TRAVERSE will store an integer in data,
1103 so that nodes can be sorted in decreasing order of traversal."))
1106 (defgeneric* (setf visiting-component) (new-value operation component))
1108 (defgeneric* component-visiting-p (operation component))
1110 (defgeneric* component-depends-on (operation component)
1112 "Returns a list of dependencies needed by the component to perform
1113 the operation. A dependency has one of the following forms:
1115 (<operation> <component>*), where <operation> is a class
1116 designator and each <component> is a component
1117 designator, which means that the component depends on
1118 <operation> having been performed on each <component>; or
1120 (FEATURE <feature>), which means that the component depends
1121 on <feature>'s presence in *FEATURES*.
1123 Methods specialized on subclasses of existing component types
1124 should usually append the results of CALL-NEXT-METHOD to the
1127 (defgeneric* component-self-dependencies (operation component))
1129 (defgeneric* traverse (operation component)
1131 "Generate and return a plan for performing OPERATION on COMPONENT.
1133 The plan returned is a list of dotted-pairs. Each pair is the CONS
1134 of ASDF operation object and a COMPONENT object. The pairs will be
1135 processed in order by OPERATE."))
1138 ;;;; -------------------------------------------------------------------------
1139 ;;; Methods in case of hot-upgrade. See https://bugs.launchpad.net/asdf/+bug/485687
1141 (when (find-class 'module nil)
1143 '(defmethod update-instance-for-redefined-class :after
1144 ((m module) added deleted plist &key)
1145 (declare (ignorable deleted plist))
1146 (when *asdf-verbose*
1147 (asdf-message (compatfmt "~&~@<; ~@;Updating ~A for ASDF ~A~@:>~%")
1149 (when (member 'components-by-name added)
1150 (compute-module-components-by-name m))
1151 (when (typep m 'system)
1152 (when (member 'source-file added)
1153 (%set-system-source-file
1154 (probe-asd (component-name m) (component-pathname m)) m)
1155 (when (equal (component-name m) "asdf")
1156 (setf (component-version m) *asdf-version*))))))))
1158 ;;;; -------------------------------------------------------------------------
1159 ;;;; Classes, Conditions
1161 (define-condition system-definition-error (error) ()
1162 ;; [this use of :report should be redundant, but unfortunately it's not.
1163 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
1164 ;; over print-object; this is always conditions::%print-condition for
1165 ;; condition objects, which in turn does inheritance of :report options at
1166 ;; run-time. fortunately, inheritance means we only need this kludge here in
1167 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
1168 #+cmu (:report print-object))
1170 (define-condition formatted-system-definition-error (system-definition-error)
1171 ((format-control :initarg :format-control :reader format-control)
1172 (format-arguments :initarg :format-arguments :reader format-arguments))
1173 (:report (lambda (c s)
1174 (apply 'format s (format-control c) (format-arguments c)))))
1176 (define-condition load-system-definition-error (system-definition-error)
1177 ((name :initarg :name :reader error-name)
1178 (pathname :initarg :pathname :reader error-pathname)
1179 (condition :initarg :condition :reader error-condition))
1180 (:report (lambda (c s)
1181 (format s (compatfmt "~@<Error while trying to load definition for system ~A from pathname ~A: ~3i~_~A~@:>")
1182 (error-name c) (error-pathname c) (error-condition c)))))
1184 (define-condition circular-dependency (system-definition-error)
1185 ((components :initarg :components :reader circular-dependency-components))
1186 (:report (lambda (c s)
1187 (format s (compatfmt "~@<Circular dependency: ~3i~_~S~@:>")
1188 (circular-dependency-components c)))))
1190 (define-condition duplicate-names (system-definition-error)
1191 ((name :initarg :name :reader duplicate-names-name))
1192 (:report (lambda (c s)
1193 (format s (compatfmt "~@<Error while defining system: multiple components are given same name ~A~@:>")
1194 (duplicate-names-name c)))))
1196 (define-condition missing-component (system-definition-error)
1197 ((requires :initform "(unnamed)" :reader missing-requires :initarg :requires)
1198 (parent :initform nil :reader missing-parent :initarg :parent)))
1200 (define-condition missing-component-of-version (missing-component)
1201 ((version :initform nil :reader missing-version :initarg :version)))
1203 (define-condition missing-dependency (missing-component)
1204 ((required-by :initarg :required-by :reader missing-required-by)))
1206 (define-condition missing-dependency-of-version (missing-dependency
1207 missing-component-of-version)
1210 (define-condition operation-error (error)
1211 ((component :reader error-component :initarg :component)
1212 (operation :reader error-operation :initarg :operation))
1213 (:report (lambda (c s)
1214 (format s (compatfmt "~@<Error while invoking ~A on ~A~@:>")
1215 (error-operation c) (error-component c)))))
1216 (define-condition compile-error (operation-error) ())
1217 (define-condition compile-failed (compile-error) ())
1218 (define-condition compile-warned (compile-error) ())
1220 (define-condition invalid-configuration ()
1221 ((form :reader condition-form :initarg :form)
1222 (location :reader condition-location :initarg :location)
1223 (format :reader condition-format :initarg :format)
1224 (arguments :reader condition-arguments :initarg :arguments :initform nil))
1225 (:report (lambda (c s)
1226 (format s (compatfmt "~@<~? (will be skipped)~@:>")
1227 (condition-format c)
1228 (list* (condition-form c) (condition-location c)
1229 (condition-arguments c))))))
1230 (define-condition invalid-source-registry (invalid-configuration warning)
1231 ((format :initform (compatfmt "~@<Invalid source registry ~S~@[ in ~S~]~@{ ~@?~}~@:>"))))
1232 (define-condition invalid-output-translation (invalid-configuration warning)
1233 ((format :initform (compatfmt "~@<Invalid asdf output-translation ~S~@[ in ~S~]~@{ ~@?~}~@:>"))))
1235 (defclass component ()
1236 ((name :accessor component-name :initarg :name :type string :documentation
1237 "Component name: designator for a string composed of portable pathname characters")
1238 ;; We might want to constrain version with
1239 ;; :type (and string (satisfies parse-version))
1240 ;; but we cannot until we fix all systems that don't use it correctly!
1241 (version :accessor component-version :initarg :version)
1242 (description :accessor component-description :initarg :description)
1243 (long-description :accessor component-long-description :initarg :long-description)
1244 ;; This one below is used by POIU - http://www.cliki.net/poiu
1245 ;; a parallelizing extension of ASDF that compiles in multiple parallel
1246 ;; slave processes (forked on demand) and loads in the master process.
1247 ;; Maybe in the future ASDF may use it internally instead of in-order-to.
1248 (load-dependencies :accessor component-load-dependencies :initform nil)
1249 ;; In the ASDF object model, dependencies exist between *actions*
1250 ;; (an action is a pair of operation and component). They are represented
1251 ;; alists of operations to dependencies (other actions) in each component.
1252 ;; There are two kinds of dependencies, each stored in its own slot:
1253 ;; in-order-to and do-first dependencies. These two kinds are related to
1254 ;; the fact that some actions modify the filesystem,
1255 ;; whereas other actions modify the current image, and
1256 ;; this implies a difference in how to interpret timestamps.
1257 ;; in-order-to dependencies will trigger re-performing the action
1258 ;; when the timestamp of some dependency
1259 ;; makes the timestamp of current action out-of-date;
1260 ;; do-first dependencies do not trigger such re-performing.
1261 ;; Therefore, a FASL must be recompiled if it is obsoleted
1262 ;; by any of its FASL dependencies (in-order-to); but
1263 ;; it needn't be recompiled just because one of these dependencies
1264 ;; hasn't yet been loaded in the current image (do-first).
1265 ;; The names are crap, but they have been the official API since Dan Barlow's ASDF 1.52!
1266 ;; LispWorks's defsystem has caused-by and requires for in-order-to and do-first respectively.
1267 ;; Maybe rename the slots in ASDF? But that's not very backwards compatible.
1268 ;; See our ASDF 2 paper for more complete explanations.
1269 (in-order-to :initform nil :initarg :in-order-to
1270 :accessor component-in-order-to)
1271 (do-first :initform nil :initarg :do-first
1272 :accessor component-do-first)
1273 ;; methods defined using the "inline" style inside a defsystem form:
1274 ;; need to store them somewhere so we can delete them when the system
1276 (inline-methods :accessor component-inline-methods :initform nil)
1277 (parent :initarg :parent :initform nil :reader component-parent)
1278 ;; no direct accessor for pathname, we do this as a method to allow
1279 ;; it to default in funky ways if not supplied
1280 (relative-pathname :initarg :pathname)
1281 ;; the absolute-pathname is computed based on relative-pathname...
1283 (operation-times :initform (make-hash-table)
1284 :accessor component-operation-times)
1285 (around-compile :initarg :around-compile)
1286 (%encoding :accessor %component-encoding :initform nil :initarg :encoding)
1287 ;; XXX we should provide some atomic interface for updating the
1288 ;; component properties
1289 (properties :accessor component-properties :initarg :properties
1292 (defun* component-find-path (component)
1294 (loop :for c = component :then (component-parent c)
1295 :while c :collect (component-name c))))
1297 (defmethod print-object ((c component) stream)
1298 (print-unreadable-object (c stream :type t :identity nil)
1299 (format stream "~{~S~^ ~}" (component-find-path c))))
1302 ;;;; methods: conditions
1304 (defmethod print-object ((c missing-dependency) s)
1305 (format s (compatfmt "~@<~A, required by ~A~@:>")
1306 (call-next-method c nil) (missing-required-by c)))
1308 (defun* sysdef-error (format &rest arguments)
1309 (error 'formatted-system-definition-error :format-control
1310 format :format-arguments arguments))
1312 ;;;; methods: components
1314 (defmethod print-object ((c missing-component) s)
1315 (format s (compatfmt "~@<Component ~S not found~@[ in ~A~]~@:>")
1316 (missing-requires c)
1317 (when (missing-parent c)
1318 (coerce-name (missing-parent c)))))
1320 (defmethod print-object ((c missing-component-of-version) s)
1321 (format s (compatfmt "~@<Component ~S does not match version ~A~@[ in ~A~]~@:>")
1322 (missing-requires c)
1324 (when (missing-parent c)
1325 (coerce-name (missing-parent c)))))
1327 (defmethod component-system ((component component))
1328 (aif (component-parent component)
1329 (component-system it)
1332 (defvar *default-component-class* 'cl-source-file)
1334 (defun* compute-module-components-by-name (module)
1335 (let ((hash (make-hash-table :test 'equal)))
1336 (setf (module-components-by-name module) hash)
1337 (loop :for c :in (module-components module)
1338 :for name = (component-name c)
1339 :for previous = (gethash name (module-components-by-name module))
1342 (error 'duplicate-names :name name))
1343 :do (setf (gethash name (module-components-by-name module)) c))
1346 (defclass module (component)
1349 :initarg :components
1350 :accessor module-components)
1352 :accessor module-components-by-name)
1353 ;; What to do if we can't satisfy a dependency of one of this module's
1354 ;; components. This allows a limited form of conditional processing.
1355 (if-component-dep-fails
1357 :initarg :if-component-dep-fails
1358 :accessor module-if-component-dep-fails)
1359 (default-component-class
1361 :initarg :default-component-class
1362 :accessor module-default-component-class)))
1364 (defun* component-parent-pathname (component)
1365 ;; No default anymore (in particular, no *default-pathname-defaults*).
1366 ;; If you force component to have a NULL pathname, you better arrange
1367 ;; for any of its children to explicitly provide a proper absolute pathname
1368 ;; wherever a pathname is actually wanted.
1369 (let ((parent (component-parent component)))
1371 (component-pathname parent))))
1373 (defmethod component-pathname ((component component))
1374 (if (slot-boundp component 'absolute-pathname)
1375 (slot-value component 'absolute-pathname)
1378 (component-relative-pathname component)
1379 (pathname-directory-pathname (component-parent-pathname component)))))
1380 (unless (or (null pathname) (absolute-pathname-p pathname))
1381 (error (compatfmt "~@<Invalid relative pathname ~S for component ~S~@:>")
1382 pathname (component-find-path component)))
1383 (setf (slot-value component 'absolute-pathname) pathname)
1386 (defmethod component-property ((c component) property)
1387 (cdr (assoc property (slot-value c 'properties) :test #'equal)))
1389 (defmethod (setf component-property) (new-value (c component) property)
1390 (let ((a (assoc property (slot-value c 'properties) :test #'equal)))
1392 (setf (cdr a) new-value)
1393 (setf (slot-value c 'properties)
1394 (acons property new-value (slot-value c 'properties)))))
1397 (defvar *default-encoding* :default
1398 "Default encoding for source files.
1399 The default value :default preserves the legacy behavior.
1400 A future default might be :utf-8 or :autodetect
1401 reading emacs-style -*- coding: utf-8 -*- specifications,
1402 and falling back to utf-8 or latin1 if nothing is specified.")
1404 (defparameter *utf-8-external-format*
1405 #+(and asdf-unicode (not clisp)) :utf-8
1406 #+(and asdf-unicode clisp) charset:utf-8
1407 #-asdf-unicode :default
1408 "Default :external-format argument to pass to CL:OPEN and also
1409 CL:LOAD or CL:COMPILE-FILE to best process a UTF-8 encoded file.
1410 On modern implementations, this will decode UTF-8 code points as CL characters.
1411 On legacy implementations, it may fall back on some 8-bit encoding,
1412 with non-ASCII code points being read as several CL characters;
1413 hopefully, if done consistently, that won't affect program behavior too much.")
1415 (defun* always-default-encoding (pathname)
1416 (declare (ignore pathname))
1419 (defvar *encoding-detection-hook* #'always-default-encoding
1420 "Hook for an extension to define a function to automatically detect a file's encoding")
1422 (defun* detect-encoding (pathname)
1423 (funcall *encoding-detection-hook* pathname))
1425 (defmethod component-encoding ((c component))
1426 (or (loop :for x = c :then (component-parent x)
1427 :while x :thereis (%component-encoding x))
1428 (detect-encoding (component-pathname c))))
1430 (defun* default-encoding-external-format (encoding)
1432 (:default :default) ;; for backwards compatibility only. Explicit usage discouraged.
1433 (:utf-8 *utf-8-external-format*)
1435 (cerror "Continue using :external-format :default" (compatfmt "~@<Your ASDF component is using encoding ~S but it isn't recognized. Your system should :defsystem-depends-on (:asdf-encodings).~:>") encoding)
1438 (defvar *encoding-external-format-hook*
1439 #'default-encoding-external-format
1440 "Hook for an extension to define a mapping between non-default encodings
1441 and implementation-defined external-format's")
1443 (defun encoding-external-format (encoding)
1444 (funcall *encoding-external-format-hook* encoding))
1446 (defmethod component-external-format ((c component))
1447 (encoding-external-format (component-encoding c)))
1449 (defclass proto-system () ; slots to keep when resetting a system
1450 ;; To preserve identity for all objects, we'd need keep the components slots
1451 ;; but also to modify parse-component-form to reset the recycled objects.
1452 ((name) #|(components) (components-by-names)|#))
1454 (defclass system (module proto-system)
1455 (;; description and long-description are now available for all component's,
1456 ;; but now also inherited from component, but we add the legacy accessor
1457 (description :accessor system-description :initarg :description)
1458 (long-description :accessor system-long-description :initarg :long-description)
1459 (author :accessor system-author :initarg :author)
1460 (maintainer :accessor system-maintainer :initarg :maintainer)
1461 (licence :accessor system-licence :initarg :licence
1462 :accessor system-license :initarg :license)
1463 (source-file :reader %system-source-file :initarg :source-file ; for CLISP upgrade
1464 :writer %set-system-source-file)
1465 (defsystem-depends-on :reader system-defsystem-depends-on :initarg :defsystem-depends-on)))
1467 ;;;; -------------------------------------------------------------------------
1468 ;;;; version-satisfies
1470 (defmethod version-satisfies ((c component) version)
1471 (unless (and version (slot-boundp c 'version))
1473 (warn "Requested version ~S but component ~S has no version" version c))
1474 (return-from version-satisfies t))
1475 (version-satisfies (component-version c) version))
1477 (defun* asdf-version ()
1478 "Exported interface to the version of ASDF currently installed. A string.
1479 You can compare this string with e.g.:
1480 (ASDF:VERSION-SATISFIES (ASDF:ASDF-VERSION) \"2.345.67\")."
1483 (defun* parse-version (string &optional on-error)
1484 "Parse a version string as a series of natural integers separated by dots.
1485 Return a (non-null) list of integers if the string is valid, NIL otherwise.
1486 If on-error is error, warn, or designates a function of compatible signature,
1487 the function is called with an explanation of what is wrong with the argument.
1488 NB: ignores leading zeroes, and so doesn't distinguish between 2.003 and 2.3"
1490 (or (stringp string)
1492 (funcall on-error "~S: ~S is not a string"
1493 'parse-version string)) nil)
1494 (or (loop :for prev = nil :then c :for c :across string
1495 :always (or (digit-char-p c)
1496 (and (eql c #\.) prev (not (eql prev #\.))))
1497 :finally (return (and c (digit-char-p c))))
1499 (funcall on-error "~S: ~S doesn't follow asdf version numbering convention"
1500 'parse-version string)) nil)
1501 (mapcar #'parse-integer (split-string string :separator "."))))
1503 (defmethod version-satisfies ((cver string) version)
1504 (let ((x (parse-version cver 'warn))
1505 (y (parse-version version 'warn)))
1506 (labels ((bigger (x y)
1509 ((> (car x) (car y)) t)
1510 ((= (car x) (car y))
1511 (bigger (cdr x) (cdr y))))))
1512 (and x y (= (car x) (car y))
1513 (or (not (cdr y)) (bigger (cdr x) (cdr y)))))))
1515 ;;;; -----------------------------------------------------------------
1516 ;;;; Windows shortcut support. Based on:
1518 ;;;; Jesse Hager: The Windows Shortcut File Format.
1519 ;;;; http://www.wotsit.org/list.asp?fc=13
1521 #-(or clisp genera) ; CLISP doesn't need it, and READ-SEQUENCE annoys old Genera.
1523 (defparameter *link-initial-dword* 76)
1524 (defparameter *link-guid* #(1 20 2 0 0 0 0 0 192 0 0 0 0 0 0 70))
1526 (defun* read-null-terminated-string (s)
1527 (with-output-to-string (out)
1528 (loop :for code = (read-byte s)
1530 :do (write-char (code-char code) out))))
1532 (defun* read-little-endian (s &optional (bytes 4))
1533 (loop :for i :from 0 :below bytes
1534 :sum (ash (read-byte s) (* 8 i))))
1536 (defun* parse-file-location-info (s)
1537 (let ((start (file-position s))
1538 (total-length (read-little-endian s))
1539 (end-of-header (read-little-endian s))
1540 (fli-flags (read-little-endian s))
1541 (local-volume-offset (read-little-endian s))
1542 (local-offset (read-little-endian s))
1543 (network-volume-offset (read-little-endian s))
1544 (remaining-offset (read-little-endian s)))
1545 (declare (ignore total-length end-of-header local-volume-offset))
1546 (unless (zerop fli-flags)
1548 ((logbitp 0 fli-flags)
1549 (file-position s (+ start local-offset)))
1550 ((logbitp 1 fli-flags)
1551 (file-position s (+ start
1552 network-volume-offset
1554 (strcat (read-null-terminated-string s)
1556 (file-position s (+ start remaining-offset))
1557 (read-null-terminated-string s))))))
1559 (defun* parse-windows-shortcut (pathname)
1560 (with-open-file (s pathname :element-type '(unsigned-byte 8))
1562 (when (and (= (read-little-endian s) *link-initial-dword*)
1563 (let ((header (make-array (length *link-guid*))))
1564 (read-sequence header s)
1565 (equalp header *link-guid*)))
1566 (let ((flags (read-little-endian s)))
1567 (file-position s 76) ;skip rest of header
1568 (when (logbitp 0 flags)
1569 ;; skip shell item id list
1570 (let ((length (read-little-endian s 2)))
1571 (file-position s (+ length (file-position s)))))
1574 (parse-file-location-info s))
1576 (when (logbitp 2 flags)
1577 ;; skip description string
1578 (let ((length (read-little-endian s 2)))
1579 (file-position s (+ length (file-position s)))))
1580 (when (logbitp 3 flags)
1581 ;; finally, our pathname
1582 (let* ((length (read-little-endian s 2))
1583 (buffer (make-array length)))
1584 (read-sequence buffer s)
1585 (map 'string #'code-char buffer)))))))
1589 ;;;; -------------------------------------------------------------------------
1590 ;;;; Finding systems
1592 (defun* make-defined-systems-table ()
1593 (make-hash-table :test 'equal))
1595 (defvar *defined-systems* (make-defined-systems-table)
1596 "This is a hash table whose keys are strings, being the
1597 names of the systems, and whose values are pairs, the first
1598 element of which is a universal-time indicating when the
1599 system definition was last updated, and the second element
1600 of which is a system object.")
1602 (defun* coerce-name (name)
1604 (component (component-name name))
1605 (symbol (string-downcase (symbol-name name)))
1607 (t (sysdef-error (compatfmt "~@<Invalid component designator: ~3i~_~A~@:>") name))))
1609 (defun* system-registered-p (name)
1610 (gethash (coerce-name name) *defined-systems*))
1612 (defun* registered-systems ()
1613 (loop :for (() . system) :being :the :hash-values :of *defined-systems*
1614 :collect (coerce-name system)))
1616 (defun* register-system (system)
1617 (check-type system system)
1618 (let ((name (component-name system)))
1619 (check-type name string)
1620 (asdf-message (compatfmt "~&~@<; ~@;Registering ~3i~_~A~@:>~%") system)
1621 (unless (eq system (cdr (gethash name *defined-systems*)))
1622 (setf (gethash name *defined-systems*)
1623 (cons (get-universal-time) system)))))
1625 (defun* clear-system (name)
1626 "Clear the entry for a system in the database of systems previously loaded.
1627 Note that this does NOT in any way cause the code of the system to be unloaded."
1628 ;; There is no "unload" operation in Common Lisp, and
1629 ;; a general such operation cannot be portably written,
1630 ;; considering how much CL relies on side-effects to global data structures.
1631 (remhash (coerce-name name) *defined-systems*))
1633 (defun* map-systems (fn)
1634 "Apply FN to each defined system.
1636 FN should be a function of one argument. It will be
1637 called with an object of type asdf:system."
1638 (maphash #'(lambda (_ datum)
1639 (declare (ignore _))
1640 (destructuring-bind (_ . def) datum
1641 (declare (ignore _))
1645 ;;; for the sake of keeping things reasonably neat, we adopt a
1646 ;;; convention that functions in this list are prefixed SYSDEF-
1648 (defvar *system-definition-search-functions* '())
1650 (setf *system-definition-search-functions*
1652 ;; Remove known-incompatible sysdef functions from ancient sbcl asdf.
1653 (remove 'contrib-sysdef-search *system-definition-search-functions*)
1654 ;; Tuck our defaults at the end of the list if they were absent.
1655 ;; This is imperfect, in case they were removed on purpose,
1656 ;; but then it will be the responsibility of whoever does that
1657 ;; to upgrade asdf before he does such a thing rather than after.
1658 (remove-if #'(lambda (x) (member x *system-definition-search-functions*))
1659 '(sysdef-central-registry-search
1660 sysdef-source-registry-search
1661 sysdef-find-asdf))))
1663 (defun* search-for-system-definition (system)
1664 (some (let ((name (coerce-name system))) #'(lambda (x) (funcall x name)))
1665 (cons 'find-system-if-being-defined
1666 *system-definition-search-functions*)))
1668 (defvar *central-registry* nil
1669 "A list of 'system directory designators' ASDF uses to find systems.
1671 A 'system directory designator' is a pathname or an expression
1672 which evaluates to a pathname. For example:
1674 (setf asdf:*central-registry*
1675 (list '*default-pathname-defaults*
1676 #p\"/home/me/cl/systems/\"
1677 #p\"/usr/share/common-lisp/systems/\"))
1679 This is for backward compatibilily.
1680 Going forward, we recommend new users should be using the source-registry.
1683 (defun* featurep (x &optional (features *features*))
1686 (and (member x features) t))
1688 (assert (null (cddr x)))
1689 (not (featurep (cadr x) features)))
1691 (some #'(lambda (x) (featurep x features)) (cdr x)))
1693 (every #'(lambda (x) (featurep x features)) (cdr x)))
1695 (error "Malformed feature specification ~S" x))))
1697 (defun* os-unix-p ()
1698 (featurep '(:or :unix :cygwin :darwin)))
1700 (defun* os-windows-p ()
1701 (and (not (os-unix-p)) (featurep '(:or :win32 :windows :mswindows :mingw32))))
1703 (defun* probe-asd (name defaults)
1705 (when (directory-pathname-p defaults)
1706 (let* ((file (probe-file* (subpathname defaults (strcat name ".asd")))))
1709 #-(or clisp genera) ; clisp doesn't need it, plain genera doesn't have read-sequence(!)
1710 (when (os-windows-p)
1713 :defaults defaults :version :newest :case :local
1714 :name (strcat name ".asd")
1716 (when (probe-file* shortcut)
1717 (let ((target (parse-windows-shortcut shortcut)))
1719 (return (pathname target))))))))))
1721 (defun* sysdef-central-registry-search (system)
1722 (let ((name (coerce-name system))
1727 (dolist (dir *central-registry*)
1728 (let ((defaults (eval dir)))
1730 (cond ((directory-pathname-p defaults)
1731 (let ((file (probe-asd name defaults)))
1736 (let* ((*print-circle* nil)
1739 (compatfmt "~@<While searching for system ~S: ~3i~_~S evaluated to ~S which is not a directory.~@:>")
1740 system dir defaults)))
1742 (remove-entry-from-registry ()
1743 :report "Remove entry from *central-registry* and continue"
1744 (push dir to-remove))
1745 (coerce-entry-to-directory ()
1747 (format s (compatfmt "~@<Coerce entry to ~a, replace ~a and continue.~@:>")
1748 (ensure-directory-pathname defaults) dir))
1749 (push (cons dir (ensure-directory-pathname defaults)) to-replace))))))))
1751 (dolist (dir to-remove)
1752 (setf *central-registry* (remove dir *central-registry*)))
1753 (dolist (pair to-replace)
1754 (let* ((current (car pair))
1756 (position (position current *central-registry*)))
1757 (setf *central-registry*
1758 (append (subseq *central-registry* 0 position)
1760 (subseq *central-registry* (1+ position))))))))))
1762 (defun* make-temporary-package ()
1763 (flet ((try (counter)
1765 (make-package (format nil "~A~D" :asdf counter)
1766 :use '(:cl :asdf)))))
1767 (do* ((counter 0 (+ counter 1))
1768 (package (try counter) (try counter)))
1769 (package package))))
1771 (defun* safe-file-write-date (pathname)
1772 ;; If FILE-WRITE-DATE returns NIL, it's possible that
1773 ;; the user or some other agent has deleted an input file.
1774 ;; Also, generated files will not exist at the time planning is done
1775 ;; and calls operation-done-p which calls safe-file-write-date.
1776 ;; So it is very possible that we can't get a valid file-write-date,
1777 ;; and we can survive and we will continue the planning
1778 ;; as if the file were very old.
1779 ;; (or should we treat the case in a different, special way?)
1780 (or (and pathname (probe-file* pathname) (ignore-errors (file-write-date pathname)))
1782 (when (and pathname *asdf-verbose*)
1783 (warn (compatfmt "~@<Missing FILE-WRITE-DATE for ~S, treating it as zero.~@:>")
1787 (defmethod find-system ((name null) &optional (error-p t))
1788 (declare (ignorable name))
1790 (sysdef-error (compatfmt "~@<NIL is not a valid system name~@:>"))))
1792 (defmethod find-system (name &optional (error-p t))
1793 (find-system (coerce-name name) error-p))
1795 (defvar *systems-being-defined* nil
1796 "A hash-table of systems currently being defined keyed by name, or NIL")
1798 (defun* find-system-if-being-defined (name)
1799 (when *systems-being-defined*
1800 (gethash (coerce-name name) *systems-being-defined*)))
1802 (defun* call-with-system-definitions (thunk)
1803 (if *systems-being-defined*
1805 (let ((*systems-being-defined* (make-hash-table :test 'equal)))
1808 (defmacro with-system-definitions ((&optional) &body body)
1809 `(call-with-system-definitions #'(lambda () ,@body)))
1811 (defun* load-sysdef (name pathname)
1812 ;; Tries to load system definition with canonical NAME from PATHNAME.
1813 (with-system-definitions ()
1814 (let ((package (make-temporary-package)))
1817 ((error #'(lambda (condition)
1818 (error 'load-system-definition-error
1819 :name name :pathname pathname
1820 :condition condition))))
1821 (let ((*package* package)
1822 (*default-pathname-defaults*
1823 ;; resolve logical-pathnames so they won't wreak havoc in parsing namestrings.
1824 (pathname-directory-pathname (translate-logical-pathname pathname)))
1825 (external-format (encoding-external-format (detect-encoding pathname))))
1826 (asdf-message (compatfmt "~&~@<; ~@;Loading system definition from ~A into ~A~@:>~%")
1828 (load pathname :external-format external-format)))
1829 (delete-package package)))))
1831 (defun* locate-system (name)
1832 "Given a system NAME designator, try to locate where to load the system from.
1833 Returns five values: FOUNDP FOUND-SYSTEM PATHNAME PREVIOUS PREVIOUS-TIME
1834 FOUNDP is true when a system was found,
1835 either a new unregistered one or a previously registered one.
1836 FOUND-SYSTEM when not null is a SYSTEM object that may be REGISTER-SYSTEM'ed as is
1837 PATHNAME when not null is a path from where to load the system,
1838 either associated with FOUND-SYSTEM, or with the PREVIOUS system.
1839 PREVIOUS when not null is a previously loaded SYSTEM object of same name.
1840 PREVIOUS-TIME when not null is the time at which the PREVIOUS system was loaded."
1841 (let* ((name (coerce-name name))
1842 (in-memory (system-registered-p name)) ; load from disk if absent or newer on disk
1843 (previous (cdr in-memory))
1844 (previous (and (typep previous 'system) previous))
1845 (previous-time (car in-memory))
1846 (found (search-for-system-definition name))
1847 (found-system (and (typep found 'system) found))
1848 (pathname (or (and (typep found '(or pathname string)) (pathname found))
1849 (and found-system (system-source-file found-system))
1850 (and previous (system-source-file previous))))
1851 (foundp (and (or found-system pathname previous) t)))
1852 (check-type found (or null pathname system))
1854 (setf pathname (resolve-symlinks* pathname))
1855 (when (and pathname (not (absolute-pathname-p pathname)))
1856 (setf pathname (ensure-pathname-absolute pathname))
1858 (%set-system-source-file pathname found-system)))
1859 (when (and previous (not (#-cormanlisp equal #+cormanlisp equalp
1860 (system-source-file previous) pathname)))
1861 (%set-system-source-file pathname previous)
1862 (setf previous-time nil))
1863 (values foundp found-system pathname previous previous-time))))
1865 (defmethod find-system ((name string) &optional (error-p t))
1866 (with-system-definitions ()
1869 (multiple-value-bind (foundp found-system pathname previous previous-time)
1870 (locate-system name)
1871 (declare (ignore foundp))
1872 (when (and found-system (not previous))
1873 (register-system found-system))
1875 (or (not previous-time)
1876 ;; don't reload if it's already been loaded,
1877 ;; or its filestamp is in the future which means some clock is skewed
1878 ;; and trying to load might cause an infinite loop.
1879 (< previous-time (safe-file-write-date pathname) (get-universal-time))))
1880 (load-sysdef name pathname))
1881 (let ((in-memory (system-registered-p name))) ; try again after loading from disk if needed
1886 (setf (car in-memory) (safe-file-write-date pathname)))
1889 (error 'missing-component :requires name))))))
1890 (reinitialize-source-registry-and-retry ()
1892 (format s (compatfmt "~@<Retry finding system ~A after reinitializing the source-registry.~@:>") name))
1893 (initialize-source-registry))))))
1895 (defun* find-system-fallback (requested fallback &rest keys &key source-file &allow-other-keys)
1896 (setf fallback (coerce-name fallback)
1897 requested (coerce-name requested))
1898 (when (equal requested fallback)
1899 (let ((registered (cdr (gethash fallback *defined-systems*))))
1901 (apply 'make-instance 'system
1902 :name fallback :source-file source-file keys)))))
1904 (defun* sysdef-find-asdf (name)
1905 ;; Bug: :version *asdf-version* won't be updated when ASDF is updated.
1906 (find-system-fallback name "asdf" :version *asdf-version*))
1909 ;;;; -------------------------------------------------------------------------
1910 ;;;; Finding components
1912 (defmethod find-component ((base string) path)
1913 (let ((s (find-system base nil)))
1914 (and s (find-component s path))))
1916 (defmethod find-component ((base symbol) path)
1918 (base (find-component (coerce-name base) path))
1919 (path (find-component path nil))
1922 (defmethod find-component ((base cons) path)
1923 (find-component (car base) (cons (cdr base) path)))
1925 (defmethod find-component ((module module) (name string))
1926 (unless (slot-boundp module 'components-by-name) ;; SBCL may miss the u-i-f-r-c method!!!
1927 (compute-module-components-by-name module))
1928 (values (gethash name (module-components-by-name module))))
1930 (defmethod find-component ((component component) (name symbol))
1932 (find-component component (coerce-name name))
1935 (defmethod find-component ((module module) (name cons))
1936 (find-component (find-component module (car name)) (cdr name)))
1939 ;;; component subclasses
1941 (defclass source-file (component)
1942 ((type :accessor source-file-explicit-type :initarg :type :initform nil)))
1944 (defclass cl-source-file (source-file)
1945 ((type :initform "lisp")))
1946 (defclass cl-source-file.cl (cl-source-file)
1947 ((type :initform "cl")))
1948 (defclass cl-source-file.lsp (cl-source-file)
1949 ((type :initform "lsp")))
1950 (defclass c-source-file (source-file)
1951 ((type :initform "c")))
1952 (defclass java-source-file (source-file)
1953 ((type :initform "java")))
1954 (defclass static-file (source-file) ())
1955 (defclass doc-file (static-file) ())
1956 (defclass html-file (doc-file)
1957 ((type :initform "html")))
1959 (defmethod source-file-type ((component module) (s module))
1960 (declare (ignorable component s))
1962 (defmethod source-file-type ((component source-file) (s module))
1963 (declare (ignorable s))
1964 (source-file-explicit-type component))
1966 (defmethod component-relative-pathname ((component component))
1968 (or (slot-value component 'relative-pathname)
1969 (component-name component))
1970 :type (source-file-type component (component-system component))
1971 :defaults (component-parent-pathname component)))
1973 ;;;; -------------------------------------------------------------------------
1976 ;;; one of these is instantiated whenever #'operate is called
1978 (defclass operation ()
1979 (;; as of danb's 2003-03-16 commit e0d02781, :force can be:
1980 ;; T to force the inside of the specified system,
1981 ;; but not recurse to other systems we depend on.
1982 ;; :ALL (or any other atom) to force all systems
1983 ;; including other systems we depend on.
1984 ;; (SYSTEM1 SYSTEM2 ... SYSTEMN)
1985 ;; to force systems named in a given list
1986 ;; However, but this feature has only ever worked but starting with ASDF 2.014.5
1987 (forced :initform nil :initarg :force :accessor operation-forced)
1988 (forced-not :initform nil :initarg :force-not :accessor operation-forced-not)
1989 (original-initargs :initform nil :initarg :original-initargs
1990 :accessor operation-original-initargs)
1991 (visited-nodes :initform (make-hash-table :test 'equal) :accessor operation-visited-nodes)
1992 (visiting-nodes :initform (make-hash-table :test 'equal) :accessor operation-visiting-nodes)
1993 (parent :initform nil :initarg :parent :accessor operation-parent)))
1995 (defmethod print-object ((o operation) stream)
1996 (print-unreadable-object (o stream :type t :identity t)
1998 (prin1 (operation-original-initargs o) stream))))
2000 (defmethod shared-initialize :after ((operation operation) slot-names
2001 &key force force-not
2003 ;; the &allow-other-keys disables initarg validity checking
2004 (declare (ignorable operation slot-names force force-not))
2005 (macrolet ((frob (x) ;; normalize forced and forced-not slots
2006 `(when (consp (,x operation))
2007 (setf (,x operation)
2008 (mapcar #'coerce-name (,x operation))))))
2009 (frob operation-forced) (frob operation-forced-not))
2012 (defun* node-for (o c)
2013 (cons (class-name (class-of o)) c))
2015 (defmethod operation-ancestor ((operation operation))
2016 (aif (operation-parent operation)
2017 (operation-ancestor it)
2021 (defun* make-sub-operation (c o dep-c dep-o)
2022 "C is a component, O is an operation, DEP-C is another
2023 component, and DEP-O, confusingly enough, is an operation
2024 class specifier, not an operation."
2025 (let* ((args (copy-list (operation-original-initargs o)))
2026 (force-p (getf args :force)))
2027 ;; note explicit comparison with T: any other non-NIL force value
2028 ;; (e.g. :recursive) will pass through
2029 (cond ((and (null (component-parent c))
2030 (null (component-parent dep-c))
2031 (not (eql c dep-c)))
2032 (when (eql force-p t)
2033 (setf (getf args :force) nil))
2034 (apply 'make-instance dep-o
2036 :original-initargs args args))
2037 ((subtypep (type-of o) dep-o)
2040 (apply 'make-instance dep-o
2041 :parent o :original-initargs args args)))))
2044 (defmethod visit-component ((o operation) (c component) data)
2045 (unless (component-visited-p o c)
2046 (setf (gethash (node-for o c)
2047 (operation-visited-nodes (operation-ancestor o)))
2050 (defmethod component-visited-p ((o operation) (c component))
2051 (gethash (node-for o c)
2052 (operation-visited-nodes (operation-ancestor o))))
2054 (defmethod (setf visiting-component) (new-value operation component)
2055 ;; MCL complains about unused lexical variables
2056 (declare (ignorable operation component))
2059 (defmethod (setf visiting-component) (new-value (o operation) (c component))
2060 (let ((node (node-for o c))
2061 (a (operation-ancestor o)))
2063 (setf (gethash node (operation-visiting-nodes a)) t)
2064 (remhash node (operation-visiting-nodes a)))
2067 (defmethod component-visiting-p ((o operation) (c component))
2068 (let ((node (node-for o c)))
2069 (gethash node (operation-visiting-nodes (operation-ancestor o)))))
2071 (defmethod component-depends-on ((op-spec symbol) (c component))
2072 ;; Note: we go from op-spec to operation via make-instance
2073 ;; to allow for specialization through defmethod's, even though
2074 ;; it's a detour in the default case below.
2075 (component-depends-on (make-instance op-spec) c))
2077 (defmethod component-depends-on ((o operation) (c component))
2078 (cdr (assoc (type-of o) (component-in-order-to c))))
2080 (defmethod component-self-dependencies ((o operation) (c component))
2082 #'(lambda (x) (member (component-name c) (cdr x) :test #'string=))
2083 (component-depends-on o c)))
2085 (defmethod input-files ((operation operation) (c component))
2086 (let ((parent (component-parent c))
2087 (self-deps (component-self-dependencies operation c)))
2089 (mapcan #'(lambda (dep)
2090 (destructuring-bind (op name) dep
2091 (output-files (make-instance op)
2092 (find-component parent name))))
2094 ;; no previous operations needed? I guess we work with the
2095 ;; original source file, then
2096 (list (component-pathname c)))))
2098 (defmethod input-files ((operation operation) (c module))
2099 (declare (ignorable operation c))
2102 (defmethod component-operation-time (o c)
2103 (gethash (type-of o) (component-operation-times c)))
2105 (defmethod operation-done-p ((o operation) (c component))
2106 (let ((out-files (output-files o c))
2107 (in-files (input-files o c))
2108 (op-time (component-operation-time o c)))
2109 (flet ((earliest-out ()
2110 (reduce #'min (mapcar #'safe-file-write-date out-files)))
2112 (reduce #'max (mapcar #'safe-file-write-date in-files))))
2114 ((and (not in-files) (not out-files))
2115 ;; arbitrary decision: an operation that uses nothing to
2116 ;; produce nothing probably isn't doing much.
2117 ;; e.g. operations on systems, modules that have no immediate action,
2118 ;; but are only meaningful through traversed dependencies
2121 ;; an operation without output-files is probably meant
2122 ;; for its side-effects in the current image,
2123 ;; assumed to be idem-potent,
2124 ;; e.g. LOAD-OP or LOAD-SOURCE-OP of some CL-SOURCE-FILE.
2125 (and op-time (>= op-time (latest-in))))
2127 ;; an operation with output-files and no input-files
2128 ;; is probably meant for its side-effects on the file-system,
2129 ;; assumed to have to be done everytime.
2130 ;; (I don't think there is any such case in ASDF unless extended)
2133 ;; an operation with both input and output files is assumed
2134 ;; as computing the latter from the former,
2135 ;; assumed to have been done if the latter are all older
2137 ;; e.g. COMPILE-OP of some CL-SOURCE-FILE.
2138 ;; We use >= instead of > to play nice with generated files.
2139 ;; This opens a race condition if an input file is changed
2140 ;; after the output is created but within the same second
2141 ;; of filesystem time; but the same race condition exists
2142 ;; whenever the computation from input to output takes more
2143 ;; than one second of filesystem time (or just crosses the
2144 ;; second). So that's cool.
2146 (every #'probe-file* in-files)
2147 (every #'probe-file* out-files)
2148 (>= (earliest-out) (latest-in))))))))
2152 ;;; For 1.700 I've done my best to refactor TRAVERSE
2153 ;;; by splitting it up in a bunch of functions,
2154 ;;; so as to improve the collection and use-detection algorithm. --fare
2155 ;;; The protocol is as follows: we pass around operation, dependency,
2156 ;;; bunch of other stuff, and a force argument. Return a force flag.
2157 ;;; The returned flag is T if anything has changed that requires a rebuild.
2158 ;;; The force argument is a list of components that will require a rebuild
2159 ;;; if the flag is T, at which point whoever returns the flag has to
2160 ;;; mark them all as forced, and whoever recurses again can use a NIL list
2161 ;;; as a further argument.
2163 (defvar *forcing* nil
2164 "This dynamically-bound variable is used to force operations in
2165 recursive calls to traverse.")
2167 (defgeneric* do-traverse (operation component collect))
2169 (defun* resolve-dependency-name (component name &optional version)
2173 (let ((comp (find-component (component-parent component) name)))
2175 (error 'missing-dependency
2176 :required-by component
2179 (unless (version-satisfies comp version)
2180 (error 'missing-dependency-of-version
2181 :required-by component
2187 (format s (compatfmt "~@<Retry loading ~3i~_~A.~@:>") name))
2191 (and (typep c 'missing-dependency)
2192 (eq (missing-required-by c) component)
2193 (equal (missing-requires c) name))))))))
2195 (defun* resolve-dependency-spec (component dep-spec)
2198 (resolve-dependency-name component dep-spec))
2199 ;; Structured dependencies --- this parses keywords.
2200 ;; The keywords could conceivably be broken out and cleanly (extensibly)
2201 ;; processed by EQL methods. But for now, here's what we've got.
2202 ((eq :version (first dep-spec))
2203 ;; https://bugs.launchpad.net/asdf/+bug/527788
2204 (resolve-dependency-name component (second dep-spec) (third dep-spec)))
2205 ((eq :feature (first dep-spec))
2206 ;; This particular subform is not documented and
2207 ;; has always been broken in the past.
2208 ;; Therefore no one uses it, and I'm cerroring it out,
2210 ;; See https://bugs.launchpad.net/asdf/+bug/518467
2211 (cerror "Continue nonetheless."
2212 "Congratulations, you're the first ever user of FEATURE dependencies! Please contact the asdf-devel mailing-list.")
2213 (when (find (second dep-spec) *features* :test 'string-equal)
2214 (resolve-dependency-name component (third dep-spec))))
2216 (error (compatfmt "~@<Bad dependency ~s. Dependencies must be (:version <name> <version>), (:feature <feature> <name>), or <name>.~@:>") dep-spec))))
2218 (defun* do-one-dep (op c collect dep-op dep-c)
2219 ;; Collects a partial plan for performing dep-op on dep-c
2220 ;; as dependencies of a larger plan involving op and c.
2221 ;; Returns t if this should force recompilation of those who depend on us.
2222 ;; dep-op is an operation class name (not an operation object),
2223 ;; whereas dep-c is a component object.n
2224 (do-traverse (make-sub-operation c op dep-c dep-op) dep-c collect))
2226 (defun* do-dep (op c collect dep-op-spec dep-c-specs)
2227 ;; Collects a partial plan for performing dep-op-spec on each of dep-c-specs
2228 ;; as dependencies of a larger plan involving op and c.
2229 ;; Returns t if this should force recompilation of those who depend on us.
2230 ;; dep-op-spec is either an operation class name (not an operation object),
2231 ;; or the magic symbol asdf:feature.
2232 ;; If dep-op-spec is asdf:feature, then the first dep-c-specs is a keyword,
2233 ;; and the plan will succeed if that keyword is present in *feature*,
2234 ;; or fail if it isn't
2235 ;; (at which point c's :if-component-dep-fails will kick in).
2236 ;; If dep-op-spec is an operation class name,
2237 ;; then dep-c-specs specifies a list of sibling component of c,
2238 ;; as per resolve-dependency-spec, such that operating op on c
2239 ;; depends on operating dep-op-spec on each of them.
2240 (cond ((eq dep-op-spec 'feature)
2241 (if (member (car dep-c-specs) *features*)
2243 (error 'missing-dependency
2245 :requires (list :feature (car dep-c-specs)))))
2248 (dolist (d dep-c-specs)
2249 (when (do-one-dep op c collect dep-op-spec
2250 (resolve-dependency-spec c d))
2254 (defvar *visit-count* 0) ; counter that allows to sort nodes from operation-visited-nodes
2256 (defun* do-collect (collect x)
2257 (funcall collect x))
2259 (defmethod do-traverse ((operation operation) (c component) collect)
2260 (let ((*forcing* *forcing*)
2261 (flag nil)) ;; return value: must we rebuild this and its dependencies?
2266 (update-flag (do-dep operation c collect op comp))))
2267 ;; Have we been visited yet? If so, just process the result.
2268 (aif (component-visited-p operation c)
2270 (update-flag (cdr it))
2271 (return-from do-traverse flag)))
2273 (when (component-visiting-p operation c)
2274 (error 'circular-dependency :components (list c)))
2275 (setf (visiting-component operation c) t)
2278 (when (typep c 'system) ;; systems can be forced or forced-not
2279 (let ((ancestor (operation-ancestor operation)))
2281 (and f (or (not (consp f)) ;; T or :ALL
2282 (member (component-name c) f :test #'equal)))))
2284 ((match? (operation-forced ancestor))
2286 ((match? (operation-forced-not ancestor))
2288 ;; first we check and do all the dependencies for the module.
2289 ;; Operations planned in this loop will show up
2290 ;; in the results, and are consumed below.
2291 (let ((*forcing* nil))
2292 ;; upstream dependencies are never forced to happen just because
2293 ;; the things that depend on them are....
2295 :for (required-op . deps) :in (component-depends-on operation c)
2296 :do (dep required-op deps)))
2299 (when (typep c 'module)
2300 (let ((at-least-one nil)
2301 ;; This is set based on the results of the
2302 ;; dependencies and whether we are in the
2303 ;; context of a *forcing* call...
2304 ;; inter-system dependencies do NOT trigger
2305 ;; building components
2308 (and flag (not (typep c 'system)))))
2310 (while-collecting (internal-collect)
2311 (dolist (kid (module-components c))
2314 (do-traverse operation kid #'internal-collect))
2316 (missing-dependency (condition)
2317 (when (eq (module-if-component-dep-fails c)
2320 (setf error condition))
2322 (declare (ignore c))
2323 (setf at-least-one t))))
2324 (when (and (eq (module-if-component-dep-fails c)
2328 (update-flag (or *forcing* (not (operation-done-p operation c))))
2329 ;; For sub-operations, check whether
2330 ;; the original ancestor operation was forced,
2331 ;; or names us amongst an explicit list of things to force...
2332 ;; except that this check doesn't distinguish
2333 ;; between all the things with a given name. Sigh.
2336 (let ((do-first (cdr (assoc (class-name (class-of operation))
2337 (component-do-first c)))))
2338 (loop :for (required-op . deps) :in do-first
2339 :do (do-dep operation c collect required-op deps)))
2340 (do-collect collect (vector module-ops))
2341 (do-collect collect (cons operation c)))))
2342 (setf (visiting-component operation c) nil)))
2343 (visit-component operation c (when flag (incf *visit-count*)))
2346 (defun* flatten-tree (l)
2347 ;; You collected things into a list.
2348 ;; Most elements are just things to collect again.
2349 ;; A (simple-vector 1) indicate that you should recurse into its contents.
2350 ;; This way, in two passes (rather than N being the depth of the tree),
2351 ;; you can collect things with marginally constant-time append,
2352 ;; achieving linear time collection instead of quadratic time.
2353 (while-collecting (c)
2355 (if (typep x '(simple-vector 1))
2359 (dolist (x l) (r x))))
2362 (defmethod traverse ((operation operation) (c component))
2364 (while-collecting (collect)
2365 (let ((*visit-count* 0))
2366 (do-traverse operation c #'collect)))))
2368 (defmethod perform ((operation operation) (c source-file))
2370 (compatfmt "~@<Required method PERFORM not implemented for operation ~A, component ~A~@:>")
2371 (class-of operation) (class-of c)))
2373 (defmethod perform ((operation operation) (c module))
2374 (declare (ignorable operation c))
2377 (defmethod mark-operation-done ((operation operation) (c component))
2378 (setf (gethash (type-of operation) (component-operation-times c))
2380 (cons (get-universal-time)
2381 (mapcar #'safe-file-write-date (input-files operation c))))))
2383 (defmethod perform-with-restarts (operation component)
2384 ;; TOO verbose, especially as the default. Add your own :before method
2385 ;; to perform-with-restart or perform if you want that:
2386 #|(when *asdf-verbose* (explain operation component))|#
2387 (perform operation component))
2389 (defmethod perform-with-restarts :around (operation component)
2392 (return (call-next-method))
2396 (format s (compatfmt "~@<Retry ~A.~@:>")
2397 (operation-description operation component))))
2401 (format s (compatfmt "~@<Continue, treating ~A as having been successful.~@:>")
2402 (operation-description operation component)))
2403 (mark-operation-done operation component)
2406 (defmethod explain ((operation operation) (component component))
2407 (asdf-message (compatfmt "~&~@<; ~@;~A~:>~%")
2408 (operation-description operation component)))
2410 (defmethod operation-description (operation component)
2411 (format nil (compatfmt "~@<~A on ~A~@:>")
2412 (class-of operation) component))
2414 ;;;; -------------------------------------------------------------------------
2417 (defclass compile-op (operation)
2418 ((proclamations :initarg :proclamations :accessor compile-op-proclamations :initform nil)
2419 (on-warnings :initarg :on-warnings :accessor operation-on-warnings
2420 :initform *compile-file-warnings-behaviour*)
2421 (on-failure :initarg :on-failure :accessor operation-on-failure
2422 :initform *compile-file-failure-behaviour*)
2423 (flags :initarg :flags :accessor compile-op-flags
2426 (defun* output-file (operation component)
2427 "The unique output file of performing OPERATION on COMPONENT"
2428 (let ((files (output-files operation component)))
2429 (assert (length=n-p files 1))
2432 (defun* ensure-all-directories-exist (pathnames)
2433 (dolist (pathname pathnames)
2434 (ensure-directories-exist (translate-logical-pathname pathname))))
2436 (defmethod perform :before ((operation compile-op) (c source-file))
2437 (ensure-all-directories-exist (output-files operation c)))
2439 (defmethod perform :after ((operation operation) (c component))
2440 (mark-operation-done operation c))
2442 (defgeneric* around-compile-hook (component))
2443 (defgeneric* call-with-around-compile-hook (component thunk))
2445 (defmethod around-compile-hook ((c component))
2447 ((slot-boundp c 'around-compile)
2448 (slot-value c 'around-compile))
2449 ((component-parent c)
2450 (around-compile-hook (component-parent c)))))
2452 (defun ensure-function (fun &key (package :asdf))
2454 ((or symbol function) fun)
2455 (cons (eval `(function ,fun)))
2456 (string (eval `(function ,(with-standard-io-syntax
2457 (let ((*package* (find-package package)))
2458 (read-from-string fun))))))))
2460 (defmethod call-with-around-compile-hook ((c component) thunk)
2461 (let ((hook (around-compile-hook c)))
2463 (funcall (ensure-function hook) thunk)
2466 ;;; perform is required to check output-files to find out where to put
2467 ;;; its answers, in case it has been overridden for site policy
2468 (defmethod perform ((operation compile-op) (c cl-source-file))
2469 (let ((source-file (component-pathname c))
2470 ;; on some implementations, there are more than one output-file,
2471 ;; but the first one should always be the primary fasl that gets loaded.
2472 (output-file (first (output-files operation c)))
2473 (*compile-file-warnings-behaviour* (operation-on-warnings operation))
2474 (*compile-file-failure-behaviour* (operation-on-failure operation)))
2475 (multiple-value-bind (output warnings-p failure-p)
2476 (call-with-around-compile-hook
2477 c #'(lambda (&rest flags)
2478 (apply *compile-op-compile-file-function* source-file
2479 :output-file output-file
2480 :external-format (component-external-format c)
2481 (append flags (compile-op-flags operation)))))
2483 (error 'compile-error :component c :operation operation))
2485 (case (operation-on-failure operation)
2487 (compatfmt "~@<COMPILE-FILE failed while performing ~A on ~A.~@:>")
2489 (:error (error 'compile-failed :component c :operation operation))
2492 (case (operation-on-warnings operation)
2494 (compatfmt "~@<COMPILE-FILE warned while performing ~A on ~A.~@:>")
2496 (:error (error 'compile-warned :component c :operation operation))
2499 (defmethod output-files ((operation compile-op) (c cl-source-file))
2500 (declare (ignorable operation))
2501 (let* ((p (lispize-pathname (component-pathname c)))
2502 (f (compile-file-pathname ;; fasl
2503 p #+mkcl :fasl-p #+mkcl t #+ecl :type #+ecl :fasl))
2504 #+mkcl (o (compile-file-pathname p :fasl-p nil))) ;; object file
2505 #+ecl (if (use-ecl-byte-compiler-p)
2507 (list (compile-file-pathname p :type :object) f))
2509 #-(or ecl mkcl) (list f)))
2511 (defmethod perform ((operation compile-op) (c static-file))
2512 (declare (ignorable operation c))
2515 (defmethod output-files ((operation compile-op) (c static-file))
2516 (declare (ignorable operation c))
2519 (defmethod input-files ((operation compile-op) (c static-file))
2520 (declare (ignorable operation c))
2523 (defmethod operation-description ((operation compile-op) component)
2524 (declare (ignorable operation))
2525 (format nil (compatfmt "~@<compiling ~3i~_~A~@:>") component))
2527 (defmethod operation-description ((operation compile-op) (component module))
2528 (declare (ignorable operation))
2529 (format nil (compatfmt "~@<compiled ~3i~_~A~@:>") component))
2532 ;;;; -------------------------------------------------------------------------
2535 (defclass basic-load-op (operation) ())
2537 (defclass load-op (basic-load-op) ())
2539 (defmethod perform-with-restarts ((o load-op) (c cl-source-file))
2542 (return (call-next-method))
2545 (format s "Recompile ~a and try loading it again"
2546 (component-name c)))
2547 (perform (make-sub-operation c o c 'compile-op) c)))))
2549 (defmethod perform ((o load-op) (c cl-source-file))
2554 (loop :for i :in (input-files o c)
2555 :unless (string= (pathname-type i) "fas")
2556 :collect (compile-file-pathname (lispize-pathname i)))))
2558 (defmethod perform ((operation load-op) (c static-file))
2559 (declare (ignorable operation c))
2562 (defmethod operation-done-p ((operation load-op) (c static-file))
2563 (declare (ignorable operation c))
2566 (defmethod output-files ((operation operation) (c component))
2567 (declare (ignorable operation c))
2570 (defmethod component-depends-on ((operation load-op) (c component))
2571 (declare (ignorable operation))
2572 (cons (list 'compile-op (component-name c))
2573 (call-next-method)))
2575 (defmethod operation-description ((operation load-op) component)
2576 (declare (ignorable operation))
2577 (format nil (compatfmt "~@<loading ~3i~_~A~@:>")
2580 (defmethod operation-description ((operation load-op) (component cl-source-file))
2581 (declare (ignorable operation))
2582 (format nil (compatfmt "~@<loading FASL for ~3i~_~A~@:>")
2585 (defmethod operation-description ((operation load-op) (component module))
2586 (declare (ignorable operation))
2587 (format nil (compatfmt "~@<loaded ~3i~_~A~@:>")
2590 ;;;; -------------------------------------------------------------------------
2593 (defclass load-source-op (basic-load-op) ())
2595 (defmethod perform ((o load-source-op) (c cl-source-file))
2596 (declare (ignorable o))
2597 (let ((source (component-pathname c)))
2598 (setf (component-property c 'last-loaded-as-source)
2599 (and (call-with-around-compile-hook
2600 c #'(lambda () (load source :external-format (component-external-format c))))
2601 (get-universal-time)))))
2603 (defmethod perform ((operation load-source-op) (c static-file))
2604 (declare (ignorable operation c))
2607 (defmethod output-files ((operation load-source-op) (c component))
2608 (declare (ignorable operation c))
2611 ;;; FIXME: We simply copy load-op's dependencies. This is Just Not Right.
2612 (defmethod component-depends-on ((o load-source-op) (c component))
2613 (declare (ignorable o))
2614 (loop :with what-would-load-op-do = (component-depends-on 'load-op c)
2615 :for (op . co) :in what-would-load-op-do
2616 :when (eq op 'load-op) :collect (cons 'load-source-op co)))
2618 (defmethod operation-done-p ((o load-source-op) (c source-file))
2619 (declare (ignorable o))
2620 (if (or (not (component-property c 'last-loaded-as-source))
2621 (> (safe-file-write-date (component-pathname c))
2622 (component-property c 'last-loaded-as-source)))
2625 (defmethod operation-description ((operation load-source-op) component)
2626 (declare (ignorable operation))
2627 (format nil (compatfmt "~@<Loading source of ~3i~_~A~@:>")
2630 (defmethod operation-description ((operation load-source-op) (component module))
2631 (declare (ignorable operation))
2632 (format nil (compatfmt "~@<Loaded source of ~3i~_~A~@:>") component))
2635 ;;;; -------------------------------------------------------------------------
2638 (defclass test-op (operation) ())
2640 (defmethod perform ((operation test-op) (c component))
2641 (declare (ignorable operation c))
2644 (defmethod operation-done-p ((operation test-op) (c system))
2645 "Testing a system is _never_ done."
2646 (declare (ignorable operation c))
2649 (defmethod component-depends-on :around ((o test-op) (c system))
2650 (declare (ignorable o))
2651 (cons `(load-op ,(component-name c)) (call-next-method)))
2654 ;;;; -------------------------------------------------------------------------
2655 ;;;; Invoking Operations
2657 (defgeneric* operate (operation-class system &key &allow-other-keys))
2658 (defgeneric* perform-plan (plan &key))
2660 ;;;; Separating this into a different function makes it more forward-compatible
2661 (defun* cleanup-upgraded-asdf (old-version)
2662 (let ((new-version (asdf-version)))
2663 (unless (equal old-version new-version)
2665 ((version-satisfies new-version old-version)
2666 (asdf-message (compatfmt "~&~@<; ~@;Upgraded ASDF from version ~A to version ~A~@:>~%")
2667 old-version new-version))
2668 ((version-satisfies old-version new-version)
2669 (warn (compatfmt "~&~@<; ~@;Downgraded ASDF from version ~A to version ~A~@:>~%")
2670 old-version new-version))
2672 (asdf-message (compatfmt "~&~@<; ~@;Changed ASDF from version ~A to incompatible version ~A~@:>~%")
2673 old-version new-version)))
2674 (let ((asdf (funcall (find-symbol* 'find-system :asdf) :asdf)))
2675 ;; Invalidate all systems but ASDF itself.
2676 (setf *defined-systems* (make-defined-systems-table))
2677 (register-system asdf)
2678 ;; If we're in the middle of something, restart it.
2679 (when *systems-being-defined*
2680 (let ((l (loop :for name :being :the :hash-keys :of *systems-being-defined* :collect name)))
2681 (clrhash *systems-being-defined*)
2682 (dolist (s l) (find-system s nil))))
2685 ;;;; Try to upgrade of ASDF. If a different version was used, return T.
2686 ;;;; We need do that before we operate on anything that depends on ASDF.
2687 (defun* upgrade-asdf ()
2688 (let ((version (asdf-version)))
2689 (handler-bind (((or style-warning warning) #'muffle-warning))
2690 (operate 'load-op :asdf :verbose nil))
2691 (cleanup-upgraded-asdf version)))
2693 (defmethod perform-plan ((steps list) &key)
2694 (let ((*package* *package*)
2695 (*readtable* *readtable*))
2696 (with-compilation-unit ()
2697 (loop :for (op . component) :in steps :do
2698 (perform-with-restarts op component)))))
2700 (defmethod operate (operation-class system &rest args
2701 &key ((:verbose *asdf-verbose*) *asdf-verbose*) version force
2703 (declare (ignore force))
2704 (with-system-definitions ()
2705 (let* ((op (apply 'make-instance operation-class
2706 :original-initargs args
2708 (*verbose-out* (if *asdf-verbose* *standard-output* (make-broadcast-stream)))
2709 (system (etypecase system
2711 ((or string symbol) (find-system system)))))
2712 (unless (version-satisfies system version)
2713 (error 'missing-component-of-version :requires system :version version))
2714 (let ((steps (traverse op system)))
2715 (when (and (not (equal '("asdf") (component-find-path system)))
2716 (find '("asdf") (mapcar 'cdr steps)
2717 :test 'equal :key 'component-find-path)
2719 ;; If we needed to upgrade ASDF to achieve our goal,
2720 ;; then do it specially as the first thing, then
2721 ;; invalidate all existing system
2722 ;; retry the whole thing with the new OPERATE function,
2723 ;; which on some implementations
2724 ;; has a new symbol shadowing the current one.
2725 (return-from operate
2726 (apply (find-symbol* 'operate :asdf) operation-class system args)))
2727 (perform-plan steps)
2728 (values op steps)))))
2730 (defun* oos (operation-class system &rest args &key force verbose version
2732 (declare (ignore force verbose version))
2733 (apply 'operate operation-class system args))
2735 (let ((operate-docstring
2736 "Operate does three things:
2738 1. It creates an instance of OPERATION-CLASS using any keyword parameters
2740 2. It finds the asdf-system specified by SYSTEM (possibly loading
2742 3. It then calls TRAVERSE with the operation and system as arguments
2744 The traverse operation is wrapped in WITH-COMPILATION-UNIT and error
2745 handling code. If a VERSION argument is supplied, then operate also
2746 ensures that the system found satisfies it using the VERSION-SATISFIES
2749 Note that dependencies may cause the operation to invoke other
2750 operations on the system or its components: the new operations will be
2751 created with the same initargs as the original one.
2753 (setf (documentation 'oos 'function)
2755 "Short for _operate on system_ and an alias for the OPERATE function.~%~%~a"
2757 (setf (documentation 'operate 'function)
2760 (defun* load-system (system &rest keys &key force verbose version &allow-other-keys)
2761 "Shorthand for `(operate 'asdf:load-op system)`.
2762 See OPERATE for details."
2763 (declare (ignore force verbose version))
2764 (apply 'operate *load-system-operation* system keys)
2767 (defun* load-systems (&rest systems)
2768 (map () 'load-system systems))
2770 (defun component-loaded-p (c)
2771 (and (gethash 'load-op (component-operation-times (find-component c nil))) t))
2773 (defun loaded-systems ()
2774 (remove-if-not 'component-loaded-p (registered-systems)))
2776 (defun require-system (s &rest keys &key &allow-other-keys)
2777 (apply 'load-system s :force-not (loaded-systems) keys))
2779 (defun* compile-system (system &rest args &key force verbose version
2781 "Shorthand for `(asdf:operate 'asdf:compile-op system)`. See OPERATE
2783 (declare (ignore force verbose version))
2784 (apply 'operate 'compile-op system args)
2787 (defun* test-system (system &rest args &key force verbose version
2789 "Shorthand for `(asdf:operate 'asdf:test-op system)`. See OPERATE for
2791 (declare (ignore force verbose version))
2792 (apply 'operate 'test-op system args)
2795 ;;;; -------------------------------------------------------------------------
2798 (defun* load-pathname ()
2799 (resolve-symlinks* (or *load-pathname* *compile-file-pathname*)))
2801 (defun* determine-system-pathname (pathname)
2802 ;; The defsystem macro calls us to determine
2803 ;; the pathname of a system as follows:
2804 ;; 1. the one supplied,
2805 ;; 2. derived from *load-pathname* via load-pathname
2806 ;; 3. taken from the *default-pathname-defaults* via default-directory
2807 (let* ((file-pathname (load-pathname))
2808 (directory-pathname (and file-pathname (pathname-directory-pathname file-pathname))))
2809 (or (and pathname (subpathname directory-pathname pathname :type :directory))
2811 (default-directory))))
2813 (defun* find-class* (x &optional (errorp t) environment)
2815 ((or standard-class built-in-class) x)
2816 (symbol (find-class x errorp environment))))
2818 (defun* class-for-type (parent type)
2819 (or (loop :for symbol :in (list
2821 (find-symbol* type *package*)
2822 (find-symbol* type :asdf))
2823 :for class = (and symbol (find-class symbol nil))
2825 (#-cormanlisp subtypep #+cormanlisp cl::subclassp
2826 class (find-class 'component)))
2828 (and (eq type :file)
2830 (or (loop :for module = parent :then (component-parent module) :while module
2831 :thereis (module-default-component-class module))
2832 *default-component-class*) nil))
2833 (sysdef-error "don't recognize component type ~A" type)))
2835 (defun* maybe-add-tree (tree op1 op2 c)
2836 "Add the node C at /OP1/OP2 in TREE, unless it's there already.
2837 Returns the new tree (which probably shares structure with the old one)"
2838 (let ((first-op-tree (assoc op1 tree)))
2841 (aif (assoc op2 (cdr first-op-tree))
2842 (if (find c (cdr it) :test #'equal)
2844 (setf (cdr it) (cons c (cdr it))))
2845 (setf (cdr first-op-tree)
2846 (acons op2 (list c) (cdr first-op-tree))))
2848 (acons op1 (list (list op2 c)) tree))))
2850 (defun* union-of-dependencies (&rest deps)
2851 (let ((new-tree nil))
2853 (dolist (op-tree dep)
2854 (dolist (op (cdr op-tree))
2855 (dolist (c (cdr op))
2857 (maybe-add-tree new-tree (car op-tree) (car op) c))))))
2861 (defvar *serial-depends-on* nil)
2863 (defun* sysdef-error-component (msg type name value)
2864 (sysdef-error (strcat msg (compatfmt "~&~@<The value specified for ~(~A~) ~A is ~S~@:>"))
2867 (defun* check-component-input (type name weakly-depends-on
2868 depends-on components in-order-to)
2869 "A partial test of the values of a component."
2870 (unless (listp depends-on)
2871 (sysdef-error-component ":depends-on must be a list."
2872 type name depends-on))
2873 (unless (listp weakly-depends-on)
2874 (sysdef-error-component ":weakly-depends-on must be a list."
2875 type name weakly-depends-on))
2876 (unless (listp components)
2877 (sysdef-error-component ":components must be NIL or a list of components."
2878 type name components))
2879 (unless (and (listp in-order-to) (listp (car in-order-to)))
2880 (sysdef-error-component ":in-order-to must be NIL or a list of components."
2881 type name in-order-to)))
2883 (defun* %remove-component-inline-methods (component)
2884 (dolist (name +asdf-methods+)
2886 ;; this is inefficient as most of the stored
2887 ;; methods will not be for this particular gf
2888 ;; But this is hardly performance-critical
2890 (remove-method (symbol-function name) m))
2891 (component-inline-methods component)))
2892 ;; clear methods, then add the new ones
2893 (setf (component-inline-methods component) nil))
2895 (defun* %define-component-inline-methods (ret rest)
2896 (dolist (name +asdf-methods+)
2897 (let ((keyword (intern (symbol-name name) :keyword)))
2898 (loop :for data = rest :then (cddr data)
2899 :for key = (first data)
2900 :for value = (second data)
2902 :when (eq key keyword) :do
2903 (destructuring-bind (op qual (o c) &body body) value
2905 (eval `(defmethod ,name ,qual ((,o ,op) (,c (eql ,ret)))
2907 (component-inline-methods ret)))))))
2909 (defun* %refresh-component-inline-methods (component rest)
2910 (%remove-component-inline-methods component)
2911 (%define-component-inline-methods component rest))
2913 (defun* parse-component-form (parent options)
2915 (type name &rest rest &key
2916 ;; the following list of keywords is reproduced below in the
2917 ;; remove-keys form. important to keep them in sync
2919 perform explain output-files operation-done-p
2920 weakly-depends-on depends-on serial in-order-to
2922 (version nil versionp)
2924 &allow-other-keys) options
2925 (declare (ignorable perform explain output-files operation-done-p))
2926 (check-component-input type name weakly-depends-on depends-on components in-order-to)
2929 (find-component parent name)
2930 ;; ignore the same object when rereading the defsystem
2932 (typep (find-component parent name)
2933 (class-for-type parent type))))
2934 (error 'duplicate-names :name name))
2937 (unless (parse-version version nil)
2938 (warn (compatfmt "~@<Invalid version ~S for component ~S~@[ of ~S~]~@:>")
2939 version name parent)))
2941 (let* ((args (list* :name (coerce-name name)
2945 '(components pathname
2946 perform explain output-files operation-done-p
2947 weakly-depends-on depends-on serial in-order-to)
2949 (ret (find-component parent name)))
2950 (when weakly-depends-on
2951 (appendf depends-on (remove-if (complement #'(lambda (x) (find-system x nil))) weakly-depends-on)))
2952 (when *serial-depends-on*
2953 (push *serial-depends-on* depends-on))
2954 (if ret ; preserve identity
2955 (apply 'reinitialize-instance ret args)
2956 (setf ret (apply 'make-instance (class-for-type parent type) args)))
2957 (component-pathname ret) ; eagerly compute the absolute pathname
2958 (when (typep ret 'module)
2959 (let ((*serial-depends-on* nil))
2960 (setf (module-components ret)
2962 :for c-form :in components
2963 :for c = (parse-component-form ret c-form)
2964 :for name = (component-name c)
2966 :when serial :do (setf *serial-depends-on* name))))
2967 (compute-module-components-by-name ret))
2969 (setf (component-load-dependencies ret) depends-on) ;; Used by POIU
2971 (setf (component-in-order-to ret)
2972 (union-of-dependencies
2974 `((compile-op (compile-op ,@depends-on))
2975 (load-op (load-op ,@depends-on)))))
2976 (setf (component-do-first ret)
2977 (union-of-dependencies
2979 `((compile-op (load-op ,@depends-on)))))
2981 (%refresh-component-inline-methods ret rest)
2984 (defun* reset-system (system &rest keys &key &allow-other-keys)
2985 (change-class (change-class system 'proto-system) 'system)
2986 (apply 'reinitialize-instance system keys))
2988 (defun* do-defsystem (name &rest options
2989 &key pathname (class 'system)
2990 defsystem-depends-on &allow-other-keys)
2991 ;; The system must be registered before we parse the body,
2992 ;; otherwise we recur when trying to find an existing system
2993 ;; of the same name to reuse options (e.g. pathname) from.
2994 ;; To avoid infinite recursion in cases where you defsystem a system
2995 ;; that is registered to a different location to find-system,
2996 ;; we also need to remember it in a special variable *systems-being-defined*.
2997 (with-system-definitions ()
2998 (let* ((name (coerce-name name))
2999 (registered (system-registered-p name))
3000 (registered! (if registered
3001 (rplaca registered (get-universal-time))
3002 (register-system (make-instance 'system :name name))))
3003 (system (reset-system (cdr registered!)
3004 :name name :source-file (load-pathname)))
3005 (component-options (remove-keys '(:class) options)))
3006 (setf (gethash name *systems-being-defined*) system)
3007 (apply 'load-systems defsystem-depends-on)
3008 ;; We change-class (when necessary) AFTER we load the defsystem-dep's
3009 ;; since the class might not be defined as part of those.
3010 (let ((class (class-for-type nil class)))
3011 (unless (eq (type-of system) class)
3012 (change-class system class)))
3013 (parse-component-form
3016 :pathname (determine-system-pathname pathname)
3017 component-options)))))
3019 (defmacro defsystem (name &body options)
3020 `(apply 'do-defsystem ',name ',options))
3022 ;;;; ---------------------------------------------------------------------------
3023 ;;;; run-shell-command
3025 ;;;; run-shell-command functions for other lisp implementations will be
3026 ;;;; gratefully accepted, if they do the same thing.
3027 ;;;; If the docstring is ambiguous, send a bug report.
3029 ;;;; WARNING! The function below is mostly dysfunctional.
3030 ;;;; For instance, it will probably run fine on most implementations on Unix,
3031 ;;;; which will hopefully use the shell /bin/sh (which we force in some cases)
3032 ;;;; which is hopefully reasonably compatible with a POSIX *or* Bourne shell.
3033 ;;;; But behavior on Windows may vary wildly between implementations,
3034 ;;;; either relying on your having installed a POSIX sh, or going through
3035 ;;;; the CMD.EXE interpreter, for a totally different meaning, depending on
3036 ;;;; what is easily expressible in said implementation.
3038 ;;;; We probably should move this functionality to its own system and deprecate
3039 ;;;; use of it from the asdf package. However, this would break unspecified
3040 ;;;; existing software, so until a clear alternative exists, we can't deprecate
3041 ;;;; it, and even after it's been deprecated, we will support it for a few
3042 ;;;; years so everyone has time to migrate away from it. -- fare 2009-12-01
3044 ;;;; As a suggested replacement which is portable to all ASDF-supported
3045 ;;;; implementations and operating systems except Genera, I recommend
3046 ;;;; xcvb-driver's xcvb-driver:run-program/ and its derivatives.
3048 (defun* run-shell-command (control-string &rest args)
3049 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
3050 synchronously execute the result using a Bourne-compatible shell, with
3051 output to *VERBOSE-OUT*. Returns the shell's exit code."
3052 (let ((command (apply 'format nil control-string args)))
3053 (asdf-message "; $ ~A~%" command)
3056 (ext:run-shell-command command :output *verbose-out*)
3059 ;; will this fail if command has embedded quotes - it seems to work
3060 (multiple-value-bind (stdout stderr exit-code)
3061 (excl.osi:command-output
3062 #-mswindows (vector "/bin/sh" "/bin/sh" "-c" command)
3063 #+mswindows command ; BEWARE!
3064 :input nil :whole nil
3065 #+mswindows :show-window #+mswindows :hide)
3066 (asdf-message "~{~&~a~%~}~%" stderr)
3067 (asdf-message "~{~&~a~%~}~%" stdout)
3071 ;; CLISP returns NIL for exit status zero.
3073 (let* ((new-command (format nil "( ~A ) ; r=$? ; echo ; echo ASDF-EXIT-STATUS $r"
3075 (outstream (ext:run-shell-command new-command :output :stream :wait t)))
3076 (multiple-value-bind (retval out-lines)
3078 (parse-clisp-shell-output outstream)
3079 (ignore-errors (close outstream)))
3080 (asdf-message "~{~&~a~%~}~%" out-lines)
3082 ;; there will be no output, just grab up the exit status
3083 (or (ext:run-shell-command command :output nil :wait t) 0))
3087 (ccl:external-process-status
3090 ((os-unix-p) "/bin/sh")
3091 ((os-windows-p) (strcat "CMD /C " command)) ; BEWARE!
3092 (t (error "Unsupported OS")))
3093 (if (os-unix-p) (list "-c" command) '())
3094 :input nil :output *verbose-out* :wait t)))
3097 (ext:process-exit-code
3101 :input nil :output *verbose-out*))
3104 (win32:system command)
3106 #+ecl ;; courtesy of Juan Jose Garcia Ripoll
3107 (ext:system command)
3110 (lisp:system command)
3113 (apply 'system:call-system-showing-output command
3114 :show-cmd nil :prefix "" :output-stream *verbose-out*
3115 (when (os-unix-p) '(:shell-type "/bin/sh")))
3118 (ccl::with-cstrs ((%command command)) (_system %command))
3121 ;; This has next to no chance of working on basic Windows!
3122 ;; Your best hope is that Cygwin or MSYS is somewhere in the PATH.
3123 (multiple-value-bind (io process exit-code)
3124 (apply #'mkcl:run-program #+windows "sh" #-windows "/bin/sh"
3126 :input nil :output t #|*verbose-out*|# ;; will be *verbose-out* when we support it
3127 #-windows '(:search nil))
3128 (declare (ignore io process))
3132 (sb-ext:process-exit-code
3133 (apply 'sb-ext:run-program
3134 #+win32 "sh" #-win32 "/bin/sh"
3136 :input nil :output *verbose-out*
3137 #+win32 '(:search t) #-win32 nil))
3140 (ext:run-shell-command command)
3142 #-(or abcl allegro clisp clozure cmu ecl gcl lispworks mcl mkcl sbcl scl xcl)
3143 (error "RUN-SHELL-COMMAND not implemented for this Lisp")))
3146 (defun* parse-clisp-shell-output (stream)
3147 "Helper function for running shell commands under clisp. Parses a specially-
3148 crafted output string to recover the exit status of the shell command and a
3149 list of lines of output."
3150 (loop :with status-prefix = "ASDF-EXIT-STATUS "
3151 :with prefix-length = (length status-prefix)
3152 :with exit-status = -1 :with lines = ()
3153 :for line = (read-line stream nil nil)
3154 :while line :do (push line lines) :finally
3155 (let* ((last (car lines))
3156 (status (and last (>= (length last) prefix-length)
3157 (string-equal last status-prefix :end1 prefix-length)
3158 (parse-integer last :start prefix-length :junk-allowed t))))
3160 (setf exit-status status)
3161 (pop lines) (when (equal "" (car lines)) (pop lines)))
3162 (return (values exit-status (reverse lines))))))
3164 ;;;; ---------------------------------------------------------------------------
3165 ;;;; system-relative-pathname
3167 (defun* system-definition-pathname (x)
3168 ;; As of 2.014.8, we mean to make this function obsolete,
3169 ;; but that won't happen until all clients have been updated.
3170 ;;(cerror "Use ASDF:SYSTEM-SOURCE-FILE instead"
3171 "Function ASDF:SYSTEM-DEFINITION-PATHNAME is obsolete.
3172 It used to expose ASDF internals with subtle differences with respect to
3173 user expectations, that have been refactored away since.
3174 We recommend you use ASDF:SYSTEM-SOURCE-FILE instead
3175 for a mostly compatible replacement that we're supporting,
3176 or even ASDF:SYSTEM-SOURCE-DIRECTORY or ASDF:SYSTEM-RELATIVE-PATHNAME
3177 if that's whay you mean." ;;)
3178 (system-source-file x))
3180 (defmethod system-source-file ((system system))
3181 ;; might be missing when upgrading from ASDF 1 and u-i-f-r-c failed
3182 (unless (slot-boundp system 'source-file)
3183 (%set-system-source-file
3184 (probe-asd (component-name system) (component-pathname system)) system))
3185 (%system-source-file system))
3186 (defmethod system-source-file ((system-name string))
3187 (%system-source-file (find-system system-name)))
3188 (defmethod system-source-file ((system-name symbol))
3189 (%system-source-file (find-system system-name)))
3191 (defun* system-source-directory (system-designator)
3192 "Return a pathname object corresponding to the