2 (eval-when (:compile-toplevel
:load-toplevel
:execute
) (require :uiop
))
3 ;;;; -------------------------------------------------------------------------
4 ;;;; Handle upgrade as forward- and backward-compatibly as possible
5 ;; See https://bugs.launchpad.net/asdf/+bug/485687
7 (uiop/package
:define-package
:asdf
/upgrade
8 (:recycle
:asdf
/upgrade
:asdf
)
9 (:use
:uiop
/common-lisp
:uiop
)
11 #:asdf-version
#:*previous-asdf-versions
* #:*asdf-version
*
12 #:asdf-message
#:*verbose-out
*
13 #:upgrading-p
#:when-upgrading
#:upgrade-asdf
#:defparameter
*
14 #:*post-upgrade-cleanup-hook
* #:cleanup-upgraded-asdf
15 ;; There will be no symbol left behind!
16 #:with-asdf-deprecation
18 (:import-from
:uiop
/package
#:intern
* #:find-symbol
*))
19 (in-package :asdf
/upgrade
)
21 ;;; Special magic to detect if this is an upgrade
23 (with-upgradability ()
24 (defun asdf-version ()
25 "Exported interface to the version of ASDF currently installed. A string.
26 You can compare this string with e.g.: (ASDF:VERSION-SATISFIES (ASDF:ASDF-VERSION) \"3.4.5.67\")."
27 (when (find-package :asdf
)
28 (or (symbol-value (find-symbol (string :*asdf-version
*) :asdf
))
29 (let* ((revsym (find-symbol (string :*asdf-revision
*) :asdf
))
30 (rev (and revsym
(boundp revsym
) (symbol-value revsym
))))
33 (cons (format nil
"~{~D~^.~}" rev
))
35 ;; This (private) variable contains a list of versions of previously loaded variants of ASDF,
36 ;; from which ASDF was upgraded.
37 ;; Important: define *p-a-v* /before/ *a-v* so that they initialize correctly.
38 (defvar *previous-asdf-versions
*
39 (let ((previous (asdf-version)))
41 ;; Punt on upgrade from ASDF1 or ASDF2, by renaming (or deleting) the package.
42 (when (version< previous
"2.27") ;; 2.27 is the first to have the :asdf3 feature.
43 (let ((away (format nil
"~A-~A" :asdf previous
)))
44 (rename-package :asdf away
)
46 (format t
"~&; Renamed old ~A package away to ~A~%" :asdf away
))))
48 ;; This public variable will be bound shortly to the currently loaded version of ASDF.
49 (defvar *asdf-version
* nil
)
50 ;; We need to clear systems from versions older than the one in this (private) parameter.
51 ;; The latest incompatible defclass is 2.32.13 renaming a slot in component,
52 ;; or 3.2.0.2 for CCL (incompatibly changing some superclasses).
53 ;; the latest incompatible gf change is in 3.1.7.20 (see redefined-functions below).
54 (defparameter *oldest-forward-compatible-asdf-version
* "3.2.0.2")
55 ;; Semi-private variable: a designator for a stream on which to output ASDF progress messages
56 (defvar *verbose-out
* nil
)
57 ;; Private function by which ASDF outputs progress messages and warning messages:
58 (defun asdf-message (format-string &rest format-args
)
59 (when *verbose-out
* (apply 'format
*verbose-out
* format-string format-args
)))
60 ;; Private hook for functions to run after ASDF has upgraded itself from an older variant:
61 (defvar *post-upgrade-cleanup-hook
* ())
62 ;; Private function to detect whether the current upgrade counts as an incompatible
63 ;; data schema upgrade implying the need to drop data.
64 (defun upgrading-p (&optional
(oldest-compatible-version *oldest-forward-compatible-asdf-version
*))
65 (and *previous-asdf-versions
*
66 (version< (first *previous-asdf-versions
*) oldest-compatible-version
)))
67 ;; Private variant of defparameter that works in presence of incompatible upgrades:
68 ;; behaves like defvar in a compatible upgrade (e.g. reloading system after simple code change),
69 ;; but behaves like defparameter if in presence of an incompatible upgrade.
70 (defmacro defparameter
* (var value
&optional docstring
(version *oldest-forward-compatible-asdf-version
*))
71 (let* ((name (string-trim "*" var
))
72 (valfun (intern (format nil
"%~A-~A-~A" :compute name
:value
))))
74 (defun ,valfun
() ,value
)
75 (defvar ,var
(,valfun
) ,@(ensure-list docstring
))
76 (when (upgrading-p ,version
)
77 (setf ,var
(,valfun
))))))
78 ;; Private macro to declare sections of code that are only compiled and run when upgrading.
79 ;; The use of eval portably ensures that the code will not have adverse compile-time side-effects,
80 ;; whereas the use of handler-bind portably ensures that it will not issue warnings when it runs.
81 (defmacro when-upgrading
((&key
(version *oldest-forward-compatible-asdf-version
*)
82 (upgrading-p `(upgrading-p ,version
)) when
) &body body
)
83 "A wrapper macro for code that should only be run when upgrading a
84 previously-loaded version of ASDF."
85 `(with-upgradability ()
86 (when (and ,upgrading-p
,@(when when
`(,when
)))
87 (handler-bind ((style-warning #'muffle-warning
))
88 (eval '(progn ,@body
))))))
89 ;; Only now can we safely update the version.
90 (let* (;; For bug reporting sanity, please always bump this version when you modify this file.
91 ;; Please also modify asdf.asd to reflect this change. make bump-version v=3.4.5.67.8
92 ;; can help you do these changes in synch (look at the source for documentation).
93 ;; Relying on its automation, the version is now redundantly present on top of asdf.lisp.
94 ;; "3.4" would be the general branch for major version 3, minor version 4.
95 ;; "3.4.5" would be an official release in the 3.4 branch.
96 ;; "3.4.5.67" would be a development version in the official branch, on top of 3.4.5.
97 ;; "3.4.5.0.8" would be your eighth local modification of official release 3.4.5
98 ;; "3.4.5.67.8" would be your eighth local modification of development version 3.4.5.67
99 (asdf-version "3.3.1")
100 (existing-version (asdf-version)))
101 (setf *asdf-version
* asdf-version
)
102 (when (and existing-version
(not (equal asdf-version existing-version
)))
103 (push existing-version
*previous-asdf-versions
*)
104 (when (or *verbose-out
* *load-verbose
*)
105 (format (or *verbose-out
* *trace-output
*)
106 (compatfmt "~&~@<; ~@;Upgrading ASDF ~@[from version ~A ~]to version ~A~@:>~%")
107 existing-version asdf-version
)))))
109 ;;; Upon upgrade, specially frob some functions and classes that are being incompatibly redefined
111 (let* ((previous-version (first *previous-asdf-versions
*))
112 (redefined-functions ;; List of functions that changes incompatibly since 2.27:
113 ;; gf signature changed (should NOT happen), defun that became a generic function,
114 ;; method removed that will mess up with new ones (especially :around :before :after,
115 ;; more specific or call-next-method'ed method) and/or semantics otherwise modified. Oops.
116 ;; NB: it's too late to do anything about functions in UIOP!
117 ;; If you introduce some critical incompatibility there, you must change the function name.
118 ;; Note that we don't need do anything about functions that changed incompatibly
119 ;; from ASDF 2.26 or earlier: we wholly punt on the entire ASDF package in such an upgrade.
120 ;; Also note that we don't include the defgeneric=>defun, because they are
121 ;; done directly with defun* and need not trigger a punt on data.
122 ;; See discussion at https://gitlab.common-lisp.net/asdf/asdf/merge_requests/36
123 `(,@(when (version<= previous-version
"3.1.2") '(#:component-depends-on
#:input-files
)) ;; crucial methods *removed* before 3.1.2
124 ,@(when (version<= previous-version
"3.1.7.20") '(#:find-component
))))
126 ;; redefining the classes causes interim circularities
127 ;; with the old ASDF during upgrade, and many implementations bork
130 '((#:compile-concatenated-source-op
(#:operation
) ())
131 (#:compile-bundle-op
(#:operation
) ())
132 (#:concatenate-source-op
(#:operation
) ())
133 (#:dll-op
(#:operation
) ())
134 (#:lib-op
(#:operation
) ())
135 (#:monolithic-compile-bundle-op
(#:operation
) ())
136 (#:monolithic-concatenate-source-op
(#:operation
) ()))))
137 (loop :for name
:in redefined-functions
138 :for sym
= (find-symbol* name
:asdf nil
)
139 :do
(when sym
(fmakunbound sym
)))
140 (labels ((asym (x) (multiple-value-bind (s p
)
141 (if (consp x
) (values (car x
) (cadr x
)) (values x
:asdf
))
142 (find-symbol* s p nil
)))
143 (asyms (l) (mapcar #'asym l
)))
144 (loop* :for
(name superclasses slots
) :in redefined-classes
145 :for sym
= (find-symbol* name
:asdf nil
)
146 :when
(and sym
(find-class sym
))
147 :do
(eval `(defclass ,sym
,(asyms superclasses
) ,(asyms slots
)))))))
150 ;;; Self-upgrade functions
151 (with-upgradability ()
152 ;; This private function is called at the end of asdf/footer and ensures that,
153 ;; *if* this loading of ASDF was an upgrade, then all registered cleanup functions will be called.
154 (defun cleanup-upgraded-asdf (&optional
(old-version (first *previous-asdf-versions
*)))
155 (let ((new-version (asdf-version)))
156 (unless (equal old-version new-version
)
157 (push new-version
*previous-asdf-versions
*)
159 (if (version<= new-version old-version
)
160 (error (compatfmt "~&~@<; ~@;Downgraded ASDF from version ~A to version ~A~@:>~%")
161 old-version new-version
)
162 (asdf-message (compatfmt "~&~@<; ~@;Upgraded ASDF from version ~A to version ~A~@:>~%")
163 old-version new-version
))
164 ;; In case the previous version was too old to be forward-compatible, clear systems.
165 ;; TODO: if needed, we may have to define a separate hook to run
166 ;; in case of forward-compatible upgrade.
167 ;; Or to move the tests forward-compatibility test inside each hook function?
168 (unless (version<= *oldest-forward-compatible-asdf-version
* old-version
)
169 (call-functions (reverse *post-upgrade-cleanup-hook
*)))
172 (defun upgrade-asdf ()
173 "Try to upgrade of ASDF. If a different version was used, return T.
174 We need do that before we operate on anything that may possibly depend on ASDF."
175 (let ((*load-print
* nil
)
176 (*compile-print
* nil
))
177 (handler-bind (((or style-warning
) #'muffle-warning
))
178 (symbol-call :asdf
:load-system
:asdf
:verbose nil
))))
180 (defmacro with-asdf-deprecation
((&rest keys
&key
&allow-other-keys
) &body body
)
181 `(with-upgradability ()
182 (with-deprecation ((version-deprecation *asdf-version
* ,@keys
))
184 ;;;; -------------------------------------------------------------------------
187 (uiop/package
:define-package
:asdf
/session
188 (:recycle
:asdf
/session
:asdf
/cache
:asdf
/component
189 :asdf
/action
:asdf
/find-system
:asdf
/plan
:asdf
)
190 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
)
192 #:get-file-stamp
#:compute-file-stamp
#:register-file-stamp
193 #:asdf-cache
#:set-asdf-cache-entry
#:unset-asdf-cache-entry
#:consult-asdf-cache
194 #:do-asdf-cache
#:normalize-namestring
195 #:call-with-asdf-session
#:with-asdf-session
196 #:*asdf-session
* #:*asdf-session-class
* #:session
#:toplevel-asdf-session
197 #:session-cache
#:forcing
#:asdf-upgraded-p
198 #:visited-actions
#:visiting-action-set
#:visiting-action-list
199 #:total-action-count
#:planned-action-count
#:planned-output-action-count
200 #:clear-configuration-and-retry
#:retry
203 #:system-definition-error
;; top level, moved here because this is the earliest place for it.
204 #:formatted-system-definition-error
#:format-control
#:format-arguments
#:sysdef-error
))
205 (in-package :asdf
/session
)
208 (with-upgradability ()
209 ;; The session variable.
210 ;; NIL when outside a session.
211 (defvar *asdf-session
* nil
)
212 (defparameter* *asdf-session-class
* 'session
213 "The default class for sessions")
216 (;; The ASDF session cache is used to memoize some computations.
217 ;; It is instrumental in achieving:
218 ;; * Consistency in the view of the world relied on by ASDF within a given session.
219 ;; Inconsistencies in file stamps, system definitions, etc., could cause infinite loops
220 ;; (a.k.a. stack overflows) and other erratic behavior.
221 ;; * Speed and reliability of ASDF, with fewer side-effects from access to the filesystem, and
222 ;; no expensive recomputations of transitive dependencies for input-files or output-files.
223 ;; * Testability of ASDF with the ability to fake timestamps without actually touching files.
225 :initform nil
:initarg
:ancestor
:reader session-ancestor
226 :documentation
"Top level session that this is part of")
228 :initform
(make-hash-table :test
'equal
) :initarg
:session-cache
:reader session-cache
229 :documentation
"Memoize expensive computations")
231 :initform
0 :initarg
:operate-level
:accessor session-operate-level
232 :documentation
"Number of nested calls to operate we're under (for toplevel session only)")
233 ;; shouldn't the below be superseded by the session-wide caching of action-status
234 ;; for (load-op "asdf") ?
236 :initform nil
:initarg
:asdf-upgraded-p
:accessor asdf-upgraded-p
237 :documentation
"Was ASDF already upgraded in this session - only valid for toplevel-asdf-session.")
239 :initform nil
:initarg
:forcing
:accessor forcing
240 :documentation
"Forcing parameters for the session")
241 ;; Table that to actions already visited while walking the dependencies associates status
242 (visited-actions :initform
(make-hash-table :test
'equal
) :accessor visited-actions
)
243 ;; Actions that depend on those being currently walked through, to detect circularities
244 (visiting-action-set ;; as a set
245 :initform
(make-hash-table :test
'equal
) :accessor visiting-action-set
)
246 (visiting-action-list :initform
() :accessor visiting-action-list
) ;; as a list
247 ;; Counts of total actions in plan
248 (total-action-count :initform
0 :accessor total-action-count
)
249 ;; Count of actions that need to be performed
250 (planned-action-count :initform
0 :accessor planned-action-count
)
251 ;; Count of actions that need to be performed that have a non-empty list of output-files.
252 (planned-output-action-count :initform
0 :accessor planned-output-action-count
))
253 (:documentation
"An ASDF session with a cache to memoize some computations"))
255 (defun toplevel-asdf-session ()
256 (when *asdf-session
* (or (session-ancestor *asdf-session
*) *asdf-session
*)))
258 (defun operate-level ()
259 (session-operate-level (toplevel-asdf-session)))
261 (defun (setf operate-level
) (new-level)
262 (setf (session-operate-level (toplevel-asdf-session)) new-level
))
265 (session-cache *asdf-session
*))
267 ;; Set a session cache entry for KEY to a list of values VALUE-LIST, when inside a session.
268 ;; Return those values.
269 (defun set-asdf-cache-entry (key value-list
)
270 (values-list (if *asdf-session
*
271 (setf (gethash key
(asdf-cache)) value-list
)
274 ;; Unset the session cache entry for KEY, when inside a session.
275 (defun unset-asdf-cache-entry (key)
277 (remhash key
(session-cache *asdf-session
*))))
279 ;; Consult the session cache entry for KEY if present and in a session;
280 ;; if not present, compute it by calling the THUNK,
281 ;; and set the session cache entry accordingly, if in a session.
282 ;; Return the values from the cache and/or the thunk computation.
283 (defun consult-asdf-cache (key &optional thunk
)
285 (multiple-value-bind (results foundp
) (gethash key
(session-cache *asdf-session
*))
287 (values-list results
)
288 (set-asdf-cache-entry key
(multiple-value-list (call-function thunk
)))))
289 (call-function thunk
)))
291 ;; Syntactic sugar for consult-asdf-cache
292 (defmacro do-asdf-cache
(key &body body
)
293 `(consult-asdf-cache ,key
#'(lambda () ,@body
)))
295 ;; Compute inside a ASDF session with a cache.
296 ;; First, make sure an ASDF session is underway, by binding the session cache variable
297 ;; to a new hash-table if it's currently null (or even if it isn't, if OVERRIDE is true).
298 ;; Second, if a new session was started, establish restarts for retrying the overall computation.
299 ;; Finally, consult the cache if a KEY was specified with the THUNK as a fallback when the cache
300 ;; entry isn't found, or just call the THUNK if no KEY was specified.
301 (defun call-with-asdf-session (thunk &key override key override-cache override-forcing
)
302 (let ((fun (if key
#'(lambda () (consult-asdf-cache key thunk
)) thunk
)))
303 (if (and (not override
) *asdf-session
*)
307 (let ((*asdf-session
*
308 (apply 'make-instance
*asdf-session-class
*
310 `(:ancestor
,(toplevel-asdf-session)
311 ,@(unless override-forcing
312 `(:forcing
,(forcing *asdf-session
*)))
313 ,@(unless override-cache
314 `(:session-cache
,(session-cache *asdf-session
*))))))))
315 (return (funcall fun
)))
318 (format s
(compatfmt "~@<Retry ASDF operation.~@:>"))))
319 (clear-configuration-and-retry ()
321 (format s
(compatfmt "~@<Retry ASDF operation after resetting the configuration.~@:>")))
322 (clrhash (session-cache *asdf-session
*))
323 (clear-configuration)))))))
325 ;; Syntactic sugar for call-with-asdf-session
326 (defmacro with-asdf-session
((&key key override override-cache override-forcing
) &body body
)
327 `(call-with-asdf-session
329 :override
,override
:key
,key
330 :override-cache
,override-cache
:override-forcing
,override-forcing
))
333 ;;; Define specific accessor for file (date) stamp.
335 ;; Normalize a namestring for use as a key in the session cache.
336 (defun normalize-namestring (pathname)
337 (let ((resolved (resolve-symlinks*
338 (ensure-absolute-pathname
339 (physicalize-pathname pathname
)
340 'get-pathname-defaults
))))
341 (with-pathname-defaults () (namestring resolved
))))
343 ;; Compute the file stamp for a normalized namestring
344 (defun compute-file-stamp (normalized-namestring)
345 (with-pathname-defaults ()
346 (or (safe-file-write-date normalized-namestring
) t
)))
348 ;; Override the time STAMP associated to a given FILE in the session cache.
349 ;; If no STAMP is specified, recompute a new one from the filesystem.
350 (defun register-file-stamp (file &optional
(stamp nil stampp
))
351 (let* ((namestring (normalize-namestring file
))
352 (stamp (if stampp stamp
(compute-file-stamp namestring
))))
353 (set-asdf-cache-entry `(get-file-stamp ,namestring
) (list stamp
))))
355 ;; Get or compute a memoized stamp for given FILE from the session cache.
356 (defun get-file-stamp (file)
358 (let ((namestring (normalize-namestring file
)))
359 (do-asdf-cache `(get-file-stamp ,namestring
) (compute-file-stamp namestring
)))))
364 (define-condition system-definition-error
(error) ()
365 ;; [this use of :report should be redundant, but unfortunately it's not.
366 ;; cmucl's lisp::output-instance prefers the kernel:slot-class-print-function
367 ;; over print-object; this is always conditions::%print-condition for
368 ;; condition objects, which in turn does inheritance of :report options at
369 ;; run-time. fortunately, inheritance means we only need this kludge here in
370 ;; order to fix all conditions that build on it. -- rgr, 28-Jul-02.]
371 #+cmucl
(:report print-object
))
373 (define-condition formatted-system-definition-error
(system-definition-error)
374 ((format-control :initarg
:format-control
:reader format-control
)
375 (format-arguments :initarg
:format-arguments
:reader format-arguments
))
376 (:report
(lambda (c s
)
377 (apply 'format s
(format-control c
) (format-arguments c
)))))
379 (defun sysdef-error (format &rest arguments
)
380 (error 'formatted-system-definition-error
:format-control
381 format
:format-arguments arguments
)))
382 ;;;; -------------------------------------------------------------------------
385 (uiop/package
:define-package
:asdf
/component
386 (:recycle
:asdf
/component
:asdf
/find-component
:asdf
)
387 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
)
389 #:component
#:component-find-path
390 #:find-component
;; methods defined in find-component
391 #:component-name
#:component-pathname
#:component-relative-pathname
392 #:component-parent
#:component-system
#:component-parent-pathname
393 #:child-component
#:parent-component
#:module
395 #:source-file
#:c-source-file
#:java-source-file
396 #:static-file
#:doc-file
#:html-file
398 #:source-file-type
#:source-file-explicit-type
;; backward-compatibility
399 #:component-in-order-to
#:component-sideway-dependencies
400 #:component-if-feature
#:around-compile-hook
401 #:component-description
#:component-long-description
402 #:component-version
#:version-satisfies
403 #:component-inline-methods
;; backward-compatibility only. DO NOT USE!
404 #:component-operation-times
;; For internal use only.
405 ;; portable ASDF encoding and implementation-specific external-format
406 #:component-external-format
#:component-encoding
407 #:component-children-by-name
#:component-children
#:compute-children-by-name
408 #:component-build-operation
409 #:module-default-component-class
410 #:module-components
;; backward-compatibility. DO NOT USE.
416 ;; Internals we'd like to share with the ASDF package, especially for upgrade purposes
417 #:name
#:version
#:description
#:long-description
#:author
#:maintainer
#:licence
418 #:components-by-name
#:components
#:children
#:children-by-name
419 #:default-component-class
#:source-file
420 #:defsystem-depends-on
; This symbol retained for backward compatibility.
421 #:sideway-dependencies
#:if-feature
#:in-order-to
#:inline-methods
422 #:relative-pathname
#:absolute-pathname
#:operation-times
#:around-compile
423 #:%encoding
#:properties
#:component-properties
#:parent
))
424 (in-package :asdf
/component
)
426 (with-upgradability ()
427 (defgeneric component-name
(component)
428 (:documentation
"Name of the COMPONENT, unique relative to its parent"))
429 (defgeneric component-system
(component)
430 (:documentation
"Top-level system containing the COMPONENT"))
431 (defgeneric component-pathname
(component)
432 (:documentation
"Pathname of the COMPONENT if any, or NIL."))
433 (defgeneric component-relative-pathname
(component)
434 ;; in ASDF4, rename that to component-specified-pathname ?
435 (:documentation
"Specified pathname of the COMPONENT,
436 intended to be merged with the pathname of that component's parent if any, using merged-pathnames*.
437 Despite the function's name, the return value can be an absolute pathname, in which case the merge
438 will leave it unmodified."))
439 (defgeneric component-external-format
(component)
440 (:documentation
"The external-format of the COMPONENT.
441 By default, deduced from the COMPONENT-ENCODING."))
442 (defgeneric component-encoding
(component)
443 (:documentation
"The encoding of the COMPONENT. By default, only :utf-8 is supported.
444 Use asdf-encodings to support more encodings."))
445 (defgeneric version-satisfies
(component version
)
446 (:documentation
"Check whether a COMPONENT satisfies the constraint of being at least as recent
447 as the specified VERSION, which must be a string of dot-separated natural numbers, or NIL."))
448 (defgeneric component-version
(component)
449 (:documentation
"Return the version of a COMPONENT, which must be a string of dot-separated
450 natural numbers, or NIL."))
451 (defgeneric (setf component-version
) (new-version component
)
452 (:documentation
"Updates the version of a COMPONENT, which must be a string of dot-separated
453 natural numbers, or NIL."))
454 (defgeneric component-parent
(component)
455 (:documentation
"The parent of a child COMPONENT,
456 or NIL for top-level components (a.k.a. systems)"))
457 ;; NIL is a designator for the absence of a component, in which case the parent is also absent.
458 (defmethod component-parent ((component null
)) nil
)
460 ;; Deprecated: Backward compatible way of computing the FILE-TYPE of a component.
461 ;; TODO: find users, have them stop using that, remove it for ASDF4.
462 (defgeneric source-file-type
(component system
)
463 (:documentation
"DEPRECATED. Use the FILE-TYPE of a COMPONENT instead."))
465 (define-condition duplicate-names
(system-definition-error)
466 ((name :initarg
:name
:reader duplicate-names-name
))
467 (:report
(lambda (c s
)
468 (format s
(compatfmt "~@<Error while defining system: multiple components are given same name ~S~@:>")
469 (duplicate-names-name c
))))))
472 (with-upgradability ()
473 (defclass component
()
474 ((name :accessor component-name
:initarg
:name
:type string
:documentation
475 "Component name: designator for a string composed of portable pathname characters")
476 ;; We might want to constrain version with
477 ;; :type (and string (satisfies parse-version))
478 ;; but we cannot until we fix all systems that don't use it correctly!
479 (version :accessor component-version
:initarg
:version
:initform nil
)
480 (description :accessor component-description
:initarg
:description
:initform nil
)
481 (long-description :accessor component-long-description
:initarg
:long-description
:initform nil
)
482 (sideway-dependencies :accessor component-sideway-dependencies
:initform nil
)
483 (if-feature :accessor component-if-feature
:initform nil
:initarg
:if-feature
)
484 ;; In the ASDF object model, dependencies exist between *actions*,
485 ;; where an action is a pair of an operation and a component.
486 ;; Dependencies are represented as alists of operations
487 ;; to a list where each entry is a pair of an operation and a list of component specifiers.
488 ;; Up until ASDF 2.26.9, there used to be two kinds of dependencies:
489 ;; in-order-to and do-first, each stored in its own slot. Now there is only in-order-to.
490 ;; in-order-to used to represent things that modify the filesystem (such as compiling a fasl)
491 ;; and do-first things that modify the current image (such as loading a fasl).
492 ;; These are now unified because we now correctly propagate timestamps between dependencies.
493 ;; Happily, no one seems to have used do-first too much (especially since until ASDF 2.017,
494 ;; anything you specified was overridden by ASDF itself anyway), but the name in-order-to remains.
495 ;; The names are bad, but they have been the official API since Dan Barlow's ASDF 1.52!
496 ;; LispWorks's defsystem has caused-by and requires for in-order-to and do-first respectively.
497 ;; Maybe rename the slots in ASDF? But that's not very backward-compatible.
498 ;; See our ASDF 2 paper for more complete explanations.
499 (in-order-to :initform nil
:initarg
:in-order-to
500 :accessor component-in-order-to
)
501 ;; Methods defined using the "inline" style inside a defsystem form:
502 ;; we store them here so we can delete them when the system is re-evaluated.
503 (inline-methods :accessor component-inline-methods
:initform nil
)
504 ;; ASDF4: rename it from relative-pathname to specified-pathname. It need not be relative.
505 ;; There is no initform and no direct accessor for this specified pathname,
506 ;; so we only access the information through appropriate methods, after it has been processed.
507 ;; Unhappily, some braindead systems directly access the slot. Make them stop before ASDF4.
508 (relative-pathname :initarg
:pathname
)
509 ;; The absolute-pathname is computed based on relative-pathname and parent pathname.
510 ;; The slot is but a cache used by component-pathname.
512 (operation-times :initform
(make-hash-table)
513 :accessor component-operation-times
)
514 (around-compile :initarg
:around-compile
)
515 ;; Properties are for backward-compatibility with ASDF2 only. DO NOT USE!
516 (properties :accessor component-properties
:initarg
:properties
518 (%encoding
:accessor %component-encoding
:initform nil
:initarg
:encoding
)
519 ;; For backward-compatibility, this slot is part of component rather than of child-component. ASDF4: stop it.
520 (parent :initarg
:parent
:initform nil
:reader component-parent
)
522 :initarg
:build-operation
:initform nil
:reader component-build-operation
)
523 ;; Cache for ADDITIONAL-INPUT-FILES function.
524 (additional-input-files :accessor %additional-input-files
:initform nil
))
525 (:documentation
"Base class for all components of a build"))
527 (defgeneric find-component
(base path
&key registered
)
528 (:documentation
"Find a component by resolving the PATH starting from BASE parent.
529 If REGISTERED is true, only search currently registered systems."))
531 (defun component-find-path (component)
532 "Return a path from a root system to the COMPONENT.
533 The return value is a list of component NAMES; a list of strings."
534 (check-type component
(or null component
))
536 (loop :for c
= component
:then
(component-parent c
)
537 :while c
:collect
(component-name c
))))
539 (defmethod print-object ((c component
) stream
)
540 (print-unreadable-object (c stream
:type t
:identity nil
)
541 (format stream
"~{~S~^ ~}" (component-find-path c
))))
543 (defmethod component-system ((component component
))
544 (if-let (system (component-parent component
))
545 (component-system system
)
549 ;;;; Component hierarchy within a system
550 ;; The tree typically but not necessarily follows the filesystem hierarchy.
551 (with-upgradability ()
552 (defclass child-component
(component) ()
553 (:documentation
"A CHILD-COMPONENT is a COMPONENT that may be part of
554 a PARENT-COMPONENT."))
556 (defclass file-component
(child-component)
557 ((type :accessor file-type
:initarg
:type
)) ; no default
558 (:documentation
"a COMPONENT that represents a file"))
559 (defclass source-file
(file-component)
560 ((type :accessor source-file-explicit-type
;; backward-compatibility
561 :initform nil
))) ;; NB: many systems have come to rely on this default.
562 (defclass c-source-file
(source-file)
563 ((type :initform
"c")))
564 (defclass java-source-file
(source-file)
565 ((type :initform
"java")))
566 (defclass static-file
(source-file)
567 ((type :initform nil
))
568 (:documentation
"Component for a file to be included as is in the build output"))
569 (defclass doc-file
(static-file) ())
570 (defclass html-file
(doc-file)
571 ((type :initform
"html")))
573 (defclass parent-component
(component)
577 :reader module-components
; backward-compatibility
578 :accessor component-children
)
580 :reader module-components-by-name
; backward-compatibility
581 :accessor component-children-by-name
)
582 (default-component-class
584 :initarg
:default-component-class
585 :accessor module-default-component-class
))
586 (:documentation
"A PARENT-COMPONENT is a component that may have children.")))
588 (with-upgradability ()
589 ;; (Private) Function that given a PARENT component,
590 ;; the list of children of which has been initialized,
591 ;; compute the hash-table in slot children-by-name that allows to retrieve its children by name.
592 ;; If ONLY-IF-NEEDED-P is defined, skip any (re)computation if the slot is already populated.
593 (defun compute-children-by-name (parent &key only-if-needed-p
)
594 (unless (and only-if-needed-p
(slot-boundp parent
'children-by-name
))
595 (let ((hash (make-hash-table :test
'equal
)))
596 (setf (component-children-by-name parent
) hash
)
597 (loop :for c
:in
(component-children parent
)
598 :for name
= (component-name c
)
599 :for previous
= (gethash name hash
)
600 :do
(when previous
(error 'duplicate-names
:name name
))
601 (setf (gethash name hash
) c
))
604 (with-upgradability ()
605 (defclass module
(child-component parent-component
)
606 (#+clisp
(components)) ;; backward compatibility during upgrade only
607 (:documentation
"A module is a intermediate component with both a parent and children,
608 typically but not necessarily representing the files in a subdirectory of the build source.")))
611 ;;;; component pathnames
612 (with-upgradability ()
613 (defgeneric component-parent-pathname
(component)
614 (:documentation
"The pathname of the COMPONENT's parent, if any, or NIL"))
615 (defmethod component-parent-pathname (component)
616 (component-pathname (component-parent component
)))
618 ;; The default method for component-pathname tries to extract a cached precomputed
619 ;; absolute-pathname from the relevant slot, and if not, computes it by merging the
620 ;; component-relative-pathname (which should be component-specified-pathname, it can be absolute)
621 ;; with the directory of the component-parent-pathname.
622 (defmethod component-pathname ((component component
))
623 (if (slot-boundp component
'absolute-pathname
)
624 (slot-value component
'absolute-pathname
)
627 (component-relative-pathname component
)
628 (pathname-directory-pathname (component-parent-pathname component
)))))
629 (unless (or (null pathname
) (absolute-pathname-p pathname
))
630 (error (compatfmt "~@<Invalid relative pathname ~S for component ~S~@:>")
631 pathname
(component-find-path component
)))
632 (setf (slot-value component
'absolute-pathname
) pathname
)
635 ;; Default method for component-relative-pathname:
636 ;; combine the contents of slot relative-pathname (from specified initarg :pathname)
637 ;; with the appropriate source-file-type, which defaults to the file-type of the component.
638 (defmethod component-relative-pathname ((component component
))
639 ;; SOURCE-FILE-TYPE below is strictly for backward-compatibility with ASDF1.
640 ;; We ought to be able to extract this from the component alone with FILE-TYPE.
641 ;; TODO: track who uses it in Quicklisp, and have them not use it anymore;
642 ;; maybe issue a WARNING (then eventually CERROR) if the two methods diverge?
643 (parse-unix-namestring
644 (or (and (slot-boundp component
'relative-pathname
)
645 (slot-value component
'relative-pathname
))
646 (component-name component
))
648 :type
(source-file-type component
(component-system component
))
649 :defaults
(component-parent-pathname component
)))
651 (defmethod source-file-type ((component parent-component
) (system parent-component
))
654 (defmethod source-file-type ((component file-component
) (system parent-component
))
655 (file-type component
)))
659 (with-upgradability ()
660 (defmethod component-encoding ((c component
))
661 (or (loop :for x
= c
:then
(component-parent x
)
662 :while x
:thereis
(%component-encoding x
))
663 (detect-encoding (component-pathname c
))))
665 (defmethod component-external-format ((c component
))
666 (encoding-external-format (component-encoding c
))))
669 ;;;; around-compile-hook
670 (with-upgradability ()
671 (defgeneric around-compile-hook
(component)
672 (:documentation
"An optional hook function that will be called with one argument, a thunk.
673 The hook function must call the thunk, that will compile code from the component, and may or may not
674 also evaluate the compiled results. The hook function may establish dynamic variable bindings around
675 this compilation, or check its results, etc."))
676 (defmethod around-compile-hook ((c component
))
678 ((slot-boundp c
'around-compile
)
679 (slot-value c
'around-compile
))
680 ((component-parent c
)
681 (around-compile-hook (component-parent c
))))))
684 ;;;; version-satisfies
685 (with-upgradability ()
686 ;; short-circuit testing of null version specifications.
687 ;; this is an all-pass, without warning
688 (defmethod version-satisfies :around
((c t
) (version null
))
690 (defmethod version-satisfies ((c component
) version
)
691 (unless (and version
(slot-boundp c
'version
) (component-version c
))
693 (warn "Requested version ~S but ~S has no version" version c
))
694 (return-from version-satisfies nil
))
695 (version-satisfies (component-version c
) version
))
697 (defmethod version-satisfies ((cver string
) version
)
698 (version<= version cver
)))
701 ;;; all sub-components (of a given type)
702 (with-upgradability ()
703 (defun sub-components (component &key
(type t
))
704 "Compute the transitive sub-components of given COMPONENT that are of given TYPE"
705 (while-collecting (c)
706 (labels ((recurse (x)
707 (when (if-let (it (component-if-feature x
)) (featurep it
) t
)
710 (when (typep x
'parent-component
)
711 (map () #'recurse
(component-children x
))))))
712 (recurse component
)))))
714 ;;;; -------------------------------------------------------------------------
717 (uiop/package
:define-package
:asdf
/operation
718 (:recycle
:asdf
/operation
:asdf
/action
:asdf
) ;; asdf/action for FEATURE pre 2.31.5.
719 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
)
722 #:*operations
* #:make-operation
#:find-operation
723 #:feature
)) ;; TODO: stop exporting the deprecated FEATURE feature.
724 (in-package :asdf
/operation
)
726 ;;; Operation Classes
727 (when-upgrading (:version
"2.27" :when
(find-class 'operation nil
))
728 ;; override any obsolete shared-initialize method when upgrading from ASDF2.
729 (defmethod shared-initialize :after
((o operation
) (slot-names t
) &key
)
732 (with-upgradability ()
733 (defclass operation
()
735 (:documentation
"The base class for all ASDF operations.
737 ASDF does NOT and never did distinguish between multiple operations of the same class.
738 Therefore, all slots of all operations MUST have :allocation :class and no initargs. No exceptions.
741 (defvar *in-make-operation
* nil
)
743 (defun check-operation-constructor ()
744 "Enforce that OPERATION instances must be created with MAKE-OPERATION."
745 (unless *in-make-operation
*
746 (sysdef-error "OPERATION instances must only be created through MAKE-OPERATION.")))
748 (defmethod print-object ((o operation
) stream
)
749 (print-unreadable-object (o stream
:type t
:identity nil
)))
751 ;;; Override previous methods (from 3.1.7 and earlier) and add proper error checking.
752 #-genera
;; Genera adds its own system initargs, e.g. clos-internals:storage-area 8
753 (defmethod initialize-instance :after
((o operation
) &rest initargs
&key
&allow-other-keys
)
754 (unless (null initargs
)
755 (parameter-error "~S does not accept initargs" 'operation
))))
758 ;;; make-operation, find-operation
760 (with-upgradability ()
761 ;; A table to memoize instances of a given operation. There shall be only one.
762 (defparameter* *operations
* (make-hash-table :test
'equal
))
764 ;; A memoizing way of creating instances of operation.
765 (defun make-operation (operation-class)
766 "This function creates and memoizes an instance of OPERATION-CLASS.
767 All operation instances MUST be created through this function.
769 Use of INITARGS is not supported at this time."
770 (let ((class (coerce-class operation-class
771 :package
:asdf
/interface
:super
'operation
:error
'sysdef-error
))
772 (*in-make-operation
* t
))
773 (ensure-gethash class
*operations
* `(make-instance ,class
))))
775 ;; This function is mostly for backward and forward compatibility:
776 ;; operations used to preserve the operation-original-initargs of the context,
777 ;; and may in the future preserve some operation-canonical-initargs.
778 ;; Still, the treatment of NIL as a disabling context is useful in some cases.
779 (defgeneric find-operation
(context spec
)
780 (:documentation
"Find an operation by resolving the SPEC in the CONTEXT"))
781 (defmethod find-operation ((context t
) (spec operation
))
783 (defmethod find-operation ((context t
) (spec symbol
))
784 (when spec
;; NIL designates itself, i.e. absence of operation
785 (make-operation spec
))) ;; TODO: preserve the (operation-canonical-initargs context)
786 (defmethod find-operation ((context t
) (spec string
))
787 (make-operation spec
))) ;; TODO: preserve the (operation-canonical-initargs context)
789 ;;;; -------------------------------------------------------------------------
792 (uiop/package
:define-package
:asdf
/system
793 (:recycle
:asdf
:asdf
/system
:asdf
/find-system
)
794 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
:asdf
/component
)
796 #:system
#:proto-system
#:undefined-system
#:reset-system-class
797 #:system-source-file
#:system-source-directory
#:system-relative-pathname
798 #:system-description
#:system-long-description
799 #:system-author
#:system-maintainer
#:system-licence
#:system-license
800 #:definition-dependency-list
#:definition-dependency-set
#:system-defsystem-depends-on
801 #:system-depends-on
#:system-weakly-depends-on
802 #:component-build-pathname
#:build-pathname
803 #:component-entry-point
#:entry-point
804 #:homepage
#:system-homepage
805 #:bug-tracker
#:system-bug-tracker
806 #:mailto
#:system-mailto
807 #:long-name
#:system-long-name
808 #:source-control
#:system-source-control
809 #:coerce-name
#:primary-system-name
#:primary-system-p
#:coerce-filename
810 #:find-system
#:builtin-system-p
)) ;; forward-reference, defined in find-system
811 (in-package :asdf
/system
)
813 (with-upgradability ()
814 ;; The method is actually defined in asdf/find-system,
815 ;; but we declare the function here to avoid a forward reference.
816 (defgeneric find-system
(system &optional error-p
)
817 (:documentation
"Given a system designator, find the actual corresponding system object.
818 If no system is found, then signal an error if ERROR-P is true (the default), or else return NIL.
819 A system designator is usually a string (conventionally all lowercase) or a symbol, designating
820 the same system as its downcased name; it can also be a system object (designating itself)."))
821 (defgeneric system-source-file
(system)
822 (:documentation
"Return the source file in which system is defined."))
823 ;; This is bad design, but was the easiest kluge I found to let the user specify that
824 ;; some special actions create outputs at locations controled by the user that are not affected
825 ;; by the usual output-translations.
826 ;; TODO: Fix operate to stop passing flags to operation (which in the current design shouldn't
827 ;; have any flags, since the stamp cache, etc., can't distinguish them), and instead insert
828 ;; *there* the ability of specifying special output paths, not in the system definition.
829 (defgeneric component-build-pathname
(component)
830 (:documentation
"The COMPONENT-BUILD-PATHNAME, when defined and not null, specifies the
831 output pathname for the action using the COMPONENT-BUILD-OPERATION.
833 NB: This interface is subject to change. Please contact ASDF maintainers if you use it."))
835 ;; TODO: Should this have been made a SYSTEM-ENTRY-POINT instead?
836 (defgeneric component-entry-point
(component)
837 (:documentation
"The COMPONENT-ENTRY-POINT, when defined, specifies what function to call
838 (with no argument) when running an image dumped from the COMPONENT.
840 NB: This interface is subject to change. Please contact ASDF maintainers if you use it."))
841 (defmethod component-entry-point ((c component
))
845 ;;;; The system class
847 (with-upgradability ()
848 (defclass proto-system
() ; slots to keep when resetting a system
849 ;; To preserve identity for all objects, we'd need keep the components slots
850 ;; but also to modify parse-component-form to reset the recycled objects.
853 ;; These two slots contains the *inferred* dependencies of define-op,
854 ;; from loading the .asd file, as list and as set.
855 (definition-dependency-list
856 :initform nil
:accessor definition-dependency-list
)
857 (definition-dependency-set
858 :initform
(list-to-hash-set nil
) :accessor definition-dependency-set
))
859 (:documentation
"PROTO-SYSTEM defines the elements of identity that are preserved when
860 a SYSTEM is redefined and its class is modified."))
862 (defclass system
(module proto-system
)
863 ;; Backward-compatibility: inherit from module. ASDF4: only inherit from parent-component.
864 (;; {,long-}description is now inherited from component, but we add the legacy accessors
865 (description :accessor system-description
)
866 (long-description :accessor system-long-description
)
867 (author :accessor system-author
:initarg
:author
:initform nil
)
868 (maintainer :accessor system-maintainer
:initarg
:maintainer
:initform nil
)
869 (licence :accessor system-licence
:initarg
:licence
870 :accessor system-license
:initarg
:license
:initform nil
)
871 (homepage :accessor system-homepage
:initarg
:homepage
:initform nil
)
872 (bug-tracker :accessor system-bug-tracker
:initarg
:bug-tracker
:initform nil
)
873 (mailto :accessor system-mailto
:initarg
:mailto
:initform nil
)
874 (long-name :accessor system-long-name
:initarg
:long-name
:initform nil
)
875 ;; Conventions for this slot aren't clear yet as of ASDF 2.27, but whenever they are, they will be enforced.
876 ;; I'm introducing the slot before the conventions are set for maximum compatibility.
877 (source-control :accessor system-source-control
:initarg
:source-control
:initform nil
)
878 (builtin-system-p :accessor builtin-system-p
:initform nil
:initarg
:builtin-system-p
)
880 :initform nil
:initarg
:build-pathname
:accessor component-build-pathname
)
882 :initform nil
:initarg
:entry-point
:accessor component-entry-point
)
883 (source-file :initform nil
:initarg
:source-file
:accessor system-source-file
)
884 ;; This slot contains the *declared* defsystem-depends-on dependencies
885 (defsystem-depends-on :reader system-defsystem-depends-on
:initarg
:defsystem-depends-on
887 ;; these two are specially set in parse-component-form, so have no :INITARGs.
888 (depends-on :reader system-depends-on
:initform nil
)
889 (weakly-depends-on :reader system-weakly-depends-on
:initform nil
))
890 (:documentation
"SYSTEM is the base class for top-level components that users may request
893 (defclass undefined-system
(system) ()
894 (:documentation
"System that was not defined yet."))
896 (defun reset-system-class (system new-class
&rest keys
&key
&allow-other-keys
)
897 "Erase any data from a SYSTEM except its basic identity, then reinitialize it
898 based on supplied KEYS."
899 (change-class (change-class system
'proto-system
) new-class
)
900 (apply 'reinitialize-instance system keys
)))
903 ;;; Canonicalizing system names
905 (with-upgradability ()
906 (defun coerce-name (name)
907 "Given a designator for a component NAME, return the name as a string.
908 The designator can be a COMPONENT (designing its name; note that a SYSTEM is a component),
909 a SYMBOL (designing its name, downcased), or a STRING (designing itself)."
911 (component (component-name name
))
912 (symbol (string-downcase name
))
914 (t (sysdef-error (compatfmt "~@<Invalid component designator: ~3i~_~A~@:>") name
))))
916 (defun primary-system-name (system-designator)
917 "Given a system designator NAME, return the name of the corresponding primary system,
918 after which the .asd file is named. That's the first component when dividing the name
919 as a string by / slashes. A component designates its system."
920 (etypecase system-designator
921 (string (if-let (p (position #\
/ system-designator
))
922 (subseq system-designator
0 p
) system-designator
))
923 (symbol (primary-system-name (coerce-name system-designator
)))
924 (component (primary-system-name (coerce-name (component-system system-designator
))))))
926 (defun primary-system-p (system)
927 "Given a system designator SYSTEM, return T if it designates a primary system, or else NIL.
928 Also return NIL if system is neither a SYSTEM nor a string designating one."
930 (string (not (find #\
/ system
)))
931 (system (primary-system-p (coerce-name system
)))))
933 (defun coerce-filename (name)
934 "Coerce a system designator NAME into a string suitable as a filename component.
935 The (current) transformation is to replace characters /:\\ each by --,
936 the former being forbidden in a filename component.
937 NB: The onus is unhappily on the user to avoid clashes."
938 (frob-substrings (coerce-name name
) '("/" ":" "\\") "--")))
943 (with-upgradability ()
944 ;; Resolve a system designator to a system before extracting its system-source-file
945 (defmethod system-source-file ((system-name string
))
946 (system-source-file (find-system system-name
)))
947 (defmethod system-source-file ((system-name symbol
))
949 (system-source-file (find-system system-name
))))
951 (defun system-source-directory (system-designator)
952 "Return a pathname object corresponding to the directory
953 in which the system specification (.asd file) is located."
954 (pathname-directory-pathname (system-source-file system-designator
)))
956 (defun* (system-relative-pathname) (system name
&key type
)
957 "Given a SYSTEM, and a (Unix-style relative path) NAME of a file (or directory) of given TYPE,
958 return the absolute pathname of a corresponding file under that system's source code pathname."
959 (subpathname (system-source-directory system
) name
:type type
))
961 (defmethod component-pathname ((system system
))
962 "Given a SYSTEM, and a (Unix-style relative path) NAME of a file (or directory) of given TYPE,
963 return the absolute pathname of a corresponding file under that system's source code pathname."
964 (let ((pathname (or (call-next-method) (system-source-directory system
))))
965 (unless (and (slot-boundp system
'relative-pathname
) ;; backward-compatibility with ASDF1-age
966 (slot-value system
'relative-pathname
)) ;; systems that directly access this slot.
967 (setf (slot-value system
'relative-pathname
) pathname
))
970 ;; The default method of component-relative-pathname for a system:
971 ;; if a pathname was specified in the .asd file, it must be relative to the .asd file
972 ;; (actually, to its truename* if *resolve-symlinks* it true, the default).
973 ;; The method will return an *absolute* pathname, once again showing that the historical name
974 ;; component-relative-pathname is misleading and should have been component-specified-pathname.
975 (defmethod component-relative-pathname ((system system
))
976 (parse-unix-namestring
977 (and (slot-boundp system
'relative-pathname
)
978 (slot-value system
'relative-pathname
))
982 :defaults
(system-source-directory system
)))
984 ;; A system has no parent; if some method wants to make a path "relative to its parent",
985 ;; it will instead be relative to the system itself.
986 (defmethod component-parent-pathname ((system system
))
987 (system-source-directory system
))
989 ;; Most components don't have a specified component-build-pathname, and therefore
990 ;; no magic redirection of their output that disregards the output-translations.
991 (defmethod component-build-pathname ((c component
))
994 ;;;; -------------------------------------------------------------------------
997 (uiop/package
:define-package
:asdf
/system-registry
998 (:recycle
:asdf
/system-registry
:asdf
/find-system
:asdf
)
999 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
1000 :asdf
/session
:asdf
/component
:asdf
/system
)
1002 #:remove-entry-from-registry
#:coerce-entry-to-directory
1003 #:registered-system
#:register-system
1004 #:registered-systems
* #:registered-systems
1005 #:clear-system
#:map-systems
1006 #:*system-definition-search-functions
* #:search-for-system-definition
1007 #:*central-registry
* #:probe-asd
#:sysdef-central-registry-search
1008 #:contrib-sysdef-search
#:sysdef-find-asdf
;; backward compatibility symbols, functions removed
1009 #:sysdef-preloaded-system-search
#:register-preloaded-system
#:*preloaded-systems
*
1010 #:find-system-if-being-defined
#:mark-component-preloaded
;; forward references to asdf/find-system
1011 #:sysdef-immutable-system-search
#:register-immutable-system
#:*immutable-systems
*
1012 #:*registered-systems
* #:clear-registered-systems
1013 ;; defined in source-registry, but specially mentioned here:
1014 #:sysdef-source-registry-search
))
1015 (in-package :asdf
/system-registry
)
1017 (with-upgradability ()
1018 ;;; Registry of Defined Systems
1020 (defvar *registered-systems
* (make-hash-table :test
'equal
)
1021 "This is a hash table whose keys are strings -- the names of systems --
1022 and whose values are systems.
1023 A system is referred to as \"registered\" if it is present in this table.")
1025 (defun registered-system (name)
1026 "Return a system of given NAME that was registered already,
1027 if such a system exists. NAME is a system designator, to be
1028 normalized by COERCE-NAME. The value returned is a system object,
1029 or NIL if not found."
1030 (gethash (coerce-name name
) *registered-systems
*))
1032 (defun registered-systems* ()
1033 "Return a list containing every registered system (as a system object)."
1034 (loop :for registered
:being
:the
:hash-values
:of
*registered-systems
*
1035 :collect registered
))
1037 (defun registered-systems ()
1038 "Return a list of the names of every registered system."
1039 (mapcar 'coerce-name
(registered-systems*)))
1041 (defun register-system (system)
1042 "Given a SYSTEM object, register it."
1043 (check-type system system
)
1044 (let ((name (component-name system
)))
1045 (check-type name string
)
1046 (asdf-message (compatfmt "~&~@<; ~@;Registering system ~3i~_~A~@:>~%") name
)
1047 (setf (gethash name
*registered-systems
*) system
)))
1049 (defun map-systems (fn)
1050 "Apply FN to each defined system.
1052 FN should be a function of one argument. It will be
1053 called with an object of type asdf:system."
1054 (loop :for registered
:being
:the
:hash-values
:of
*registered-systems
*
1055 :do
(funcall fn registered
)))
1058 ;;; Preloaded systems: in the image even if you can't find source files backing them.
1060 (defvar *preloaded-systems
* (make-hash-table :test
'equal
)
1061 "Registration table for preloaded systems.")
1063 (declaim (ftype (function (t) t
) mark-component-preloaded
)) ; defined in asdf/find-system
1065 (defun make-preloaded-system (name keys
)
1066 "Make a preloaded system of given NAME with build information from KEYS"
1067 (let ((system (apply 'make-instance
(getf keys
:class
'system
)
1068 :name name
:source-file
(getf keys
:source-file
)
1069 (remove-plist-keys '(:class
:name
:source-file
) keys
))))
1070 (mark-component-preloaded system
)
1073 (defun sysdef-preloaded-system-search (requested)
1074 "If REQUESTED names a system registered as preloaded, return a new system
1075 with its registration information."
1076 (let ((name (coerce-name requested
)))
1077 (multiple-value-bind (keys foundp
) (gethash name
*preloaded-systems
*)
1079 (make-preloaded-system name keys
)))))
1081 (defun ensure-preloaded-system-registered (name)
1082 "If there isn't a registered _defined_ system of given NAME,
1083 and a there is a registered _preloaded_ system of given NAME,
1084 then define and register said preloaded system."
1085 (if-let (system (and (not (registered-system name
)) (sysdef-preloaded-system-search name
)))
1086 (register-system system
)))
1088 (defun register-preloaded-system (system-name &rest keys
&key
(version t
) &allow-other-keys
)
1089 "Register a system as being preloaded. If the system has not been loaded from the filesystem
1090 yet, or if its build information is later cleared with CLEAR-SYSTEM, a dummy system will be
1091 registered without backing filesystem information, based on KEYS (e.g. to provide a VERSION).
1092 If VERSION is the default T, and a system was already loaded, then its version will be preserved."
1093 (let ((name (coerce-name system-name
)))
1094 (when (eql version t
)
1095 (if-let (system (registered-system name
))
1096 (setf (getf keys
:version
) (component-version system
))))
1097 (setf (gethash name
*preloaded-systems
*) keys
)
1098 (ensure-preloaded-system-registered system-name
)))
1101 ;;; Immutable systems: in the image and can't be reloaded from source.
1103 (defvar *immutable-systems
* nil
1104 "A hash-set (equal hash-table mapping keys to T) of systems that are immutable,
1105 i.e. already loaded in memory and not to be refreshed from the filesystem.
1106 They will be treated specially by find-system, and passed as :force-not argument to make-plan.
1108 For instance, to can deliver an image with many systems precompiled, that *will not* check the
1109 filesystem for them every time a user loads an extension, what more risk a problematic upgrade
1110 or catastrophic downgrade, before you dump an image, you may use:
1111 (map () 'asdf:register-immutable-system (asdf:already-loaded-systems))
1113 Note that direct access to this variable from outside ASDF is not supported.
1114 Please call REGISTER-IMMUTABLE-SYSTEM to add new immutable systems, and
1115 contact maintainers if you need a stable API to do more than that.")
1117 (defun sysdef-immutable-system-search (requested)
1118 (let ((name (coerce-name requested
)))
1119 (when (and *immutable-systems
* (gethash name
*immutable-systems
*))
1120 (or (registered-system requested
)
1121 (error 'formatted-system-definition-error
1122 :format-control
"Requested system ~A registered as an immutable-system, ~
1123 but not even registered as defined"
1124 :format-arguments
(list name
))))))
1126 (defun register-immutable-system (system-name &rest keys
)
1127 "Register SYSTEM-NAME as preloaded and immutable.
1128 It will automatically be considered as passed to FORCE-NOT in a plan."
1129 (let ((system-name (coerce-name system-name
)))
1130 (apply 'register-preloaded-system system-name keys
)
1131 (unless *immutable-systems
*
1132 (setf *immutable-systems
* (list-to-hash-set nil
)))
1133 (setf (gethash system-name
*immutable-systems
*) t
)))
1136 ;;; Making systems undefined.
1138 (defun clear-system (system)
1139 "Clear the entry for a SYSTEM in the database of systems previously defined.
1140 However if the system was registered as PRELOADED (which it is if it is IMMUTABLE),
1141 then a new system with the same name will be defined and registered in its place
1142 from which build details will have been cleared.
1143 Note that this does NOT in any way cause any of the code of the system to be unloaded.
1144 Returns T if system was or is now undefined, NIL if a new preloaded system was redefined."
1145 ;; There is no "unload" operation in Common Lisp, and
1146 ;; a general such operation cannot be portably written,
1147 ;; considering how much CL relies on side-effects to global data structures.
1148 (let ((name (coerce-name system
)))
1149 (remhash name
*registered-systems
*)
1150 (unset-asdf-cache-entry `(find-system ,name
))
1151 (not (ensure-preloaded-system-registered name
))))
1153 (defun clear-registered-systems ()
1154 "Clear all currently registered defined systems.
1155 Preloaded systems (including immutable ones) will be reset, other systems will be de-registered."
1156 (map () 'clear-system
(registered-systems)))
1159 ;;; Searching for system definitions
1161 ;; For the sake of keeping things reasonably neat, we adopt a convention that
1162 ;; only symbols are to be pushed to this list (rather than e.g. function objects),
1163 ;; which makes upgrade easier. Also, the name of these symbols shall start with SYSDEF-
1164 (defvar *system-definition-search-functions
* '()
1165 "A list that controls the ways that ASDF looks for system definitions.
1166 It contains symbols to be funcalled in order, with a requested system name as argument,
1167 until one returns a non-NIL result (if any), which must then be a fully initialized system object
1170 ;; Initialize and/or upgrade the *system-definition-search-functions*
1171 ;; so it doesn't contain obsolete symbols, and does contain the current ones.
1172 (defun cleanup-system-definition-search-functions ()
1173 (setf *system-definition-search-functions
*
1175 ;; Remove known-incompatible sysdef functions from old versions of asdf.
1176 ;; Order matters, so we can't just use set-difference.
1178 '(contrib-sysdef-search sysdef-find-asdf sysdef-preloaded-system-search
)))
1179 (remove-if #'(lambda (x) (member x obsolete
)) *system-definition-search-functions
*))
1180 ;; Tuck our defaults at the end of the list if they were absent.
1181 ;; This is imperfect, in case they were removed on purpose,
1182 ;; but then it will be the responsibility of whoever removes these symmbols
1183 ;; to upgrade asdf before he does such a thing rather than after.
1184 (remove-if #'(lambda (x) (member x
*system-definition-search-functions
*))
1185 '(sysdef-central-registry-search
1186 sysdef-source-registry-search
)))))
1187 (cleanup-system-definition-search-functions)
1189 ;; This (private) function does the search for a system definition using *s-d-s-f*;
1190 ;; it is to be called by locate-system.
1191 (defun search-for-system-definition (system)
1192 ;; Search for valid definitions of the system available in the current session.
1193 ;; Previous definitions as registered in *registered-systems* MUST NOT be considered;
1194 ;; they will be reconciled by locate-system then find-system.
1195 ;; There are two special treatments: first, specially search for objects being defined
1196 ;; in the current session, to avoid definition races between several files;
1197 ;; second, specially search for immutable systems, so they cannot be redefined.
1198 ;; Finally, use the search functions specified in *system-definition-search-functions*.
1199 (let ((name (coerce-name system
)))
1200 (flet ((try (f) (if-let ((x (funcall f name
))) (return-from search-for-system-definition x
))))
1201 (try 'find-system-if-being-defined
)
1202 (try 'sysdef-immutable-system-search
)
1203 (map () #'try
*system-definition-search-functions
*))))
1206 ;;; The legacy way of finding a system: the *central-registry*
1208 ;; This variable contains a list of directories to be lazily searched for the requested asd
1209 ;; by sysdef-central-registry-search.
1210 (defvar *central-registry
* nil
1211 "A list of 'system directory designators' ASDF uses to find systems.
1213 A 'system directory designator' is a pathname or an expression
1214 which evaluates to a pathname. For example:
1216 (setf asdf:*central-registry*
1217 (list '*default-pathname-defaults*
1218 #p\"/home/me/cl/systems/\"
1219 #p\"/usr/share/common-lisp/systems/\"))
1221 This variable is for backward compatibility.
1222 Going forward, we recommend new users should be using the source-registry.")
1224 ;; Function to look for an asd file of given NAME under a directory provided by DEFAULTS.
1225 ;; Return the truename of that file if it is found and TRUENAME is true.
1226 ;; Return NIL if the file is not found.
1227 ;; On Windows, follow shortcuts to .asd files.
1228 (defun probe-asd (name defaults
&key truename
)
1230 (when (directory-pathname-p defaults
)
1231 (if-let (file (probe-file*
1232 (ensure-absolute-pathname
1233 (parse-unix-namestring name
:type
"asd")
1234 #'(lambda () (ensure-absolute-pathname defaults
'get-pathname-defaults nil
))
1236 :truename truename
))
1238 #-
(or clisp genera
) ; clisp doesn't need it, plain genera doesn't have read-sequence(!)
1241 (when (physical-pathname-p defaults
)
1244 :defaults defaults
:case
:local
1245 :name
(strcat name
".asd")
1247 (when (probe-file* shortcut
)
1248 (ensure-pathname (parse-windows-shortcut shortcut
) :namestring
:native
)))))))))
1250 ;; Function to push onto *s-d-s-f* to use the *central-registry*
1251 (defun sysdef-central-registry-search (system)
1252 (let ((name (primary-system-name system
))
1257 (dolist (dir *central-registry
*)
1258 (let ((defaults (eval dir
))
1261 (cond ((directory-pathname-p defaults
)
1262 (let* ((file (probe-asd name defaults
:truename
*resolve-symlinks
*)))
1267 (let* ((*print-circle
* nil
)
1270 (compatfmt "~@<While searching for system ~S: ~3i~_~S evaluated to ~S which is not an absolute directory.~@:>")
1271 system dir defaults
)))
1273 (remove-entry-from-registry ()
1274 :report
"Remove entry from *central-registry* and continue"
1275 (push dir to-remove
))
1276 (coerce-entry-to-directory ()
1277 :test
(lambda (c) (declare (ignore c
))
1278 (and (not (directory-pathname-p defaults
))
1279 (directory-pathname-p
1281 (ensure-directory-pathname defaults
)))))
1283 (format s
(compatfmt "~@<Coerce entry to ~a, replace ~a and continue.~@:>")
1285 (push (cons dir directorized
) to-replace
))))))))
1287 (dolist (dir to-remove
)
1288 (setf *central-registry
* (remove dir
*central-registry
*)))
1289 (dolist (pair to-replace
)
1290 (let* ((current (car pair
))
1292 (position (position current
*central-registry
*)))
1293 (setf *central-registry
*
1294 (append (subseq *central-registry
* 0 position
)
1296 (subseq *central-registry
* (1+ position
)))))))))))
1298 ;;;; -------------------------------------------------------------------------
1301 (uiop/package
:define-package
:asdf
/action
1302 (:nicknames
:asdf-action
)
1303 (:recycle
:asdf
/action
:asdf
/plan
:asdf
)
1304 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
:asdf
/component
:asdf
/operation
)
1305 (:import-from
:asdf
/operation
#:check-operation-constructor
)
1306 (:import-from
:asdf
/component
#:%additional-input-files
)
1308 #:action
#:define-convenience-action-methods
1309 #:action-description
#:format-action
1310 #:downward-operation
#:upward-operation
#:sideway-operation
#:selfward-operation
1311 #:non-propagating-operation
1312 #:component-depends-on
1313 #:input-files
#:output-files
#:output-file
#:operation-done-p
1314 #:action-operation
#:action-component
#:make-action
1315 #:component-operation-time
#:mark-operation-done
#:compute-action-stamp
1316 #:perform
#:perform-with-restarts
#:retry
#:accept
1317 #:action-path
#:find-action
1318 #:operation-definition-warning
#:operation-definition-error
;; condition
1320 #:circular-dependency
#:circular-dependency-actions
1321 #:call-while-visiting-action
#:while-visiting-action
1322 #:additional-input-files
))
1323 (in-package :asdf
/action
)
1325 (eval-when (#-lispworks
:compile-toplevel
:load-toplevel
:execute
) ;; LispWorks issues spurious warning
1328 "A pair of operation and component uniquely identifies a node in the dependency graph
1329 of steps to be performed while building a system."
1330 '(cons operation component
))
1332 (deftype operation-designator
()
1333 "An operation designates itself. NIL designates a context-dependent current operation,
1334 and a class-name or class designates the canonical instance of the designated class."
1335 '(or operation null symbol class
)))
1337 ;;; these are pseudo accessors -- let us abstract away the CONS cell representation of plan
1339 (with-upgradability ()
1340 (defun make-action (operation component
)
1341 (cons operation component
))
1342 (defun action-operation (action)
1344 (defun action-component (action)
1347 ;;;; Reified representation for storage or debugging. Note: an action is identified by its class.
1348 (with-upgradability ()
1349 (defun action-path (action)
1350 "A readable data structure that identifies the action."
1352 (let ((o (action-operation action
))
1353 (c (action-component action
)))
1354 (cons (type-of o
) (component-find-path c
)))))
1355 (defun find-action (path)
1356 "Reconstitute an action from its action-path"
1357 (destructuring-bind (o . c
) path
(make-action (make-operation o
) (find-component () c
)))))
1359 ;;;; Convenience methods
1360 (with-upgradability ()
1361 ;; A macro that defines convenience methods for a generic function (gf) that
1362 ;; dispatches on operation and component. The convenience methods allow users
1363 ;; to call the gf with operation and/or component designators, that the
1364 ;; methods will resolve into actual operation and component objects, so that
1365 ;; the users can interact using readable designators, but developers only have
1366 ;; to write methods that handle operation and component objects.
1367 ;; FUNCTION is the generic function name
1368 ;; FORMALS is its list of arguments, which must include OPERATION and COMPONENT.
1369 ;; IF-NO-OPERATION is a form (defaults to NIL) describing what to do if no operation is found.
1370 ;; IF-NO-COMPONENT is a form (defaults to NIL) describing what to do if no component is found.
1371 (defmacro define-convenience-action-methods
1372 (function formals
&key if-no-operation if-no-component
)
1373 (let* ((rest (gensym "REST"))
1374 (found (gensym "FOUND"))
1375 (keyp (equal (last formals
) '(&key
)))
1376 (formals-no-key (if keyp
(butlast formals
) formals
))
1377 (len (length formals-no-key
))
1378 (operation 'operation
)
1379 (component 'component
)
1380 (opix (position operation formals
))
1381 (coix (position component formals
))
1382 (prefix (subseq formals
0 opix
))
1383 (suffix (subseq formals
(1+ coix
) len
))
1384 (more-args (when keyp
`(&rest
,rest
&key
&allow-other-keys
))))
1385 (assert (and (integerp opix
) (integerp coix
) (= coix
(1+ opix
))))
1386 (flet ((next-method (o c
)
1388 `(apply ',function
,@prefix
,o
,c
,@suffix
,rest
)
1389 `(,function
,@prefix
,o
,c
,@suffix
))))
1391 (defmethod ,function
(,@prefix
(,operation string
) ,component
,@suffix
,@more-args
)
1392 (declare (notinline ,function
))
1393 (let ((,component
(find-component () ,component
))) ;; do it first, for defsystem-depends-on
1394 ,(next-method `(safe-read-from-string ,operation
:package
:asdf
/interface
) component
)))
1395 (defmethod ,function
(,@prefix
(,operation symbol
) ,component
,@suffix
,@more-args
)
1396 (declare (notinline ,function
))
1399 `(make-operation ,operation
)
1400 `(or (find-component () ,component
) ,if-no-component
))
1402 (defmethod ,function
(,@prefix
(,operation operation
) ,component
,@suffix
,@more-args
)
1403 (declare (notinline ,function
))
1404 (if (typep ,component
'component
)
1405 (error "No defined method for ~S on ~/asdf-action:format-action/"
1406 ',function
(make-action ,operation
,component
))
1407 (if-let (,found
(find-component () ,component
))
1408 ,(next-method operation found
)
1409 ,if-no-component
))))))))
1412 ;;;; Self-description
1413 (with-upgradability ()
1414 (defgeneric action-description
(operation component
)
1415 (:documentation
"returns a phrase that describes performing this operation
1416 on this component, e.g. \"loading /a/b/c\".
1417 You can put together sentences using this phrase."))
1418 (defmethod action-description (operation component
)
1419 (format nil
(compatfmt "~@<~A on ~A~@:>")
1420 operation component
))
1422 (defun format-action (stream action
&optional colon-p at-sign-p
)
1423 "FORMAT helper to display an action's action-description.
1424 Use it in FORMAT control strings as ~/asdf-action:format-action/"
1425 (assert (null colon-p
)) (assert (null at-sign-p
))
1426 (destructuring-bind (operation . component
) action
1427 (princ (action-description operation component
) stream
))))
1430 ;;;; Detection of circular dependencies
1431 (with-upgradability ()
1432 (defun (action-valid-p) (operation component
)
1433 "Is this action valid to include amongst dependencies?"
1434 ;; If either the operation or component was resolved to nil, the action is invalid.
1435 ;; :if-feature will invalidate actions on components for which the features don't apply.
1436 (and operation component
1437 (if-let (it (component-if-feature component
)) (featurep it
) t
)))
1439 (define-condition circular-dependency
(system-definition-error)
1440 ((actions :initarg
:actions
:reader circular-dependency-actions
))
1441 (:report
(lambda (c s
)
1442 (format s
(compatfmt "~@<Circular dependency: ~3i~_~S~@:>")
1443 (circular-dependency-actions c
)))))
1445 (defun call-while-visiting-action (operation component fun
)
1446 "Detect circular dependencies"
1447 (with-asdf-session ()
1448 (with-accessors ((action-set visiting-action-set
)
1449 (action-list visiting-action-list
)) *asdf-session
*
1450 (let ((action (cons operation component
)))
1451 (when (gethash action action-set
)
1452 (error 'circular-dependency
:actions
1453 (member action
(reverse action-list
) :test
'equal
)))
1454 (setf (gethash action action-set
) t
)
1455 (push action action-list
)
1459 (setf (gethash action action-set
) nil
))))))
1461 ;; Syntactic sugar for call-while-visiting-action
1462 (defmacro while-visiting-action
((o c
) &body body
)
1463 `(call-while-visiting-action ,o
,c
#'(lambda () ,@body
))))
1467 (with-upgradability ()
1468 (defgeneric component-depends-on
(operation component
) ;; ASDF4: rename to component-dependencies
1470 "Returns a list of dependencies needed by the component to perform
1471 the operation. A dependency has one of the following forms:
1473 (<operation> <component>*), where <operation> is an operation designator
1474 with respect to FIND-OPERATION in the context of the OPERATION argument,
1475 and each <component> is a component designator with respect to
1476 FIND-COMPONENT in the context of the COMPONENT argument,
1477 and means that the component depends on
1478 <operation> having been performed on each <component>;
1480 [Note: an <operation> is an operation designator -- it can be either an
1481 operation name or an operation object. Similarly, a <component> may be
1482 a component name or a component object. Also note that, the degenerate
1483 case of (<operation>) is a no-op.]
1485 Methods specialized on subclasses of existing component types
1486 should usually append the results of CALL-NEXT-METHOD to the list."))
1487 (define-convenience-action-methods component-depends-on
(operation component
))
1489 (defmethod component-depends-on :around
((o operation
) (c component
))
1490 (do-asdf-cache `(component-depends-on ,o
,c
)
1491 (call-next-method))))
1494 ;;;; upward-operation, downward-operation, sideway-operation, selfward-operation
1495 ;; These together handle actions that propagate along the component hierarchy or operation universe.
1496 (with-upgradability ()
1497 (defclass downward-operation
(operation)
1498 ((downward-operation
1499 :initform nil
:reader downward-operation
1500 :type operation-designator
:allocation
:class
))
1501 (:documentation
"A DOWNWARD-OPERATION's dependencies propagate down the component hierarchy.
1502 I.e., if O is a DOWNWARD-OPERATION and its DOWNWARD-OPERATION slot designates operation D, then
1503 the action (O . M) of O on module M will depends on each of (D . C) for each child C of module M.
1504 The default value for slot DOWNWARD-OPERATION is NIL, which designates the operation O itself.
1505 E.g. in order for a MODULE to be loaded with LOAD-OP (resp. compiled with COMPILE-OP), all the
1506 children of the MODULE must have been loaded with LOAD-OP (resp. compiled with COMPILE-OP."))
1507 (defun downward-operation-depends-on (o c
)
1508 `((,(or (downward-operation o
) o
) ,@(component-children c
))))
1509 (defmethod component-depends-on ((o downward-operation
) (c parent-component
))
1510 `(,@(downward-operation-depends-on o c
) ,@(call-next-method)))
1512 (defclass upward-operation
(operation)
1514 :initform nil
:reader upward-operation
1515 :type operation-designator
:allocation
:class
))
1516 (:documentation
"An UPWARD-OPERATION has dependencies that propagate up the component hierarchy.
1517 I.e., if O is an instance of UPWARD-OPERATION, and its UPWARD-OPERATION slot designates operation U,
1518 then the action (O . C) of O on a component C that has the parent P will depends on (U . P).
1519 The default value for slot UPWARD-OPERATION is NIL, which designates the operation O itself.
1520 E.g. in order for a COMPONENT to be prepared for loading or compiling with PREPARE-OP, its PARENT
1521 must first be prepared for loading or compiling with PREPARE-OP."))
1522 ;; For backward-compatibility reasons, a system inherits from module and is a child-component
1523 ;; so we must guard against this case. ASDF4: remove that.
1524 (defun upward-operation-depends-on (o c
)
1525 (if-let (p (component-parent c
)) `((,(or (upward-operation o
) o
) ,p
))))
1526 (defmethod component-depends-on ((o upward-operation
) (c child-component
))
1527 `(,@(upward-operation-depends-on o c
) ,@(call-next-method)))
1529 (defclass sideway-operation
(operation)
1531 :initform nil
:reader sideway-operation
1532 :type operation-designator
:allocation
:class
))
1533 (:documentation
"A SIDEWAY-OPERATION has dependencies that propagate \"sideway\" to siblings
1534 that a component depends on. I.e. if O is a SIDEWAY-OPERATION, and its SIDEWAY-OPERATION slot
1535 designates operation S (where NIL designates O itself), then the action (O . C) of O on component C
1536 depends on each of (S . D) where D is a declared dependency of C.
1537 E.g. in order for a COMPONENT to be prepared for loading or compiling with PREPARE-OP,
1538 each of its declared dependencies must first be loaded as by LOAD-OP."))
1539 (defun sideway-operation-depends-on (o c
)
1540 `((,(or (sideway-operation o
) o
) ,@(component-sideway-dependencies c
))))
1541 (defmethod component-depends-on ((o sideway-operation
) (c component
))
1542 `(,@(sideway-operation-depends-on o c
) ,@(call-next-method)))
1544 (defclass selfward-operation
(operation)
1545 ((selfward-operation
1546 ;; NB: no :initform -- if an operation depends on others, it must explicitly specify which
1547 :type
(or operation-designator list
) :reader selfward-operation
:allocation
:class
))
1548 (:documentation
"A SELFWARD-OPERATION depends on another operation on the same component.
1549 I.e., if O is a SELFWARD-OPERATION, and its SELFWARD-OPERATION designates a list of operations L,
1550 then the action (O . C) of O on component C depends on each (S . C) for S in L.
1551 E.g. before a component may be loaded by LOAD-OP, it must have been compiled by COMPILE-OP.
1552 A operation-designator designates a singleton list of the designated operation;
1553 a list of operation-designators designates the list of designated operations;
1554 NIL is not a valid operation designator in that context. Note that any dependency
1555 ordering between the operations in a list of SELFWARD-OPERATION should be specified separately
1556 in the respective operation's COMPONENT-DEPENDS-ON methods so that they be scheduled properly."))
1557 (defun selfward-operation-depends-on (o c
)
1558 (loop :for op
:in
(ensure-list (selfward-operation o
)) :collect
`(,op
,c
)))
1559 (defmethod component-depends-on ((o selfward-operation
) (c component
))
1560 `(,@(selfward-operation-depends-on o c
) ,@(call-next-method)))
1562 (defclass non-propagating-operation
(operation)
1564 (:documentation
"A NON-PROPAGATING-OPERATION is an operation that propagates
1565 no dependencies whatsoever. It is supplied in order that the programmer be able
1566 to specify that s/he is intentionally specifying an operation which invokes no
1570 ;;;---------------------------------------------------------------------------
1571 ;;; Help programmers catch obsolete OPERATION subclasses
1572 ;;;---------------------------------------------------------------------------
1573 (with-upgradability ()
1574 (define-condition operation-definition-warning
(simple-warning)
1576 (:documentation
"Warning condition related to definition of obsolete OPERATION objects."))
1578 (define-condition operation-definition-error
(simple-error)
1580 (:documentation
"Error condition related to definition of incorrect OPERATION objects."))
1582 (defmethod initialize-instance :before
((o operation
) &key
)
1583 (check-operation-constructor)
1584 (unless (typep o
'(or downward-operation upward-operation sideway-operation
1585 selfward-operation non-propagating-operation
))
1586 (warn 'operation-definition-warning
1588 "No dependency propagating scheme specified for operation class ~S.
1589 The class needs to be updated for ASDF 3.1 and specify appropriate propagation mixins."
1590 :format-arguments
(list (type-of o
)))))
1592 (defmethod initialize-instance :before
((o non-propagating-operation
) &key
)
1593 (when (typep o
'(or downward-operation upward-operation sideway-operation selfward-operation
))
1594 (error 'operation-definition-error
1596 "Inconsistent class: ~S
1597 NON-PROPAGATING-OPERATION is incompatible with propagating operation classes as superclasses."
1599 (list (type-of o
)))))
1601 (defun backward-compatible-depends-on (o c
)
1602 "DEPRECATED: all subclasses of OPERATION used in ASDF should inherit from one of
1603 DOWNWARD-OPERATION UPWARD-OPERATION SIDEWAY-OPERATION SELFWARD-OPERATION NON-PROPAGATING-OPERATION.
1604 The function BACKWARD-COMPATIBLE-DEPENDS-ON temporarily provides ASDF2 behaviour for those that
1605 don't. In the future this functionality will be removed, and the default will be no propagation."
1606 (uiop/version
::notify-deprecated-function
1607 (version-deprecation *asdf-version
* :style-warning
"3.2")
1608 `(backward-compatible-depends-on :for-operation
,o
))
1609 `(,@(sideway-operation-depends-on o c
)
1610 ,@(when (typep c
'parent-component
) (downward-operation-depends-on o c
))))
1612 (defmethod component-depends-on ((o operation
) (c component
))
1613 `(;; Normal behavior, to allow user-specified in-order-to dependencies
1614 ,@(cdr (assoc (type-of o
) (component-in-order-to c
)))
1615 ;; For backward-compatibility with ASDF2, any operation that doesn't specify propagation
1616 ;; or non-propagation through an appropriate mixin will be downward and sideway.
1617 ,@(unless (typep o
'(or downward-operation upward-operation sideway-operation
1618 selfward-operation non-propagating-operation
))
1619 (backward-compatible-depends-on o c
))))
1621 (defmethod downward-operation ((o operation
)) nil
)
1622 (defmethod sideway-operation ((o operation
)) nil
))
1625 ;;;---------------------------------------------------------------------------
1626 ;;; End of OPERATION class checking
1627 ;;;---------------------------------------------------------------------------
1630 ;;;; Inputs, Outputs, and invisible dependencies
1631 (with-upgradability ()
1632 (defgeneric output-files
(operation component
)
1633 (:documentation
"Methods for this function return two values: a list of output files
1634 corresponding to this action, and a boolean indicating if they have already been subjected
1635 to relevant output translations and should not be further translated.
1637 Methods on PERFORM *must* call this function to determine where their outputs are to be located.
1638 They may rely on the order of the files to discriminate between outputs.
1640 (defgeneric input-files
(operation component
)
1641 (:documentation
"A list of input files corresponding to this action.
1643 Methods on PERFORM *must* call this function to determine where their inputs are located.
1644 They may rely on the order of the files to discriminate between inputs.
1646 (defgeneric operation-done-p
(operation component
)
1647 (:documentation
"Returns a boolean which is NIL if the action must be performed (again)."))
1648 (define-convenience-action-methods output-files
(operation component
))
1649 (define-convenience-action-methods input-files
(operation component
))
1650 (define-convenience-action-methods operation-done-p
(operation component
))
1652 (defmethod operation-done-p ((o operation
) (c component
))
1655 ;; Translate output files, unless asked not to. Memoize the result.
1656 (defmethod output-files :around
((operation t
) (component t
))
1657 (do-asdf-cache `(output-files ,operation
,component
)
1659 (multiple-value-bind (pathnames fixedp
) (call-next-method)
1660 ;; 1- Make sure we have absolute pathnames
1661 (let* ((directory (pathname-directory-pathname
1662 (component-pathname (find-component () component
))))
1665 :for pathname
:in pathnames
1666 :collect
(ensure-absolute-pathname pathname directory
))))
1667 ;; 2- Translate those pathnames as required
1670 (mapcar *output-translation-function
* absolute-pathnames
))))
1672 (defmethod output-files ((o operation
) (c component
))
1674 (defun output-file (operation component
)
1675 "The unique output file of performing OPERATION on COMPONENT"
1676 (let ((files (output-files operation component
)))
1677 (assert (length=n-p files
1))
1680 (defgeneric additional-input-files
(operation component
)
1681 (:documentation
"Additional input files for the operation on this
1682 component. These are files that are inferred, rather than
1683 explicitly specified, and these are typically NOT files that
1684 undergo operations directly. Instead, they are files that it is
1685 important for ASDF to know about in order to compute operation times,etc."))
1686 (define-convenience-action-methods additional-input-files
(operation component
))
1687 (defmethod additional-input-files ((op operation
) (comp component
))
1688 (cdr (assoc op
(%additional-input-files comp
))))
1690 ;; Memoize input files.
1691 (defmethod input-files :around
(operation component
)
1692 (do-asdf-cache `(input-files ,operation
,component
)
1693 ;; get the additional input files, if any
1694 (append (call-next-method)
1695 ;; must come after the first, for other code that
1696 ;; assumes the first will be the "key" file
1697 (additional-input-files operation component
))))
1699 ;; By default an action has no input-files.
1700 (defmethod input-files ((o operation
) (c component
))
1703 ;; An action with a selfward-operation by default gets its input-files from the output-files of
1704 ;; the actions using selfward-operations it depends on (and the same component),
1705 ;; or if there are none, on the component-pathname of the component if it's a file
1706 ;; -- and then on the results of the next-method.
1707 (defmethod input-files ((o selfward-operation
) (c component
))
1708 `(,@(or (loop :for dep-o
:in
(ensure-list (selfward-operation o
))
1709 :append
(or (output-files dep-o c
) (input-files dep-o c
)))
1710 (if-let ((pathname (component-pathname c
)))
1711 (and (file-pathname-p pathname
) (list pathname
))))
1712 ,@(call-next-method))))
1715 ;;;; Done performing
1716 (with-upgradability ()
1717 ;; ASDF4: hide it behind plan-action-stamp
1718 (defgeneric component-operation-time
(operation component
)
1719 (:documentation
"Return the timestamp for when an action was last performed"))
1720 (defgeneric (setf component-operation-time
) (time operation component
)
1721 (:documentation
"Update the timestamp for when an action was last performed"))
1722 (define-convenience-action-methods component-operation-time
(operation component
))
1724 ;; ASDF4: hide it behind (setf plan-action-stamp)
1725 (defgeneric mark-operation-done
(operation component
)
1726 (:documentation
"Mark a action as having been just done.
1728 Updates the action's COMPONENT-OPERATION-TIME to match the COMPUTE-ACTION-STAMP
1729 using the JUST-DONE flag."))
1730 (defgeneric compute-action-stamp
(plan- operation component
&key just-done
)
1731 ;; NB: using plan- rather than plan above allows clisp to upgrade from 2.26(!)
1732 (:documentation
"Has this action been successfully done already,
1733 and at what known timestamp has it been done at or will it be done at?
1734 * PLAN is a plan object modelling future effects of actions,
1735 or NIL to denote what actually happened.
1736 * OPERATION and COMPONENT denote the action.
1737 Takes keyword JUST-DONE:
1738 * JUST-DONE is a boolean that is true if the action was just successfully performed,
1739 at which point we want compute the actual stamp and warn if files are missing;
1740 otherwise we are making plans, anticipating the effects of the action.
1742 * a STAMP saying when it was done or will be done,
1743 or T if the action involves files that need to be recomputed.
1744 * a boolean DONE-P that indicates whether the action has actually been done,
1745 and both its output-files and its in-image side-effects are up to date."))
1747 (defmethod component-operation-time ((o operation
) (c component
))
1748 (gethash o
(component-operation-times c
)))
1750 (defmethod (setf component-operation-time
) (stamp (o operation
) (c component
))
1751 (assert stamp
() "invalid null stamp for ~A" (action-description o c
))
1752 (setf (gethash o
(component-operation-times c
)) stamp
))
1754 (defmethod mark-operation-done ((o operation
) (c component
))
1755 (let ((stamp (compute-action-stamp nil o c
:just-done t
)))
1756 (assert stamp
() "Failed to compute a stamp for completed action ~A" (action-description o c
))1
1757 (setf (component-operation-time o c
) stamp
))))
1761 (with-upgradability ()
1762 (defgeneric perform
(operation component
)
1763 (:documentation
"PERFORM an action, consuming its input-files and building its output-files"))
1764 (define-convenience-action-methods perform
(operation component
))
1766 (defmethod perform :around
((o operation
) (c component
))
1767 (while-visiting-action (o c
) (call-next-method)))
1768 (defmethod perform :before
((o operation
) (c component
))
1769 (ensure-all-directories-exist (output-files o c
)))
1770 (defmethod perform :after
((o operation
) (c component
))
1771 (mark-operation-done o c
))
1772 (defmethod perform ((o operation
) (c parent-component
))
1774 (defmethod perform ((o operation
) (c source-file
))
1775 ;; For backward compatibility, don't error on operations that don't specify propagation.
1776 (when (typep o
'(or downward-operation upward-operation sideway-operation
1777 selfward-operation non-propagating-operation
))
1779 (compatfmt "~@<Required method ~S not implemented for ~/asdf-action:format-action/~@:>")
1780 'perform
(make-action o c
))))
1782 ;; The restarts of the perform-with-restarts variant matter in an interactive context.
1783 ;; The retry strategies of p-w-r itself, and/or the background workers of a multiprocess build
1784 ;; may call perform directly rather than call p-w-r.
1785 (defgeneric perform-with-restarts
(operation component
)
1786 (:documentation
"PERFORM an action in a context where suitable restarts are in place."))
1787 (defmethod perform-with-restarts (operation component
)
1788 (perform operation component
))
1789 (defmethod perform-with-restarts :around
(operation component
)
1792 (return (call-next-method))
1796 (format s
(compatfmt "~@<Retry ~A.~@:>")
1797 (action-description operation component
))))
1801 (format s
(compatfmt "~@<Continue, treating ~A as having been successful.~@:>")
1802 (action-description operation component
)))
1803 (mark-operation-done operation component
)
1805 ;;;; -------------------------------------------------------------------------
1806 ;;;; Actions to build Common Lisp software
1808 (uiop/package
:define-package
:asdf
/lisp-action
1809 (:recycle
:asdf
/lisp-action
:asdf
)
1810 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
1811 :asdf
/component
:asdf
/system
:asdf
/operation
:asdf
/action
)
1814 #:cl-source-file
#:cl-source-file.cl
#:cl-source-file.lsp
1815 #:basic-load-op
#:basic-compile-op
1816 #:load-op
#:prepare-op
#:compile-op
#:test-op
#:load-source-op
#:prepare-source-op
1817 #:call-with-around-compile-hook
1818 #:perform-lisp-compilation
#:perform-lisp-load-fasl
#:perform-lisp-load-source
1819 #:lisp-compilation-output-files
))
1820 (in-package :asdf
/lisp-action
)
1823 ;;;; Component classes
1824 (with-upgradability ()
1825 (defclass cl-source-file
(source-file)
1826 ((type :initform
"lisp"))
1827 (:documentation
"Component class for a Common Lisp source file (using type \"lisp\")"))
1828 (defclass cl-source-file.cl
(cl-source-file)
1829 ((type :initform
"cl"))
1830 (:documentation
"Component class for a Common Lisp source file using type \"cl\""))
1831 (defclass cl-source-file.lsp
(cl-source-file)
1832 ((type :initform
"lsp"))
1833 (:documentation
"Component class for a Common Lisp source file using type \"lsp\"")))
1836 ;;;; Operation classes
1837 (with-upgradability ()
1838 (defclass basic-load-op
(operation) ()
1839 (:documentation
"Base class for operations that apply the load-time effects of a file"))
1840 (defclass basic-compile-op
(operation) ()
1841 (:documentation
"Base class for operations that apply the compile-time effects of a file")))
1844 ;;; Our default operations: loading into the current lisp image
1845 (with-upgradability ()
1846 (defclass prepare-op
(upward-operation sideway-operation
)
1847 ((sideway-operation :initform
'load-op
:allocation
:class
))
1848 (:documentation
"Load the dependencies for the COMPILE-OP or LOAD-OP of a given COMPONENT."))
1849 (defclass load-op
(basic-load-op downward-operation selfward-operation
)
1850 ;; NB: even though compile-op depends on prepare-op it is not needed-in-image-p,
1851 ;; so we need to directly depend on prepare-op for its side-effects in the current image.
1852 ((selfward-operation :initform
'(prepare-op compile-op
) :allocation
:class
))
1853 (:documentation
"Operation for loading the compiled FASL for a Lisp file"))
1854 (defclass compile-op
(basic-compile-op downward-operation selfward-operation
)
1855 ((selfward-operation :initform
'prepare-op
:allocation
:class
))
1856 (:documentation
"Operation for compiling a Lisp file to a FASL"))
1859 (defclass prepare-source-op
(upward-operation sideway-operation
)
1860 ((sideway-operation :initform
'load-source-op
:allocation
:class
))
1861 (:documentation
"Operation for loading the dependencies of a Lisp file as source."))
1862 (defclass load-source-op
(basic-load-op downward-operation selfward-operation
)
1863 ((selfward-operation :initform
'prepare-source-op
:allocation
:class
))
1864 (:documentation
"Operation for loading a Lisp file as source."))
1866 (defclass test-op
(selfward-operation)
1867 ((selfward-operation :initform
'load-op
:allocation
:class
))
1868 (:documentation
"Operation for running the tests for system.
1869 If the tests fail, an error will be signaled.")))
1872 ;;;; Methods for prepare-op, compile-op and load-op
1875 (with-upgradability ()
1876 (defmethod action-description ((o prepare-op
) (c component
))
1877 (format nil
(compatfmt "~@<loading dependencies of ~3i~_~A~@:>") c
))
1878 (defmethod perform ((o prepare-op
) (c component
))
1880 (defmethod input-files ((o prepare-op
) (s system
))
1881 (if-let (it (system-source-file s
)) (list it
))))
1884 (with-upgradability ()
1885 (defmethod action-description ((o compile-op
) (c component
))
1886 (format nil
(compatfmt "~@<compiling ~3i~_~A~@:>") c
))
1887 (defmethod action-description ((o compile-op
) (c parent-component
))
1888 (format nil
(compatfmt "~@<completing compilation for ~3i~_~A~@:>") c
))
1889 (defgeneric call-with-around-compile-hook
(component thunk
)
1890 (:documentation
"A method to be called around the PERFORM'ing of actions that apply the
1891 compile-time side-effects of file (i.e., COMPILE-OP or LOAD-SOURCE-OP). This method can be used
1892 to setup readtables and other variables that control reading, macroexpanding, and compiling, etc.
1893 Note that it will NOT be called around the performing of LOAD-OP."))
1894 (defmethod call-with-around-compile-hook ((c component
) function
)
1895 (call-around-hook (around-compile-hook c
) function
))
1896 (defun perform-lisp-compilation (o c
)
1897 "Perform the compilation of the Lisp file associated to the specified action (O . C)."
1898 (let (;; Before 2.26.53, that was unfortunately component-pathname. Now,
1899 ;; we consult input-files, the first of which should be the one to compile-file
1900 (input-file (first (input-files o c
)))
1901 ;; On some implementations, there are more than one output-file,
1902 ;; but the first one should always be the primary fasl that gets loaded.
1903 (outputs (output-files o c
)))
1904 (multiple-value-bind (output warnings-p failure-p
)
1908 #+(or clasp ecl mkcl
) object-file
1910 warnings-file
&rest rest
) outputs
1911 ;; Allow for extra outputs that are not of type warnings-file
1912 ;; The way we do it is kludgy. In ASDF4, output-files shall not be positional.
1913 (declare (ignore rest
))
1915 (unless (equal (pathname-type warnings-file
) (warnings-file-type))
1916 (setf warnings-file nil
)))
1917 (call-with-around-compile-hook
1918 c
#'(lambda (&rest flags
)
1919 (apply 'compile-file
* input-file
1920 :output-file output-file
1921 :external-format
(component-external-format c
)
1922 :warnings-file warnings-file
1924 #+clisp
(list :lib-file lib-file
)
1925 #+(or clasp ecl mkcl
) (list :object-file object-file
)
1927 (check-lisp-compile-results output warnings-p failure-p
1928 "~/asdf-action::format-action/" (list (cons o c
))))))
1929 (defun report-file-p (f)
1930 "Is F a build report file containing, e.g., warnings to check?"
1931 (equalp (pathname-type f
) "build-report"))
1932 (defun perform-lisp-warnings-check (o c
)
1933 "Check the warnings associated with the dependencies of an action."
1934 (let* ((expected-warnings-files (remove-if-not #'warnings-file-p
(input-files o c
)))
1935 (actual-warnings-files (loop :for w
:in expected-warnings-files
1936 :when
(get-file-stamp w
)
1938 :else
:do
(warn "Missing warnings file ~S while ~A"
1939 w
(action-description o c
)))))
1940 (check-deferred-warnings actual-warnings-files
)
1941 (let* ((output (output-files o c
))
1942 (report (find-if #'report-file-p output
)))
1944 (with-open-file (s report
:direction
:output
:if-exists
:supersede
)
1945 (format s
":success~%"))))))
1946 (defmethod perform ((o compile-op
) (c cl-source-file
))
1947 (perform-lisp-compilation o c
))
1948 (defun lisp-compilation-output-files (o c
)
1949 "Compute the output-files for compiling the Lisp file for the specified action (O . C),
1950 an OPERATION and a COMPONENT."
1951 (let* ((i (first (input-files o c
)))
1952 (f (compile-file-pathname
1953 i
#+clasp
:output-type
#+ecl
:type
#+(or clasp ecl
) :fasl
1954 #+mkcl
:fasl-p
#+mkcl t
)))
1955 `(,f
;; the fasl is the primary output, in first position
1957 ,@(unless nil
;; was (use-ecl-byte-compiler-p)
1958 `(,(compile-file-pathname i
:output-type
:object
)))
1960 ,@`(,(make-pathname :type
"lib" :defaults f
))
1962 ,@(unless (use-ecl-byte-compiler-p)
1963 `(,(compile-file-pathname i
:type
:object
)))
1965 ,(compile-file-pathname i
:fasl-p nil
) ;; object file
1966 ,@(when (and *warnings-file-type
* (not (builtin-system-p (component-system c
))))
1967 `(,(make-pathname :type
*warnings-file-type
* :defaults f
))))))
1968 (defmethod output-files ((o compile-op
) (c cl-source-file
))
1969 (lisp-compilation-output-files o c
))
1970 (defmethod perform ((o compile-op
) (c static-file
))
1973 ;; Performing compile-op on a system will check the deferred warnings for the system
1974 (defmethod perform ((o compile-op
) (c system
))
1975 (when (and *warnings-file-type
* (not (builtin-system-p c
)))
1976 (perform-lisp-warnings-check o c
)))
1977 (defmethod input-files ((o compile-op
) (c system
))
1978 (when (and *warnings-file-type
* (not (builtin-system-p c
)))
1979 ;; The most correct way to do it would be to use:
1980 ;; (collect-dependencies o c :other-systems nil :keep-operation 'compile-op :keep-component 'cl-source-file)
1981 ;; but it's expensive and we don't care too much about file order or ASDF extensions.
1982 (loop :for sub
:in
(sub-components c
:type
'cl-source-file
)
1983 :nconc
(remove-if-not 'warnings-file-p
(output-files o sub
)))))
1984 (defmethod output-files ((o compile-op
) (c system
))
1985 (when (and *warnings-file-type
* (not (builtin-system-p c
)))
1986 (if-let ((pathname (component-pathname c
)))
1987 (list (subpathname pathname
(coerce-filename c
) :type
"build-report"))))))
1990 (with-upgradability ()
1991 (defmethod action-description ((o load-op
) (c cl-source-file
))
1992 (format nil
(compatfmt "~@<loading FASL for ~3i~_~A~@:>") c
))
1993 (defmethod action-description ((o load-op
) (c parent-component
))
1994 (format nil
(compatfmt "~@<completing load for ~3i~_~A~@:>") c
))
1995 (defmethod action-description ((o load-op
) (c component
))
1996 (format nil
(compatfmt "~@<loading ~3i~_~A~@:>") c
))
1997 (defmethod perform-with-restarts ((o load-op
) (c cl-source-file
))
2000 (return (call-next-method))
2003 (format s
"Recompile ~a and try loading it again"
2004 (component-name c
)))
2005 (perform (find-operation o
'compile-op
) c
)))))
2006 (defun perform-lisp-load-fasl (o c
)
2007 "Perform the loading of a FASL associated to specified action (O . C),
2008 an OPERATION and a COMPONENT."
2009 (if-let (fasl (first (input-files o c
)))
2011 (defmethod perform ((o load-op
) (c cl-source-file
))
2012 (perform-lisp-load-fasl o c
))
2013 (defmethod perform ((o load-op
) (c static-file
))
2017 ;;;; prepare-source-op, load-source-op
2019 ;;; prepare-source-op
2020 (with-upgradability ()
2021 (defmethod action-description ((o prepare-source-op
) (c component
))
2022 (format nil
(compatfmt "~@<loading source for dependencies of ~3i~_~A~@:>") c
))
2023 (defmethod input-files ((o prepare-source-op
) (s system
))
2024 (if-let (it (system-source-file s
)) (list it
)))
2025 (defmethod perform ((o prepare-source-op
) (c component
))
2029 (with-upgradability ()
2030 (defmethod action-description ((o load-source-op
) (c component
))
2031 (format nil
(compatfmt "~@<Loading source of ~3i~_~A~@:>") c
))
2032 (defmethod action-description ((o load-source-op
) (c parent-component
))
2033 (format nil
(compatfmt "~@<Loaded source of ~3i~_~A~@:>") c
))
2034 (defun perform-lisp-load-source (o c
)
2035 "Perform the loading of a Lisp file as associated to specified action (O . C)"
2036 (call-with-around-compile-hook
2038 (load* (first (input-files o c
))
2039 :external-format
(component-external-format c
)))))
2041 (defmethod perform ((o load-source-op
) (c cl-source-file
))
2042 (perform-lisp-load-source o c
))
2043 (defmethod perform ((o load-source-op
) (c static-file
))
2048 (with-upgradability ()
2049 (defmethod perform ((o test-op
) (c component
))
2051 (defmethod operation-done-p ((o test-op
) (c system
))
2052 "Testing a system is _never_ done."
2054 ;;;; -------------------------------------------------------------------------
2055 ;;;; Finding components
2057 (uiop/package
:define-package
:asdf
/find-component
2058 (:recycle
:asdf
/find-component
:asdf
/find-system
:asdf
)
2059 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
2060 :asdf
/component
:asdf
/system
:asdf
/system-registry
)
2063 #:resolve-dependency-name
#:resolve-dependency-spec
2064 #:resolve-dependency-combination
2066 #:missing-component
#:missing-requires
#:missing-parent
#:missing-component-of-version
#:retry
2067 #:missing-dependency
#:missing-dependency-of-version
2068 #:missing-requires
#:missing-parent
2069 #:missing-required-by
#:missing-version
))
2070 (in-package :asdf
/find-component
)
2072 ;;;; Missing component conditions
2074 (with-upgradability ()
2075 (define-condition missing-component
(system-definition-error)
2076 ((requires :initform
"(unnamed)" :reader missing-requires
:initarg
:requires
)
2077 (parent :initform nil
:reader missing-parent
:initarg
:parent
)))
2079 (define-condition missing-component-of-version
(missing-component)
2080 ((version :initform nil
:reader missing-version
:initarg
:version
)))
2082 (define-condition missing-dependency
(missing-component)
2083 ((required-by :initarg
:required-by
:reader missing-required-by
)))
2085 (defmethod print-object ((c missing-dependency
) s
)
2086 (format s
(compatfmt "~@<~A, required by ~A~@:>")
2087 (call-next-method c nil
) (missing-required-by c
)))
2089 (define-condition missing-dependency-of-version
(missing-dependency
2090 missing-component-of-version
)
2093 (defmethod print-object ((c missing-component
) s
)
2094 (format s
(compatfmt "~@<Component ~S not found~@[ in ~A~]~@:>")
2095 (missing-requires c
)
2096 (when (missing-parent c
)
2097 (coerce-name (missing-parent c
)))))
2099 (defmethod print-object ((c missing-component-of-version
) s
)
2100 (format s
(compatfmt "~@<Component ~S does not match version ~A~@[ in ~A~]~@:>")
2101 (missing-requires c
)
2103 (when (missing-parent c
)
2104 (coerce-name (missing-parent c
))))))
2107 ;;;; Finding components
2109 (with-upgradability ()
2110 (defgeneric resolve-dependency-combination
(component combinator arguments
)
2111 (:documentation
"Return a component satisfying the dependency specification (COMBINATOR . ARGUMENTS)
2112 in the context of COMPONENT"))
2114 ;; Methods for find-component
2116 ;; If the base component is a string, resolve it as a system, then if not nil follow the path.
2117 (defmethod find-component ((base string
) path
&key registered
)
2118 (if-let ((s (if registered
2119 (registered-system base
)
2120 (find-system base nil
))))
2121 (find-component s path
:registered registered
)))
2123 ;; If the base component is a symbol, coerce it to a name if not nil, and resolve that.
2124 ;; If nil, use the path as base if not nil, or else return nil.
2125 (defmethod find-component ((base symbol
) path
&key registered
)
2127 (base (find-component (coerce-name base
) path
:registered registered
))
2128 (path (find-component path nil
:registered registered
))
2131 ;; If the base component is a cons cell, resolve its car, and add its cdr to the path.
2132 (defmethod find-component ((base cons
) path
&key registered
)
2133 (find-component (car base
) (cons (cdr base
) path
) :registered registered
))
2135 ;; If the base component is a parent-component and the path a string, find the named child.
2136 (defmethod find-component ((parent parent-component
) (name string
) &key registered
)
2137 (declare (ignorable registered
))
2138 (compute-children-by-name parent
:only-if-needed-p t
)
2139 (values (gethash name
(component-children-by-name parent
))))
2141 ;; If the path is a symbol, coerce it to a name if non-nil, or else just return the base.
2142 (defmethod find-component (base (name symbol
) &key registered
)
2144 (find-component base
(coerce-name name
) :registered registered
)
2147 ;; If the path is a cons, first resolve its car as path, then its cdr.
2148 (defmethod find-component ((c component
) (name cons
) &key registered
)
2149 (find-component (find-component c
(car name
) :registered registered
)
2150 (cdr name
) :registered registered
))
2152 ;; If the path is a component, return it, disregarding the base.
2153 (defmethod find-component ((base t
) (actual component
) &key registered
)
2154 (declare (ignorable registered
))
2157 ;; Resolve dependency NAME in the context of a COMPONENT, with given optional VERSION constraint.
2158 ;; This (private) function is used below by RESOLVE-DEPENDENCY-SPEC and by the :VERSION spec.
2159 (defun resolve-dependency-name (component name
&optional version
)
2163 (let ((comp (find-component (component-parent component
) name
)))
2165 (error 'missing-dependency
2166 :required-by component
2169 (unless (version-satisfies comp version
)
2170 (error 'missing-dependency-of-version
2171 :required-by component
2177 (format s
(compatfmt "~@<Retry loading ~3i~_~A.~@:>") name
))
2181 (and (typep c
'missing-dependency
)
2182 (eq (missing-required-by c
) component
)
2183 (equal (missing-requires c
) name
))))
2184 (unless (component-parent component
)
2185 (let ((name (coerce-name name
)))
2186 (unset-asdf-cache-entry `(find-system ,name
))))))))
2188 ;; Resolve dependency specification DEP-SPEC in the context of COMPONENT.
2189 ;; This is notably used by MAP-DIRECT-DEPENDENCIES to process the results of COMPONENT-DEPENDS-ON
2190 ;; and by PARSE-DEFSYSTEM to process DEFSYSTEM-DEPENDS-ON.
2191 (defun resolve-dependency-spec (component dep-spec
)
2192 (let ((component (find-component () component
)))
2194 (resolve-dependency-name component dep-spec
)
2195 (resolve-dependency-combination component
(car dep-spec
) (cdr dep-spec
)))))
2197 ;; Methods for RESOLVE-DEPENDENCY-COMBINATION to parse lists as dependency specifications.
2198 (defmethod resolve-dependency-combination (component combinator arguments
)
2199 (parameter-error (compatfmt "~@<In ~S, bad dependency ~S for ~S~@:>")
2200 'resolve-dependency-combination
(cons combinator arguments
) component
))
2202 (defmethod resolve-dependency-combination (component (combinator (eql :feature
)) arguments
)
2203 (when (featurep (first arguments
))
2204 (resolve-dependency-spec component
(second arguments
))))
2206 (defmethod resolve-dependency-combination (component (combinator (eql :version
)) arguments
)
2207 (resolve-dependency-name component
(first arguments
) (second arguments
)))) ;; See lp#527788
2209 ;;;; -------------------------------------------------------------------------
2212 (uiop/package
:define-package
:asdf
/forcing
2213 (:recycle
:asdf
/forcing
:asdf
/plan
:asdf
)
2214 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
2215 :asdf
/component
:asdf
/operation
:asdf
/system
:asdf
/system-registry
)
2217 #:forcing
#:make-forcing
#:forced
#:forced-not
#:performable-p
2218 #:normalize-forced-systems
#:normalize-forced-not-systems
2219 #:action-forced-p
#:action-forced-not-p
))
2220 (in-package :asdf
/forcing
)
2223 (with-upgradability ()
2224 (defclass forcing
()
2225 (;; Can plans using this forcing be PERFORMed? A plan that has different force and force-not
2226 ;; settings than the session can only be used for read-only queries that do not cause the
2227 ;; status of any action to be raised.
2228 (performable-p :initform nil
:initarg
:performable-p
:reader performable-p
)
2230 (parameters :initform nil
:initarg
:parameters
:reader parameters
)
2231 ;; Table of systems specified via :force arguments
2232 (forced :initarg
:forced
:reader forced
)
2233 ;; Table of systems specified via :force-not argument (and/or immutable)
2234 (forced-not :initarg
:forced-not
:reader forced-not
)))
2236 (defgeneric action-forced-p
(forcing operation component
)
2237 (:documentation
"Is this action forced to happen in this plan?"))
2238 (defgeneric action-forced-not-p
(forcing operation component
)
2239 (:documentation
"Is this action forced to not happen in this plan?
2240 Takes precedence over action-forced-p."))
2242 (defun normalize-forced-systems (force system
)
2243 "Given a SYSTEM on which operate is called and the specified FORCE argument,
2244 extract a hash-set of systems that are forced, or a predicate on system names,
2245 or NIL if none are forced, or :ALL if all are."
2247 ((or (member nil
:all
) hash-table function
) force
)
2248 (cons (list-to-hash-set (mapcar #'coerce-name force
)))
2249 ((eql t
) (when system
(list-to-hash-set (list (coerce-name system
)))))))
2251 (defun normalize-forced-not-systems (force-not system
)
2252 "Given a SYSTEM on which operate is called, the specified FORCE-NOT argument,
2253 and the set of IMMUTABLE systems, extract a hash-set of systems that are effectively forced-not,
2254 or predicate on system names, or NIL if none are forced, or :ALL if all are."
2256 (etypecase force-not
2257 ((or (member nil
:all
) hash-table function
) force-not
)
2258 (cons (list-to-hash-set (mapcar #'coerce-name force-not
)))
2259 ((eql t
) (if system
(let ((name (coerce-name system
)))
2260 #'(lambda (x) (not (equal x name
))))
2262 (if (and *immutable-systems
* requested
)
2263 #'(lambda (x) (or (call-function requested x
)
2264 (call-function *immutable-systems
* x
)))
2265 (or *immutable-systems
* requested
))))
2267 ;; TODO: shouldn't we be looking up the primary system name, rather than the system name?
2268 (defun action-override-p (forcing operation component override-accessor
)
2269 "Given a plan, an action, and a function that given the plan accesses a set of overrides,
2270 i.e. force or force-not, see if the override applies to the current action."
2271 (declare (ignore operation
))
2272 (call-function (funcall override-accessor forcing
)
2273 (coerce-name (component-system (find-component () component
)))))
2275 (defmethod action-forced-p (forcing operation component
)
2277 ;; Did the user ask us to re-perform the action?
2278 (action-override-p forcing operation component
'forced
)
2279 ;; You really can't force a builtin system and :all doesn't apply to it.
2280 (not (builtin-system-p (component-system component
)))))
2282 (defmethod action-forced-not-p (forcing operation component
)
2283 ;; Did the user ask us to not re-perform the action?
2284 ;; NB: force-not takes precedence over force, as it should
2285 (action-override-p forcing operation component
'forced-not
))
2287 ;; Null forcing means no forcing either way
2288 (defmethod action-forced-p ((forcing null
) (operation operation
) (component component
))
2290 (defmethod action-forced-not-p ((forcing null
) (operation operation
) (component component
))
2293 (defun or-function (fun1 fun2
)
2295 ((or (null fun2
) (eq fun1
:all
)) fun1
)
2296 ((or (null fun1
) (eq fun2
:all
)) fun2
)
2297 (t #'(lambda (x) (or (call-function fun1 x
) (call-function fun2 x
))))))
2299 (defun make-forcing (&key performable-p system
2300 (force nil force-p
) (force-not nil force-not-p
) &allow-other-keys
)
2301 (let* ((session-forcing (when *asdf-session
* (forcing *asdf-session
*)))
2302 (system (and system
(coerce-name system
)))
2303 (forced (normalize-forced-systems force system
))
2304 (forced-not (normalize-forced-not-systems force-not system
))
2305 (parameters `(,@(when force
`(:force
,force
))
2306 ,@(when force-not
`(:force-not
,force-not
))
2307 ,@(when (or (eq force t
) (eq force-not t
)) `(:system
,system
))
2308 ,@(when performable-p
`(:performable-p t
))))
2311 ((not session-forcing
)
2312 (setf forcing
(make-instance 'forcing
2313 :performable-p performable-p
:parameters parameters
2314 :forced forced
:forced-not forced-not
))
2315 (when (and performable-p
*asdf-session
*)
2316 (setf (forcing *asdf-session
*) forcing
)))
2318 (when (and (not (equal parameters
(parameters session-forcing
)))
2319 (or force-p force-not-p
))
2320 (parameter-error "~*~S and ~S arguments not allowed in a nested call to ~3:*~S ~
2321 unless identically to toplevel"
2322 (find-symbol* :operate
:asdf
) :force
:force-not
))
2323 (setf forcing session-forcing
))
2325 (setf forcing
(make-instance 'forcing
2326 ;; Combine force and force-not with values from the toplevel-plan
2327 :parameters
`(,@parameters
:on-top-of
,(parameters session-forcing
))
2328 :forced
(or-function (forced session-forcing
) forced
)
2329 :forced-not
(or-function (forced-not session-forcing
) forced-not
)))))
2332 (defmethod print-object ((forcing forcing
) stream
)
2333 (print-unreadable-object (forcing stream
:type t
)
2334 (format stream
"~{~S~^ ~}" (parameters forcing
))))
2336 ;; During upgrade, the *asdf-session* may legitimately be NIL, so we must handle that case.
2337 (defmethod forcing ((x null
))
2338 (if-let (session (toplevel-asdf-session))
2340 (make-forcing :performable-p t
)))
2342 ;; When performing a plan that is a list of actions, use the toplevel asdf sesssion forcing.
2343 (defmethod forcing ((x cons
)) (forcing (toplevel-asdf-session))))
2344 ;;;; -------------------------------------------------------------------------
2347 (uiop/package
:define-package
:asdf
/plan
2348 ;; asdf/action below is needed for required-components, traverse-action and traverse-sub-actions
2349 ;; that used to live there before 3.2.0.
2350 (:recycle
:asdf
/plan
:asdf
/action
:asdf
)
2351 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
2352 :asdf
/component
:asdf
/operation
:asdf
/action
:asdf
/lisp-action
2353 :asdf
/system
:asdf
/system-registry
:asdf
/find-component
:asdf
/forcing
)
2355 #:plan
#:plan-traversal
#:sequential-plan
#:*plan-class
*
2356 #:action-status
#:status-stamp
#:status-index
#:status-done-p
#:status-keep-p
#:status-need-p
2357 #:action-already-done-p
2358 #:+status-good
+ #:+status-todo
+ #:+status-void
+
2359 #:system-out-of-date
#:action-up-to-date-p
2360 #:circular-dependency
#:circular-dependency-actions
2362 #:map-direct-dependencies
#:reduce-direct-dependencies
#:direct-dependencies
2363 #:compute-action-stamp
#:traverse-action
#:record-dependency
2364 #:make-plan
#:plan-actions
#:plan-actions-r
#:perform-plan
#:mark-as-done
2365 #:required-components
#:filtered-sequential-plan
2366 #:plan-component-type
#:plan-keep-operation
#:plan-keep-component
))
2367 (in-package :asdf
/plan
)
2369 ;;;; Generic plan traversal class
2370 (with-upgradability ()
2371 (defclass plan
() ()
2372 (:documentation
"Base class for a plan based on which ASDF can build a system"))
2373 (defclass plan-traversal
(plan)
2374 (;; The forcing parameters for this plan. Also indicates whether the plan is performable,
2375 ;; in which case the forcing is the same as for the entire session.
2376 (forcing :initform
(forcing (toplevel-asdf-session)) :initarg
:forcing
:reader forcing
))
2377 (:documentation
"Base class for plans that simply traverse dependencies"))
2378 ;; Sequential plans (the default)
2379 (defclass sequential-plan
(plan-traversal)
2380 ((actions-r :initform nil
:accessor plan-actions-r
))
2381 (:documentation
"Simplest, default plan class, accumulating a sequence of actions"))
2383 (defgeneric plan-actions
(plan)
2384 (:documentation
"Extract from a plan a list of actions to perform in sequence"))
2385 (defmethod plan-actions ((plan list
))
2387 (defmethod plan-actions ((plan sequential-plan
))
2388 (reverse (plan-actions-r plan
)))
2390 (defgeneric record-dependency
(plan operation component
)
2391 (:documentation
"Record an action as a dependency in the current plan"))
2393 ;; No need to record a dependency to build a full graph, just accumulate nodes in order.
2394 (defmethod record-dependency ((plan sequential-plan
) (o operation
) (c component
))
2397 (when-upgrading (:version
"3.3.0")
2398 (defmethod initialize-instance :after
((plan plan-traversal
) &key
&allow-other-keys
)))
2401 ;;;; Planned action status
2402 (with-upgradability ()
2403 (defclass action-status
()
2405 :type fixnum
:initarg
:bits
:reader status-bits
2406 :documentation
"bitmap describing the status of the action.")
2408 :type
(or integer boolean
) :initarg
:stamp
:reader status-stamp
2409 :documentation
"STAMP associated with the ACTION if it has been completed already in some
2410 previous session or image, T if it was done and builtin the image, or NIL if it needs to be done.")
2412 :type fixnum
:initarg
:level
:initform
0 :reader status-level
2413 :documentation
"the highest (operate-level) at which the action was needed")
2415 :type
(or integer null
) :initarg
:index
:initform nil
:reader status-index
2416 :documentation
"INDEX associated with the ACTION in the current session,
2417 or NIL if no the status is considered outside of a specific plan."))
2418 (:documentation
"Status of an action in a plan"))
2420 ;; STAMP KEEP-P DONE-P NEED-P symbol bitmap previously currently
2421 ;; not-nil T T T => GOOD 7 up-to-date done (e.g. file previously loaded)
2422 ;; not-nil T T NIL => HERE 6 up-to-date unplanned yet done
2423 ;; not-nil T NIL T => REDO 5 up-to-date planned (e.g. file to load)
2424 ;; not-nil T NIL NIL => SKIP 4 up-to-date unplanned (e.g. file compiled)
2425 ;; not-nil NIL T T => DONE 3 out-of-date done
2426 ;; not-nil NIL T NIL => WHAT 2 out-of-date unplanned yet done(?)
2427 ;; NIL NIL NIL T => TODO 1 out-of-date planned
2428 ;; NIL NIL NIL NIL => VOID 0 out-of-date unplanned
2430 ;; Note that a VOID status cannot happen as part of a transitive dependency of a wanted node
2431 ;; while traversing a node with TRAVERSE-ACTION; it can only happen while checking whether an
2432 ;; action is up-to-date with ACTION-UP-TO-DATE-P.
2434 ;; When calling TRAVERSE-ACTION, the +need-bit+ is set,
2435 ;; unless the action is up-to-date and not needed-in-image (HERE, SKIP).
2436 ;; When PERFORMing an action, the +done-bit+ is set.
2437 ;; When the +need-bit+ is set but not the +done-bit+, the level slot indicates which level of
2438 ;; OPERATE it was last marked needed for; if it happens to be needed at a higher-level, then
2439 ;; its urgency (and that of its transitive dependencies) must be escalated so that it will be
2440 ;; done before the end of this level of operate.
2442 ;; Also, when no ACTION-STATUS is associated to an action yet, NIL serves as a bottom value.
2444 (defparameter +keep-bit
+ 4)
2445 (defparameter +done-bit
+ 2)
2446 (defparameter +need-bit
+ 1)
2447 (defparameter +good-bits
+ 7)
2448 (defparameter +todo-bits
+ 1)
2449 (defparameter +void-bits
+ 0)
2451 (defparameter +status-good
+
2452 (make-instance 'action-status
:bits
+good-bits
+ :stamp t
))
2453 (defparameter +status-todo
+
2454 (make-instance 'action-status
:bits
+todo-bits
+ :stamp nil
))
2455 (defparameter +status-void
+
2456 (make-instance 'action-status
:bits
+void-bits
+ :stamp nil
)))
2458 (with-upgradability ()
2459 (defun make-action-status (&key bits stamp
(level 0) index
)
2460 (check-type bits
(integer 0 7))
2461 (check-type stamp
(or integer boolean
))
2462 (check-type level
(integer 0 #.most-positive-fixnum
))
2463 (check-type index
(or integer null
))
2464 (assert (eq (null stamp
) (zerop (logand bits
#.
(logior +keep-bit
+ +done-bit
+)))) ()
2465 "Bad action-status :bits ~S :stamp ~S" bits stamp
)
2467 (when (and (null index
) (zerop level
))
2469 (#.
+void-bits
+ (return +status-void
+))
2470 (#.
+todo-bits
+ (return +status-todo
+))
2471 (#.
+good-bits
+ (when (eq stamp t
) (return +status-good
+)))))
2472 (make-instance 'action-status
:bits bits
:stamp stamp
:level level
:index index
)))
2474 (defun status-keep-p (status)
2475 (plusp (logand (status-bits status
) #.
+keep-bit
+)))
2476 (defun status-done-p (status)
2477 (plusp (logand (status-bits status
) #.
+done-bit
+)))
2478 (defun status-need-p (status)
2479 (plusp (logand (status-bits status
) #.
+need-bit
+)))
2481 (defun merge-action-status (status1 status2
) ;; status-and
2482 "Return the earliest status later than both status1 and status2"
2484 :bits
(logand (status-bits status1
) (status-bits status2
))
2485 :stamp
(latest-timestamp (status-stamp status1
) (status-stamp status2
))
2486 :level
(min (status-level status1
) (status-level status2
))
2487 :index
(or (status-index status1
) (status-index status2
))))
2489 (defun mark-status-needed (status &optional
(level (operate-level))) ;; limited status-or
2490 "Return the same status but with the need bit set, for the given level"
2491 (if (and (status-need-p status
)
2492 (>= (status-level status
) level
))
2495 :bits
(logior (status-bits status
) +need-bit
+)
2496 :level
(max level
(status-level status
))
2497 :stamp
(status-stamp status
)
2498 :index
(status-index status
))))
2500 (defmethod print-object ((status action-status
) stream
)
2501 (print-unreadable-object (status stream
:type t
)
2502 (with-slots (bits stamp level index
) status
2503 (format stream
"~{~S~^ ~}" `(:bits
,bits
:stamp
,stamp
:level
,level
:index
,index
)))))
2505 (defgeneric action-status
(plan operation component
)
2506 (:documentation
"Returns the ACTION-STATUS associated to the action of OPERATION on COMPONENT
2507 in the PLAN, or NIL if the action wasn't visited yet as part of the PLAN."))
2509 (defgeneric (setf action-status
) (new-status plan operation component
)
2510 (:documentation
"Sets the ACTION-STATUS associated to
2511 the action of OPERATION on COMPONENT in the PLAN"))
2513 (defmethod action-status ((plan null
) (o operation
) (c component
))
2514 (multiple-value-bind (stamp done-p
) (component-operation-time o c
)
2516 (make-action-status :bits
#.
+keep-bit
+ :stamp stamp
)
2519 (defmethod (setf action-status
) (new-status (plan null
) (o operation
) (c component
))
2520 (let ((times (component-operation-times c
)))
2521 (if (status-done-p new-status
)
2522 (setf (gethash o times
) (status-stamp new-status
))
2526 ;; Handle FORCED-NOT: it makes an action return its current timestamp as status
2527 (defmethod action-status ((p plan
) (o operation
) (c component
))
2528 ;; TODO: should we instead test something like:
2529 ;; (action-forced-not-p plan operation (primary-system component))
2530 (or (gethash (make-action o c
) (visited-actions *asdf-session
*))
2531 (when (action-forced-not-p (forcing p
) o c
)
2532 (let ((status (action-status nil o c
)))
2533 (setf (gethash (make-action o c
) (visited-actions *asdf-session
*))
2536 :stamp
(or (and status
(status-stamp status
)) t
)
2537 :index
(incf (total-action-count *asdf-session
*))))))))
2539 (defmethod (setf action-status
) (new-status (p plan
) (o operation
) (c component
))
2540 (setf (gethash (make-action o c
) (visited-actions *asdf-session
*)) new-status
))
2542 (defmethod (setf action-status
) :after
2543 (new-status (p sequential-plan
) (o operation
) (c component
))
2544 (unless (status-done-p new-status
)
2545 (push (make-action o c
) (plan-actions-r p
)))))
2548 ;;;; Is the action needed in this image?
2549 (with-upgradability ()
2550 (defgeneric needed-in-image-p
(operation component
)
2551 (:documentation
"Is the action of OPERATION on COMPONENT needed in the current image
2552 to be meaningful, or could it just as well have been done in another Lisp image?"))
2554 (defmethod needed-in-image-p ((o operation
) (c component
))
2555 ;; We presume that actions that modify the filesystem don't need be run
2556 ;; in the current image if they have already been done in another,
2557 ;; and can be run in another process (e.g. a fork),
2558 ;; whereas those that don't are meant to side-effect the current image and can't.
2559 (not (output-files o c
))))
2562 ;;;; Visiting dependencies of an action and computing action stamps
2563 (with-upgradability ()
2564 (defun* (map-direct-dependencies) (operation component fun
)
2565 "Call FUN on all the valid dependencies of the given action in the given plan"
2566 (loop* :for
(dep-o-spec . dep-c-specs
) :in
(component-depends-on operation component
)
2567 :for dep-o
= (find-operation operation dep-o-spec
)
2569 :do
(loop :for dep-c-spec
:in dep-c-specs
2570 :for dep-c
= (and dep-c-spec
(resolve-dependency-spec component dep-c-spec
))
2571 :when
(action-valid-p dep-o dep-c
)
2572 :do
(funcall fun dep-o dep-c
))))
2574 (defun* (reduce-direct-dependencies) (operation component combinator seed
)
2575 "Reduce the direct dependencies to a value computed by iteratively calling COMBINATOR
2576 for each dependency action on the dependency's operation and component and an accumulator
2577 initialized with SEED."
2578 (map-direct-dependencies
2580 #'(lambda (dep-o dep-c
) (setf seed
(funcall combinator dep-o dep-c seed
))))
2583 (defun* (direct-dependencies) (operation component
)
2584 "Compute a list of the direct dependencies of the action within the plan"
2585 (reverse (reduce-direct-dependencies operation component
#'acons nil
)))
2587 ;; In a distant future, get-file-stamp, component-operation-time and latest-stamp
2588 ;; shall also be parametrized by the plan, or by a second model object,
2589 ;; so they need not refer to the state of the filesystem,
2590 ;; and the stamps could be cryptographic checksums rather than timestamps.
2591 ;; Such a change remarkably would only affect COMPUTE-ACTION-STAMP.
2593 (defmethod compute-action-stamp (plan (o operation
) (c component
) &key just-done
)
2594 ;; Given an action, figure out at what time in the past it has been done,
2595 ;; or if it has just been done, return the time that it has.
2596 ;; Returns two values:
2597 ;; 1- the TIMESTAMP of the action if it has already been done and is up to date,
2598 ;; or NIL is either hasn't been done or is out of date.
2599 ;; (An ASDF extension could use a cryptographic digest instead.)
2600 ;; 2- the DONE-IN-IMAGE-P boolean flag that is T if the action has already been done
2601 ;; in the current image, or NIL if it hasn't.
2602 ;; Note that if e.g. LOAD-OP only depends on up-to-date files, but
2603 ;; hasn't been done in the current image yet, then it can have a non-NIL timestamp,
2604 ;; yet a NIL done-in-image-p flag: we can predict what timestamp it will have once loaded,
2605 ;; i.e. that of the input-files.
2606 ;; If just-done is NIL, these values return are the notional fields of
2607 ;; a KEEP, REDO or TODO status (VOID is possible, but probably an error).
2608 ;; If just-done is T, they are the notional fields of DONE status
2609 ;; (or, if something went wrong, TODO).
2612 (let* ((dep-status ; collect timestamp from dependencies (or T if forced or out-of-date)
2613 (reduce-direct-dependencies
2615 #'(lambda (do dc status
)
2616 ;; out-of-date dependency: don't bother looking further
2617 (let ((action-status (action-status plan do dc
)))
2619 ((and action-status
(or (status-keep-p action-status
)
2620 (and just-done
(status-stamp action-status
))))
2621 (merge-action-status action-status status
))
2623 ;; It's OK to lose some ASDF action stamps during self-upgrade
2624 (unless (equal "asdf" (primary-system-name dc
))
2625 (warn "Computing just-done stamp in plan ~S for action ~S, but dependency ~S wasn't done yet!"
2627 (action-path (make-action o c
))
2628 (action-path (make-action do dc
))))
2631 (return (values nil nil
))))))
2633 (dep-stamp (status-stamp dep-status
))))
2634 (let* (;; collect timestamps from inputs, and exit early if any is missing
2635 (in-files (input-files o c
))
2636 (in-stamps (mapcar #'get-file-stamp in-files
))
2637 (missing-in (loop :for f
:in in-files
:for s
:in in-stamps
:unless s
:collect f
))
2638 (latest-in (timestamps-latest (cons dep-stamp in-stamps
))))
2639 (when (and missing-in
(not just-done
)) (return (values nil nil
))))
2640 (let* (;; collect timestamps from outputs, and exit early if any is missing
2641 (out-files (remove-if 'null
(output-files o c
)))
2642 (out-stamps (mapcar (if just-done
'register-file-stamp
'get-file-stamp
) out-files
))
2643 (missing-out (loop :for f
:in out-files
:for s
:in out-stamps
:unless s
:collect f
))
2644 (earliest-out (timestamps-earliest out-stamps
)))
2645 (when (and missing-out
(not just-done
)) (return (values nil nil
))))
2646 (let (;; Time stamps from the files at hand, and whether any is missing
2647 (all-present (not (or missing-in missing-out
)))
2648 ;; Has any input changed since we last generated the files?
2649 ;; Note that we use timestamp<= instead of timestamp< to play nice with generated files.
2650 ;; Any race condition is intrinsic to the limited timestamp resolution.
2651 (up-to-date-p (timestamp<= latest-in earliest-out
))
2652 ;; If everything is up to date, the latest of inputs and outputs is our stamp
2653 (done-stamp (timestamps-latest (cons latest-in out-stamps
))))
2654 ;; Warn if some files are missing:
2655 ;; either our model is wrong or some other process is messing with our files.
2656 (when (and just-done
(not all-present
))
2657 ;; Shouldn't that be an error instead?
2658 (warn "~A completed without ~:[~*~;~*its input file~:p~2:*~{ ~S~}~*~]~
2659 ~:[~; or ~]~:[~*~;~*its output file~:p~2:*~{ ~S~}~*~]"
2660 (action-description o c
)
2661 missing-in
(length missing-in
) (and missing-in missing-out
)
2662 missing-out
(length missing-out
))))
2663 (let (;; There are three kinds of actions:
2664 (out-op (and out-files t
)) ; those that create files on the filesystem
2665 ;;(image-op (and in-files (null out-files))) ; those that load stuff into the image
2666 ;;(null-op (and (null out-files) (null in-files))) ; placeholders that do nothing
2668 (if (or just-done
;; The done-stamp is valid: if we're just done, or
2669 (and all-present
;; if all filesystem effects are up-to-date
2671 (operation-done-p o c
) ;; and there's no invalidating reason.
2672 (not (action-forced-p (forcing (or plan
*asdf-session
*)) o c
))))
2673 (values done-stamp
;; return the hard-earned timestamp
2675 out-op
;; A file-creating op is done when all files are up to date.
2676 ;; An image-effecting operation is done when
2677 (and (status-done-p dep-status
) ;; all the dependencies were done, and
2678 (multiple-value-bind (perform-stamp perform-done-p
)
2679 (component-operation-time o c
)
2680 (and perform-done-p
;; the op was actually run,
2681 (equal perform-stamp done-stamp
)))))) ;; with a matching stamp.
2682 ;; done-stamp invalid: return a timestamp in an indefinite future, action not done yet
2683 (values nil nil
)))))
2686 ;;;; The four different actual traversals:
2687 ;; * TRAVERSE-ACTION o c T: Ensure all dependencies are either up-to-date in-image, or planned
2688 ;; * TRAVERSE-ACTION o c NIL: Ensure all dependencies are up-to-date or planned, in-image or not
2689 ;; * ACTION-UP-TO-DATE-P: Check whether some (defsystem-depends-on ?) dependencies are up to date
2690 ;; * COLLECT-ACTION-DEPENDENCIES: Get the dependencies (filtered), don't change any status
2691 (with-upgradability ()
2693 ;; Compute the action status for a newly visited action.
2694 (defun compute-action-status (plan operation component need-p
)
2695 (multiple-value-bind (stamp done-p
)
2696 (compute-action-stamp plan operation component
)
2697 (assert (or stamp
(not done-p
)))
2699 :bits
(logior (if stamp
#.
+keep-bit
+ 0)
2700 (if done-p
#.
+done-bit
+ 0)
2701 (if need-p
#.
+need-bit
+ 0))
2703 :level
(operate-level)
2704 :index
(incf (total-action-count *asdf-session
*)))))
2706 ;; TRAVERSE-ACTION, in the context of a given PLAN object that accumulates dependency data,
2707 ;; visits the action defined by its OPERATION and COMPONENT arguments,
2708 ;; and all its transitive dependencies (unless already visited),
2709 ;; in the context of the action being (or not) NEEDED-IN-IMAGE-P,
2710 ;; i.e. needs to be done in the current image vs merely have been done in a previous image.
2712 ;; TRAVERSE-ACTION updates the VISITED-ACTIONS entries for the action and for all its
2713 ;; transitive dependencies (that haven't been sufficiently visited so far).
2714 ;; It does not return any usable value.
2716 ;; Note that for an XCVB-like plan with one-image-per-file-outputting-action,
2717 ;; the below method would be insufficient, since it assumes a single image
2718 ;; to traverse each node at most twice; non-niip actions would be traversed only once,
2719 ;; but niip nodes could be traversed once per image, i.e. once plus once per non-niip action.
2721 (defun traverse-action (plan operation component needed-in-image-p
)
2723 (unless (action-valid-p operation component
) (return))
2724 ;; Record the dependency. This hook is needed by POIU, which tracks a full dependency graph,
2725 ;; instead of just a dependency order as in vanilla ASDF.
2726 ;; TODO: It is also needed to detect OPERATE-in-PERFORM.
2727 (record-dependency plan operation component
)
2728 (while-visiting-action (operation component
) ; maintain context, handle circularity.
2729 ;; needed-in-image distinguishes b/w things that must happen in the
2730 ;; current image and those things that simply need to have been done in a previous one.
2731 (let* ((aniip (needed-in-image-p operation component
)) ; action-specific needed-in-image
2732 ;; effective niip: meaningful for the action and required by the plan as traversed
2733 (eniip (and aniip needed-in-image-p
))
2734 ;; status: have we traversed that action previously, and if so what was its status?
2735 (status (action-status plan operation component
))
2736 (level (operate-level)))
2738 (or (status-done-p status
) ;; all done
2739 (and (status-need-p status
) (<= level
(status-level status
))) ;; already visited
2740 (and (status-keep-p status
) (not eniip
)))) ;; up-to-date and not eniip
2741 (return)) ; Already visited with sufficient need-in-image level!
2742 (labels ((visit-action (niip) ; We may visit the action twice, once with niip NIL, then T
2743 (map-direct-dependencies ; recursively traverse dependencies
2744 operation component
#'(lambda (o c
) (traverse-action plan o c niip
)))
2745 ;; AFTER dependencies have been traversed, compute action stamp
2746 (let* ((status (if status
2747 (mark-status-needed status level
)
2748 (compute-action-status plan operation component t
)))
2749 (out-of-date-p (not (status-keep-p status
)))
2750 (to-perform-p (or out-of-date-p
(and niip
(not (status-done-p status
))))))
2751 (cond ; it needs be done if it's out of date or needed in image but absent
2752 ((and out-of-date-p
(not niip
)) ; if we need to do it,
2753 (visit-action t
)) ; then we need to do it *in the (current) image*!
2755 (setf (action-status plan operation component
) status
)
2756 (when (status-done-p status
)
2757 (setf (component-operation-time operation component
)
2758 (status-stamp status
)))
2759 (when to-perform-p
; if it needs to be added to the plan, count it
2760 (incf (planned-action-count *asdf-session
*))
2761 (unless aniip
; if it's output-producing, count it
2762 (incf (planned-output-action-count *asdf-session
*)))))))))
2763 (visit-action eniip
)))))) ; visit the action
2765 ;; NB: This is not an error, not a warning, but a normal expected condition,
2766 ;; to be to signaled by FIND-SYSTEM when it detects an out-of-date system,
2767 ;; *before* it tries to replace it with a new definition.
2768 (define-condition system-out-of-date
(condition)
2769 ((name :initarg
:name
:reader component-name
))
2770 (:documentation
"condition signaled when a system is detected as being out of date")
2771 (:report
(lambda (c s
)
2772 (format s
"system ~A is out of date" (component-name c
)))))
2774 (defun action-up-to-date-p (plan operation component
)
2775 "Check whether an action was up-to-date at the beginning of the session.
2776 Update the VISITED-ACTIONS table with the known status, but don't add anything to the PLAN."
2778 (unless (action-valid-p operation component
) (return t
))
2779 (while-visiting-action (operation component
) ; maintain context, handle circularity.
2780 ;; Do NOT record the dependency: it might be out of date.
2781 (let ((status (or (action-status plan operation component
)
2782 (setf (action-status plan operation component
)
2783 (let ((dependencies-up-to-date-p
2786 (map-direct-dependencies
2789 (unless (action-up-to-date-p plan o c
)
2792 (system-out-of-date () nil
))))
2793 (if dependencies-up-to-date-p
2794 (compute-action-status plan operation component nil
)
2796 (and (status-keep-p status
) (status-stamp status
)))))))
2799 ;;;; Incidental traversals
2801 ;;; Making a FILTERED-SEQUENTIAL-PLAN can be used to, e.g., all of the source
2802 ;;; files required by a bundling operation.
2803 (with-upgradability ()
2804 (defclass filtered-sequential-plan
(sequential-plan)
2805 ((component-type :initform t
:initarg
:component-type
:reader plan-component-type
)
2806 (keep-operation :initform t
:initarg
:keep-operation
:reader plan-keep-operation
)
2807 (keep-component :initform t
:initarg
:keep-component
:reader plan-keep-component
))
2808 (:documentation
"A variant of SEQUENTIAL-PLAN that only records a subset of actions."))
2810 (defmethod initialize-instance :after
((plan filtered-sequential-plan
)
2811 &key system other-systems
)
2812 ;; Ignore force and force-not, rely on other-systems:
2813 ;; force traversal of what we're interested in, i.e. current system or also others;
2814 ;; force-not traversal of what we're not interested in, i.e. other systems unless other-systems.
2815 (setf (slot-value plan
'forcing
)
2816 (make-forcing :system system
:force
:all
:force-not
(if other-systems nil t
))))
2818 (defmethod plan-actions ((plan filtered-sequential-plan
))
2819 (with-slots (keep-operation keep-component
) plan
2820 (loop :for action
:in
(call-next-method)
2821 :as o
= (action-operation action
)
2822 :as c
= (action-component action
)
2823 :when
(and (typep o keep-operation
) (typep c keep-component
))
2824 :collect
(make-action o c
))))
2826 (defun collect-action-dependencies (plan operation component
)
2827 (when (action-valid-p operation component
)
2828 (while-visiting-action (operation component
) ; maintain context, handle circularity.
2829 (let ((action (make-action operation component
)))
2830 (unless (nth-value 1 (gethash action
(visited-actions *asdf-session
*)))
2831 (setf (gethash action
(visited-actions *asdf-session
*)) nil
)
2832 (when (and (typep component
(plan-component-type plan
))
2833 (not (action-forced-not-p (forcing plan
) operation component
)))
2834 (map-direct-dependencies operation component
2835 #'(lambda (o c
) (collect-action-dependencies plan o c
)))
2836 (push action
(plan-actions-r plan
))))))))
2838 (defgeneric collect-dependencies
(operation component
&key
&allow-other-keys
)
2839 (:documentation
"Given an action, build a plan for all of its dependencies."))
2840 (define-convenience-action-methods collect-dependencies
(operation component
&key
))
2841 (defmethod collect-dependencies ((operation operation
) (component component
)
2842 &rest keys
&key
&allow-other-keys
)
2843 (let ((plan (apply 'make-instance
'filtered-sequential-plan
2844 :system
(component-system component
) keys
)))
2845 (loop :for action
:in
(direct-dependencies operation component
)
2846 :do
(collect-action-dependencies plan
(action-operation action
) (action-component action
)))
2847 (plan-actions plan
)))
2849 (defun* (required-components) (system &rest keys
&key
(goal-operation 'load-op
) &allow-other-keys
)
2850 "Given a SYSTEM and a GOAL-OPERATION (default LOAD-OP), traverse the dependencies and
2851 return a list of the components involved in building the desired action."
2852 (with-asdf-session (:override t
)
2854 (mapcar 'action-component
2855 (apply 'collect-dependencies goal-operation system
2856 (remove-plist-key :goal-operation keys
)))
2860 ;;;; High-level interface: make-plan, perform-plan
2861 (with-upgradability ()
2862 (defgeneric make-plan
(plan-class operation component
&key
&allow-other-keys
)
2863 (:documentation
"Generate and return a plan for performing OPERATION on COMPONENT."))
2864 (define-convenience-action-methods make-plan
(plan-class operation component
&key
))
2866 (defgeneric mark-as-done
(plan-class operation component
)
2867 (:documentation
"Mark an action as done in a plan, after performing it."))
2868 (define-convenience-action-methods mark-as-done
(plan-class operation component
))
2870 (defgeneric perform-plan
(plan &key
)
2871 (:documentation
"Actually perform a plan and build the requested actions"))
2873 (defparameter* *plan-class
* 'sequential-plan
2874 "The default plan class to use when building with ASDF")
2876 (defmethod make-plan (plan-class (o operation
) (c component
) &rest keys
&key
&allow-other-keys
)
2877 (with-asdf-session ()
2878 (let ((plan (apply 'make-instance
(or plan-class
*plan-class
*) keys
)))
2879 (traverse-action plan o c t
)
2882 (defmethod perform-plan :around
((plan t
) &key
)
2883 (assert (performable-p (forcing plan
)) () "plan not performable")
2884 (let ((*package
* *package
*)
2885 (*readtable
* *readtable
*))
2886 (with-compilation-unit () ;; backward-compatibility.
2887 (call-next-method)))) ;; Going forward, see deferred-warning support in lisp-build.
2889 (defun action-already-done-p (plan operation component
)
2890 (if-let (status (action-status plan operation component
))
2891 (status-done-p status
)))
2893 (defmethod perform-plan ((plan t
) &key
)
2894 (loop :for action
:in
(plan-actions plan
)
2895 :as o
= (action-operation action
)
2896 :as c
= (action-component action
) :do
2897 (unless (action-already-done-p plan o c
)
2898 (perform-with-restarts o c
)
2899 (mark-as-done plan o c
))))
2901 (defmethod mark-as-done ((plan plan
) (o operation
) (c component
))
2902 (let ((plan-status (action-status plan o c
))
2903 (perform-status (action-status nil o c
)))
2904 (assert (and (status-stamp perform-status
) (status-keep-p perform-status
)) ()
2905 "Just performed ~A but failed to mark it done" (action-description o c
))
2906 (setf (action-status plan o c
)
2908 :bits
(logior (status-bits plan-status
) +done-bit
+)
2909 :stamp
(status-stamp perform-status
)
2910 :level
(status-level plan-status
)
2911 :index
(status-index plan-status
))))))
2912 ;;;; -------------------------------------------------------------------------
2913 ;;;; Invoking Operations
2915 (uiop/package
:define-package
:asdf
/operate
2916 (:recycle
:asdf
/operate
:asdf
)
2917 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
2918 :asdf
/component
:asdf
/system
:asdf
/system-registry
:asdf
/find-component
2919 :asdf
/operation
:asdf
/action
:asdf
/lisp-action
:asdf
/forcing
:asdf
/plan
)
2921 #:operate
#:oos
#:build-op
#:make
2922 #:load-system
#:load-systems
#:load-systems
*
2923 #:compile-system
#:test-system
#:require-system
#:module-provide-asdf
2924 #:component-loaded-p
#:already-loaded-systems
2925 #:recursive-operate
))
2926 (in-package :asdf
/operate
)
2928 (with-upgradability ()
2929 (defgeneric operate
(operation component
&key
)
2931 "Operate does mainly four things for the user:
2933 1. Resolves the OPERATION designator into an operation object.
2934 OPERATION is typically a symbol denoting an operation class, instantiated with MAKE-OPERATION.
2935 2. Resolves the COMPONENT designator into a component object.
2936 COMPONENT is typically a string or symbol naming a system, loaded from disk using FIND-SYSTEM.
2937 3. It then calls MAKE-PLAN with the operation and system as arguments.
2938 4. Finally calls PERFORM-PLAN on the resulting plan to actually build the system.
2940 The entire computation is wrapped in WITH-COMPILATION-UNIT and error handling code.
2941 If a VERSION argument is supplied, then operate also ensures that the system found satisfies it
2942 using the VERSION-SATISFIES method.
2943 If a PLAN-CLASS argument is supplied, that class is used for the plan.
2944 If a PLAN-OPTIONS argument is supplied, the options are passed to the plan.
2946 The :FORCE or :FORCE-NOT argument to OPERATE can be:
2947 T to force the inside of the specified system to be rebuilt (resp. not),
2948 without recursively forcing the other systems we depend on.
2949 :ALL to force all systems including other systems we depend on to be rebuilt (resp. not).
2950 (SYSTEM1 SYSTEM2 ... SYSTEMN) to force systems named in a given list
2951 :FORCE-NOT has precedence over :FORCE; builtin systems cannot be forced.
2953 For backward compatibility, all keyword arguments are passed to MAKE-OPERATION
2954 when instantiating a new operation, that will in turn be inherited by new operations.
2955 But do NOT depend on it, for this is deprecated behavior."))
2957 (define-convenience-action-methods operate
(operation component
&key
)
2958 :if-no-component
(error 'missing-component
:requires component
))
2960 ;; This method ensures that an ASDF upgrade is attempted as the very first thing,
2961 ;; with suitable state preservation in case in case it actually happens,
2962 ;; and that a few suitable dynamic bindings are established.
2963 (defmethod operate :around
(operation component
&rest keys
2965 (on-warnings *compile-file-warnings-behaviour
*)
2966 (on-failure *compile-file-failure-behaviour
*))
2968 (with-asdf-session ())
2969 (let* ((operation-remaker ;; how to remake the operation after ASDF was upgraded (if it was)
2970 (etypecase operation
2971 (operation (let ((name (type-of operation
)))
2972 #'(lambda () (make-operation name
))))
2973 ((or symbol string
) (constantly operation
))))
2974 (component-path (typecase component
;; to remake the component after ASDF upgrade
2975 (component (component-find-path component
))
2977 (system-name (labels ((first-name (x)
2979 ((or string symbol
) x
) ; NB: includes the NIL case.
2980 (cons (or (first-name (car x
)) (first-name (cdr x
)))))))
2981 (coerce-name (first-name component-path
)))))
2982 (apply 'make-forcing
:performable-p t
:system system-name keys
)
2983 ;; Before we operate on any system, make sure ASDF is up-to-date,
2984 ;; for if an upgrade is ever attempted at any later time, there may be BIG trouble.
2985 (unless (asdf-upgraded-p (toplevel-asdf-session))
2986 (setf (asdf-upgraded-p (toplevel-asdf-session)) t
)
2987 (when (upgrade-asdf)
2988 ;; If we were upgraded, restart OPERATE the hardest of ways, for
2989 ;; its function may have been redefined.
2990 (return-from operate
2991 (with-asdf-session (:override t
:override-cache t
)
2992 (apply 'operate
(funcall operation-remaker
) component-path keys
))))))
2993 ;; Setup proper bindings around any operate call.
2994 (let* ((*verbose-out
* (and verbose
*standard-output
*))
2995 (*compile-file-warnings-behaviour
* on-warnings
)
2996 (*compile-file-failure-behaviour
* on-failure
)))
2999 (incf (operate-level))
3001 (decf (operate-level)))))
3003 (defmethod operate :before
((operation operation
) (component component
)
3005 (unless (version-satisfies component version
)
3006 (error 'missing-component-of-version
:requires component
:version version
))
3007 (record-dependency nil operation component
))
3009 (defmethod operate ((operation operation
) (component component
)
3010 &key plan-class plan-options
)
3011 (let ((plan (apply 'make-plan plan-class operation component
3012 :forcing
(forcing *asdf-session
*) plan-options
)))
3014 (values operation plan
)))
3016 (defun oos (operation component
&rest args
&key
&allow-other-keys
)
3017 (apply 'operate operation component args
))
3019 (setf (documentation 'oos
'function
)
3020 (format nil
"Short for _operate on system_ and an alias for the OPERATE function.~%~%~a"
3021 (documentation 'operate
'function
)))
3023 (define-condition recursive-operate
(warning)
3024 ((operation :initarg
:operation
:reader condition-operation
)
3025 (component :initarg
:component
:reader condition-component
)
3026 (action :initarg
:action
:reader condition-action
))
3027 (:report
(lambda (c s
)
3028 (format s
(compatfmt "~@<Deprecated recursive use of (~S '~S '~S) while visiting ~S ~
3029 - please use proper dependencies instead~@:>")
3031 (type-of (condition-operation c
))
3032 (component-find-path (condition-component c
))
3033 (action-path (condition-action c
)))))))
3035 ;;;; Common operations
3037 (defmethod component-depends-on ((o prepare-op
) (s system
))
3038 (call-next-method)))
3039 (with-upgradability ()
3040 (defclass build-op
(non-propagating-operation) ()
3041 (:documentation
"Since ASDF3, BUILD-OP is the recommended 'master' operation,
3042 to operate by default on a system or component, via the function BUILD.
3043 Its meaning is configurable via the :BUILD-OPERATION option of a component.
3044 which typically specifies the name of a specific operation to which to delegate the build,
3045 as a symbol or as a string later read as a symbol (after loading the defsystem-depends-on);
3046 if NIL is specified (the default), BUILD-OP falls back to LOAD-OP,
3047 that will load the system in the current image."))
3048 (defmethod component-depends-on ((o build-op
) (c component
))
3049 `((,(or (component-build-operation c
) 'load-op
) ,c
)
3050 ,@(call-next-method)))
3052 (defun make (system &rest keys
)
3053 "The recommended way to interact with ASDF3.1 is via (ASDF:MAKE :FOO).
3054 It will build system FOO using the operation BUILD-OP,
3055 the meaning of which is configurable by the system, and
3056 defaults to LOAD-OP, to load it in current image."
3057 (apply 'operate
'build-op system keys
)
3060 (defun load-system (system &rest keys
&key force force-not verbose version
&allow-other-keys
)
3061 "Shorthand for `(operate 'asdf:load-op system)`. See OPERATE for details."
3062 (declare (ignore force force-not verbose version
))
3063 (apply 'operate
'load-op system keys
)
3066 (defun load-systems* (systems &rest keys
)
3067 "Loading multiple systems at once."
3068 (dolist (s systems
) (apply 'load-system s keys
)))
3070 (defun load-systems (&rest systems
)
3071 "Loading multiple systems at once."
3072 (load-systems* systems
))
3074 (defun compile-system (system &rest args
&key force force-not verbose version
&allow-other-keys
)
3075 "Shorthand for `(asdf:operate 'asdf:compile-op system)`. See OPERATE for details."
3076 (declare (ignore force force-not verbose version
))
3077 (apply 'operate
'compile-op system args
)
3080 (defun test-system (system &rest args
&key force force-not verbose version
&allow-other-keys
)
3081 "Shorthand for `(asdf:operate 'asdf:test-op system)`. See OPERATE for details."
3082 (declare (ignore force force-not verbose version
))
3083 (apply 'operate
'test-op system args
)
3086 ;;;;; Define the function REQUIRE-SYSTEM, that, similarly to REQUIRE,
3087 ;; only tries to load its specified target if it's not loaded yet.
3088 (with-upgradability ()
3089 (defun component-loaded-p (component)
3090 "Has the given COMPONENT been successfully loaded in the current image (yet)?
3091 Note that this returns true even if the component is not up to date."
3092 (if-let ((component (find-component component
() :registered t
)))
3093 (nth-value 1 (component-operation-time (make-operation 'load-op
) component
))))
3095 (defun already-loaded-systems ()
3096 "return a list of the names of the systems that have been successfully loaded so far"
3097 (mapcar 'coerce-name
(remove-if-not 'component-loaded-p
(registered-systems*)))))
3100 ;;;; Define the class REQUIRE-SYSTEM, to be hooked into CL:REQUIRE when possible,
3101 ;; i.e. for ABCL, CLISP, ClozureCL, CMUCL, ECL, MKCL and SBCL
3102 ;; Note that despite the two being homonyms, the _function_ require-system
3103 ;; and the _class_ require-system are quite distinct entities, fulfilling independent purposes.
3104 (with-upgradability ()
3105 (defvar *modules-being-required
* nil
)
3107 (defclass require-system
(system)
3108 ((module :initarg
:module
:initform nil
:accessor required-module
))
3109 (:documentation
"A SYSTEM subclass whose processing is handled by
3110 the implementation's REQUIRE rather than by internal ASDF mechanisms."))
3112 (defmethod perform ((o compile-op
) (c require-system
))
3115 (defmethod perform ((o load-op
) (s require-system
))
3116 (let* ((module (or (required-module s
) (coerce-name s
)))
3117 (*modules-being-required
* (cons module
*modules-being-required
*)))
3118 (assert (null (component-children s
)))
3121 (defmethod resolve-dependency-combination (component (combinator (eql :require
)) arguments
)
3122 (unless (and (length=n-p arguments
1)
3123 (typep (car arguments
) '(or string
(and symbol
(not null
)))))
3124 (parameter-error (compatfmt "~@<In ~S, bad dependency ~S for ~S. ~S takes one argument, a string or non-null symbol~@:>")
3125 'resolve-dependency-combination
3126 (cons combinator arguments
) component combinator
))
3127 ;; :require must be prepared for some implementations providing modules using ASDF,
3128 ;; as SBCL used to do, and others may might do. Thus, the system provided in the end
3129 ;; would be a downcased name as per module-provide-asdf above. For the same reason,
3130 ;; we cannot assume that the system in the end will be of type require-system,
3131 ;; but must check whether we can use find-system and short-circuit cl:require.
3132 ;; Otherwise, calling cl:require could result in nasty reentrant calls between
3133 ;; cl:require and asdf:operate that could potentially blow up the stack,
3134 ;; all the while defeating the consistency of the dependency graph.
3135 (let* ((module (car arguments
)) ;; NB: we already checked that it was not null
3136 ;; CMUCL, MKCL, SBCL like their module names to be all upcase.
3137 (module-name (string module
))
3138 (system-name (string-downcase module
))
3139 (system (find-system system-name nil
)))
3140 (or system
(let ((system (make-instance 'require-system
:name system-name
:module module-name
)))
3141 (register-system system
)
3144 (defun module-provide-asdf (name)
3145 ;; We must use string-downcase, because modules are traditionally specified as symbols,
3146 ;; that implementations traditionally normalize as uppercase, for which we seek a system
3147 ;; with a name that is traditionally in lowercase. Case is lost along the way. That's fine.
3148 ;; We could make complex, non-portable rules to try to preserve case, and just documenting
3149 ;; them would be a hell that it would be a disservice to inflict on users.
3150 (let ((module-name (string name
))
3151 (system-name (string-downcase name
)))
3152 (unless (member module-name
*modules-being-required
* :test
'equal
)
3153 (let ((*modules-being-required
* (cons module-name
*modules-being-required
*))
3154 #+sbcl
(sb-impl::*requiring
* (remove module-name sb-impl
::*requiring
* :test
'equal
)))
3156 (((or style-warning recursive-operate
) #'muffle-warning
)
3157 (missing-component (constantly nil
))
3160 (format *error-output
* (compatfmt "~@<ASDF could not load ~(~A~) because ~A.~@:>~%")
3162 (let ((*verbose-out
* (make-broadcast-stream)))
3163 (let ((system (find-system system-name nil
)))
3165 ;; Do not use require-system after all, use load-system:
3166 ;; on the one hand, REQUIRE already uses *MODULES* not to load something twice,
3167 ;; on the other hand, REQUIRE-SYSTEM uses FORCE-NOT which may conflict with
3168 ;; the toplevel session forcing settings.
3169 (load-system system
:verbose nil
)
3173 ;;;; Some upgrade magic
3174 (with-upgradability ()
3175 (defun restart-upgraded-asdf ()
3176 ;; If we're in the middle of something, restart it.
3177 (let ((systems-being-defined
3178 (when *asdf-session
*
3180 (loop :for k
:being
:the hash-keys
:of
(asdf-cache)
3181 :when
(eq (first k
) 'find-system
) :collect
(second k
))
3182 (clrhash (asdf-cache))))))
3183 ;; Regardless, clear defined systems, since they might be invalid
3184 ;; after an incompatible ASDF upgrade.
3185 (clear-registered-systems)
3186 ;; The configuration also may have to be upgraded.
3187 (upgrade-configuration)
3188 ;; If we were in the middle of an operation, be sure to restore the system being defined.
3189 (dolist (s systems-being-defined
) (find-system s nil
))))
3190 (register-hook-function '*post-upgrade-cleanup-hook
* 'restart-upgraded-asdf
))
3191 ;;;; -------------------------------------------------------------------------
3192 ;;;; Finding systems
3194 (uiop/package
:define-package
:asdf
/find-system
3195 (:recycle
:asdf
/find-system
:asdf
)
3196 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
3197 :asdf
/session
:asdf
/component
:asdf
/system
:asdf
/operation
:asdf
/action
:asdf
/lisp-action
3198 :asdf
/find-component
:asdf
/system-registry
:asdf
/plan
:asdf
/operate
)
3199 (:import-from
#:asdf
/component
#:%additional-input-files
)
3201 #:find-system
#:locate-system
#:load-asd
#:define-op
3202 #:load-system-definition-error
#:error-name
#:error-pathname
#:error-condition
))
3203 (in-package :asdf
/find-system
)
3205 (with-upgradability ()
3206 (define-condition load-system-definition-error
(system-definition-error)
3207 ((name :initarg
:name
:reader error-name
)
3208 (pathname :initarg
:pathname
:reader error-pathname
)
3209 (condition :initarg
:condition
:reader error-condition
))
3210 (:report
(lambda (c s
)
3211 (format s
(compatfmt "~@<Error while trying to load definition for system ~A from pathname ~A: ~3i~_~A~@:>")
3212 (error-name c
) (error-pathname c
) (error-condition c
)))))
3215 ;;; Methods for find-system
3217 ;; Reject NIL as a system designator.
3218 (defmethod find-system ((name null
) &optional
(error-p t
))
3220 (sysdef-error (compatfmt "~@<NIL is not a valid system name~@:>"))))
3222 ;; Default method for find-system: resolve the argument using COERCE-NAME.
3223 (defmethod find-system (name &optional
(error-p t
))
3224 (find-system (coerce-name name
) error-p
))
3226 (defun find-system-if-being-defined (name)
3227 ;; This function finds systems being defined *in the current ASDF session*, as embodied by
3228 ;; its session cache, even before they are fully defined and registered in *registered-systems*.
3229 ;; The purpose of this function is to prevent races between two files that might otherwise
3230 ;; try overwrite each other's system objects, resulting in infinite loops and stack overflow.
3231 ;; This function explicitly MUST NOT find definitions merely registered in previous sessions.
3232 ;; NB: this function depends on a corresponding side-effect in parse-defsystem;
3233 ;; the precise protocol between the two functions may change in the future (or not).
3234 (first (gethash `(find-system ,(coerce-name name
)) (asdf-cache))))
3236 (defclass define-op
(non-propagating-operation) ()
3237 (:documentation
"An operation to record dependencies on loading a .asd file."))
3239 (defmethod record-dependency ((plan null
) (operation t
) (component t
))
3240 (unless (or (typep operation
'define-op
)
3241 (and (typep operation
'load-op
)
3242 (typep component
'system
)
3243 (equal "asdf" (coerce-name component
))))
3244 (if-let ((action (first (visiting-action-list *asdf-session
*))))
3245 (let ((parent-operation (action-operation action
))
3246 (parent-component (action-component action
)))
3248 ((and (typep parent-operation
'define-op
)
3249 (typep parent-component
'system
))
3250 (let ((action (cons operation component
)))
3251 (unless (gethash action
(definition-dependency-set parent-component
))
3252 (push (cons operation component
) (definition-dependency-list parent-component
))
3253 (setf (gethash action
(definition-dependency-set parent-component
)) t
))))
3255 (warn 'recursive-operate
3256 :operation operation
:component component
:action action
)))))))
3258 (defmethod component-depends-on ((o define-op
) (s system
))
3259 `(;;NB: 1- ,@(system-defsystem-depends-on s)) ; Should be already included in the below.
3260 ;; 2- We don't call-next-method to avoid other methods
3261 ,@(loop* :for
(o . c
) :in
(definition-dependency-list s
) :collect
(list o c
))))
3263 (defmethod component-depends-on ((o operation
) (s system
))
3264 `(,@(when (and (not (typep o
'define-op
))
3265 (or (system-source-file s
) (definition-dependency-list s
)))
3266 `((define-op ,(primary-system-name s
))))
3267 ,@(call-next-method)))
3269 (defmethod perform ((o operation
) (c undefined-system
))
3270 (sysdef-error "Trying to use undefined or incompletely defined system ~A" (coerce-name c
)))
3272 ;; TODO: could this file be refactored so that locate-system is merely
3273 ;; the cache-priming call to input-files here?
3274 (defmethod input-files ((o define-op
) (s system
))
3275 (assert (equal (coerce-name s
) (primary-system-name s
)))
3276 (if-let ((asd (system-source-file s
))) (list asd
)))
3278 (defmethod perform ((o define-op
) (s system
))
3279 (assert (equal (coerce-name s
) (primary-system-name s
)))
3281 (if-let ((pathname (first (input-files o s
)))))
3282 (let ((readtable *readtable
*) ;; save outer syntax tables. TODO: proper syntax-control
3283 (print-pprint-dispatch *print-pprint-dispatch
*)))
3284 (with-standard-io-syntax)
3285 (let ((*print-readably
* nil
)
3286 ;; Note that our backward-compatible *readtable* is
3287 ;; a global readtable that gets globally side-effected. Ouch.
3288 ;; Same for the *print-pprint-dispatch* table.
3289 ;; We should do something about that for ASDF3 if possible, or else ASDF4.
3290 (*readtable
* readtable
) ;; restore inside syntax table
3291 (*print-pprint-dispatch
* print-pprint-dispatch
)
3292 (*package
* (find-package :asdf-user
))
3293 (*default-pathname-defaults
*
3294 ;; resolve logical-pathnames so they won't wreak havoc in parsing namestrings.
3295 (pathname-directory-pathname (physicalize-pathname pathname
)))))
3297 (((and error
(not missing-component
))
3298 #'(lambda (condition)
3299 (error 'load-system-definition-error
3300 :name
(coerce-name s
) :pathname pathname
:condition condition
))))
3301 (asdf-message (compatfmt "~&~@<; ~@;Loading system definition~@[ for ~A~] from ~A~@:>~%")
3302 (coerce-name s
) pathname
)
3303 ;; dependencies will depend on what's loaded via definition-dependency-list
3304 (unset-asdf-cache-entry `(component-depends-on ,o
,s
))
3305 (unset-asdf-cache-entry `(input-files ,o
,s
)))
3306 (load* pathname
:external-format
(encoding-external-format (detect-encoding pathname
)))))
3308 (defun load-asd (pathname &key name
)
3309 "Load system definitions from PATHNAME.
3310 NAME if supplied is the name of a system expected to be defined in that file.
3312 Do NOT try to load a .asd file directly with CL:LOAD. Always use ASDF:LOAD-ASD."
3313 (with-asdf-session ()
3314 ;; TODO: use OPERATE, so we consult the cache and only load once per session.
3315 (flet ((do-it (o c
) (operate o c
)))
3316 (let ((primary-name (primary-system-name (or name
(pathname-name pathname
))))
3317 (operation (make-operation 'define-op
)))
3318 (if-let (system (registered-system primary-name
))
3320 ;; We already determine this to be obsolete ---
3321 ;; or should we move some tests from find-system to check for up-to-date-ness here?
3322 (setf (component-operation-time operation system
) t
3323 (definition-dependency-list system
) nil
3324 (definition-dependency-set system
) (list-to-hash-set nil
))
3325 (do-it operation system
))
3326 (let ((system (make-instance 'undefined-system
3327 :name primary-name
:source-file pathname
)))
3328 (register-system system
)
3329 (unwind-protect (do-it operation system
)
3330 (when (typep system
'undefined-system
)
3331 (clear-system system
)))))))))
3333 (defvar *old-asdf-systems
* (make-hash-table :test
'equal
))
3335 ;; (Private) function to check that a system that was found isn't an asdf downgrade.
3336 ;; Returns T if everything went right, NIL if the system was an ASDF of the same or older version,
3337 ;; that shall not be loaded. Also issue a warning if it was a strictly older version of ASDF.
3338 (defun check-not-old-asdf-system (name pathname
)
3339 (or (not (member name
'("asdf" "uiop") :test
'equal
))
3341 (let* ((asdfp (equal name
"asdf")) ;; otherwise, it's uiop
3343 (subpathname pathname
"version" :type
(if asdfp
"lisp-expr" "lisp")))
3344 (version (and (probe-file* version-pathname
:truename nil
)
3345 (read-file-form version-pathname
:at
(if asdfp
'(0) '(2 2 2)))))
3346 (old-version (asdf-version)))
3348 ;; Don't load UIOP of the exact same version: we already loaded it as part of ASDF.
3349 ((and (equal old-version version
) (equal name
"uiop")) nil
)
3350 ((version<= old-version version
) t
) ;; newer or same version: Good!
3351 (t ;; old version: bad
3353 (list (namestring pathname
) version
) *old-asdf-systems
*
3355 (let ((old-pathname (system-source-file (registered-system "asdf"))))
3358 You are using ASDF version ~A ~:[(probably from (require \"asdf\") ~
3359 or loaded by quicklisp)~;from ~:*~S~] and have an older version of ASDF ~
3360 ~:[(and older than 2.27 at that)~;~:*~A~] registered at ~S. ~
3361 Having an ASDF installed and registered is the normal way of configuring ASDF to upgrade itself, ~
3362 and having an old version registered is a configuration error. ~
3363 ASDF will ignore this configured system rather than downgrade itself. ~
3364 In the future, you may want to either: ~
3365 (a) upgrade this configured ASDF to a newer version, ~
3366 (b) install a newer ASDF and register it in front of the former in your configuration, or ~
3367 (c) uninstall or unregister this and any other old version of ASDF from your configuration. ~
3368 Note that the older ASDF might be registered implicitly through configuration inherited ~
3369 from your system installation, in which case you might have to specify ~
3370 :ignore-inherited-configuration in your in your ~~/.config/common-lisp/source-registry.conf ~
3371 or other source-registry configuration file, environment variable or lisp parameter. ~
3372 Indeed, a likely offender is an obsolete version of the cl-asdf debian or ubuntu package, ~
3373 that you might want to upgrade (if a recent enough version is available) ~
3374 or else remove altogether (since most implementations ship with a recent asdf); ~
3375 if you lack the system administration rights to upgrade or remove this package, ~
3376 then you might indeed want to either install and register a more recent version, ~
3377 or use :ignore-inherited-configuration to avoid registering the old one. ~
3378 Please consult ASDF documentation and/or experts.~@:>~%"
3379 old-version old-pathname version pathname
)
3380 ;; NB: for UIOP, don't warn, just ignore.
3381 (warn "ASDF ~A (from ~A), UIOP ~A (from ~A)"
3382 old-version old-pathname version pathname
)
3384 nil
))))) ;; only issue the warning the first time, but always return nil
3386 (defun locate-system (name)
3387 "Given a system NAME designator, try to locate where to load the system from.
3388 Returns five values: FOUNDP FOUND-SYSTEM PATHNAME PREVIOUS PREVIOUS-TIME
3389 FOUNDP is true when a system was found,
3390 either a new unregistered one or a previously registered one.
3391 FOUND-SYSTEM when not null is a SYSTEM object that may be REGISTER-SYSTEM'ed.
3392 PATHNAME when not null is a path from which to load the system,
3393 either associated with FOUND-SYSTEM, or with the PREVIOUS system.
3394 PREVIOUS when not null is a previously loaded SYSTEM object of same name.
3395 PREVIOUS-TIME when not null is the time at which the PREVIOUS system was loaded."
3396 (with-asdf-session () ;; NB: We don't cache the results. We once used to, but it wasn't useful,
3397 ;; and keeping a negative cache was a bug (see lp#1335323), which required
3398 ;; explicit invalidation in clear-system and find-system (when unsucccessful).
3399 (let* ((name (coerce-name name
))
3400 (previous (registered-system name
)) ; load from disk if absent or newer on disk
3401 (primary (registered-system (primary-system-name name
)))
3402 (previous-time (and previous primary
(component-operation-time 'define-op primary
)))
3403 (found (search-for-system-definition name
))
3404 (found-system (and (typep found
'system
) found
))
3405 (pathname (ensure-pathname
3406 (or (and (typep found
'(or pathname string
)) (pathname found
))
3407 (system-source-file found-system
)
3408 (system-source-file previous
))
3409 :want-absolute t
:resolve-symlinks
*resolve-symlinks
*))
3410 (foundp (and (or found-system pathname previous
) t
)))
3411 (check-type found
(or null pathname system
))
3412 (unless (check-not-old-asdf-system name pathname
)
3413 (check-type previous system
) ;; asdf is preloaded, so there should be a previous one.
3414 (setf found-system nil pathname nil
))
3415 (values foundp found-system pathname previous previous-time
))))
3417 ;; Main method for find-system: first, make sure the computation is memoized in a session cache.
3418 ;; Unless the system is immutable, use locate-system to find the primary system;
3419 ;; reconcile the finding (if any) with any previous definition (in a previous session,
3420 ;; preloaded, with a previous configuration, or before filesystem changes), and
3421 ;; load a found .asd if appropriate. Finally, update registration table and return results.
3423 (defun definition-dependencies-up-to-date-p (system)
3424 (check-type system system
)
3425 (assert (primary-system-p system
))
3427 (loop :with plan
= (make-instance *plan-class
*)
3428 :for action
:in
(definition-dependency-list system
)
3429 :always
(action-up-to-date-p
3430 plan
(action-operation action
) (action-component action
))
3432 (let ((o (make-operation 'define-op
)))
3433 (multiple-value-bind (stamp done-p
)
3434 (compute-action-stamp plan o system
)
3435 (return (and (timestamp<= stamp
(component-operation-time o system
))
3437 (system-out-of-date () nil
)))
3439 (defmethod find-system ((name string
) &optional
(error-p t
))
3441 (with-asdf-session (:key
`(find-system ,name
)))
3442 (let ((name-primary-p (primary-system-p name
)))
3443 (unless name-primary-p
(find-system (primary-system-name name
) nil
)))
3444 (or (and *immutable-systems
* (gethash name
*immutable-systems
*) (registered-system name
)))
3445 (multiple-value-bind (foundp found-system pathname previous previous-time
)
3446 (locate-system name
)
3447 (assert (eq foundp
(and (or found-system pathname previous
) t
))))
3448 (let ((previous-pathname (system-source-file previous
))
3449 (system (or previous found-system
)))
3450 (when (and found-system
(not previous
))
3451 (register-system found-system
))
3452 (when (and system pathname
)
3453 (setf (system-source-file system
) pathname
))
3454 (if-let ((stamp (get-file-stamp pathname
)))
3457 (or (pathname-equal pathname previous-pathname
)
3458 (and pathname previous-pathname
3460 (physicalize-pathname pathname
)
3461 (physicalize-pathname previous-pathname
))))
3462 (timestamp<= stamp previous-time
)
3463 ;; TODO: check that all dependencies are up-to-date.
3464 ;; This necessitates traversing them without triggering
3465 ;; the adding of nodes to the plan.
3466 (or (not name-primary-p
)
3467 (definition-dependencies-up-to-date-p previous
)))))
3468 (unless up-to-date-p
3470 (signal 'system-out-of-date
:name name
)
3471 (continue () :report
"continue"))
3472 (load-asd pathname
:name name
)))))
3473 ;; Try again after having loaded from disk if needed
3474 (or (registered-system name
)
3475 (when error-p
(error 'missing-component
:requires name
)))))
3477 ;; Resolved forward reference for asdf/system-registry.
3478 (defun mark-component-preloaded (component)
3479 "Mark a component as preloaded."
3480 (let ((component (find-component component nil
:registered t
)))
3481 ;; Recurse to children, so asdf/plan will hopefully be happy.
3482 (map () 'mark-component-preloaded
(component-children component
))
3483 ;; Mark the timestamps of the common lisp-action operations as 0.
3484 (let ((cot (component-operation-times component
)))
3485 (dolist (o `(,@(when (primary-system-p component
) '(define-op))
3486 prepare-op compile-op load-op
))
3487 (setf (gethash (make-operation o
) cot
) 0))))))
3488 ;;;; -------------------------------------------------------------------------
3491 (uiop/package
:define-package
:asdf
/parse-defsystem
3492 (:recycle
:asdf
/parse-defsystem
:asdf
/defsystem
:asdf
)
3493 (:nicknames
:asdf
/defsystem
) ;; previous name, to be compatible with, in case anyone cares
3494 (:use
:uiop
/common-lisp
:asdf
/driver
:asdf
/upgrade
3495 :asdf
/session
:asdf
/component
:asdf
/system
:asdf
/system-registry
3496 :asdf
/find-component
:asdf
/action
:asdf
/lisp-action
:asdf
/operate
)
3497 (:import-from
:asdf
/system
#:depends-on
#:weakly-depends-on
)
3498 ;; these needed for record-additional-system-input-file
3499 (:import-from
:asdf
/operation
#:make-operation
)
3500 (:import-from
:asdf
/component
#:%additional-input-files
)
3501 (:import-from
:asdf
/find-system
#:define-op
)
3503 #:defsystem
#:register-system-definition
3504 #:class-for-type
#:*default-component-class
*
3505 #:determine-system-directory
#:parse-component-form
3506 #:non-toplevel-system
#:non-system-system
#:bad-system-name
3507 #:sysdef-error-component
#:check-component-input
3509 (in-package :asdf
/parse-defsystem
)
3512 (with-upgradability ()
3513 (defun determine-system-directory (pathname)
3514 ;; The defsystem macro calls this function to determine the pathname of a system as follows:
3515 ;; 1. If the pathname argument is an pathname object (NOT a namestring),
3516 ;; that is already an absolute pathname, return it.
3517 ;; 2. Otherwise, the directory containing the LOAD-PATHNAME
3518 ;; is considered (as deduced from e.g. *LOAD-PATHNAME*), and
3519 ;; if it is indeed available and an absolute pathname, then
3520 ;; the PATHNAME argument is normalized to a relative pathname
3521 ;; as per PARSE-UNIX-NAMESTRING (with ENSURE-DIRECTORY T)
3522 ;; and merged into that DIRECTORY as per SUBPATHNAME.
3523 ;; Note: avoid *COMPILE-FILE-PATHNAME* because the .asd is loaded as source,
3524 ;; but may be from within the EVAL-WHEN of a file compilation.
3525 ;; If no absolute pathname was found, we return NIL.
3526 (check-type pathname
(or null string pathname
))
3527 (pathname-directory-pathname
3529 (ensure-absolute-pathname
3530 (parse-unix-namestring pathname
:type
:directory
)
3531 #'(lambda () (ensure-absolute-pathname
3532 (load-pathname) 'get-pathname-defaults nil
))
3537 (with-upgradability ()
3538 ;; What :file gets interpreted as, unless overridden by a :default-component-class
3539 (defvar *default-component-class
* 'cl-source-file
)
3541 (defun class-for-type (parent type
)
3542 (or (coerce-class type
:package
:asdf
/interface
:super
'component
:error nil
)
3543 (and (eq type
:file
)
3545 (or (loop :for p
= parent
:then
(component-parent p
) :while p
3546 :thereis
(module-default-component-class p
))
3547 *default-component-class
*)
3548 :package
:asdf
/interface
:super
'component
:error nil
))
3549 (sysdef-error "don't recognize component type ~S" type
))))
3553 (with-upgradability ()
3554 (define-condition non-system-system
(system-definition-error)
3555 ((name :initarg
:name
:reader non-system-system-name
)
3556 (class-name :initarg
:class-name
:reader non-system-system-class-name
))
3557 (:report
(lambda (c s
)
3558 (format s
(compatfmt "~@<Error while defining system ~S: class ~S isn't a subclass of ~S~@:>")
3559 (non-system-system-name c
) (non-system-system-class-name c
) 'system
))))
3561 (define-condition non-toplevel-system
(system-definition-error)
3562 ((parent :initarg
:parent
:reader non-toplevel-system-parent
)
3563 (name :initarg
:name
:reader non-toplevel-system-name
))
3564 (:report
(lambda (c s
)
3565 (format s
(compatfmt "~@<Error while defining system: component ~S claims to have a system ~S as a child~@:>")
3566 (non-toplevel-system-parent c
) (non-toplevel-system-name c
)))))
3568 (define-condition bad-system-name
(warning)
3569 ((name :initarg
:name
:reader component-name
)
3570 (source-file :initarg
:source-file
:reader system-source-file
))
3571 (:report
(lambda (c s
)
3572 (let* ((file (system-source-file c
))
3573 (name (component-name c
))
3574 (asd (pathname-name file
)))
3575 (format s
(compatfmt "~@<System definition file ~S contains definition for system ~S. ~
3576 Please only define ~S and secondary systems with a name starting with ~S (e.g. ~S) in that file.~@:>")
3577 file name asd
(strcat asd
"/") (strcat asd
"/test"))))))
3579 (defun sysdef-error-component (msg type name value
)
3580 (sysdef-error (strcat msg
(compatfmt "~&~@<The value specified for ~(~A~) ~A is ~S~@:>"))
3583 (defun check-component-input (type name weakly-depends-on
3584 depends-on components
)
3585 "A partial test of the values of a component."
3586 (unless (listp depends-on
)
3587 (sysdef-error-component ":depends-on must be a list."
3588 type name depends-on
))
3589 (unless (listp weakly-depends-on
)
3590 (sysdef-error-component ":weakly-depends-on must be a list."
3591 type name weakly-depends-on
))
3592 (unless (listp components
)
3593 (sysdef-error-component ":components must be NIL or a list of components."
3594 type name components
)))
3597 (defun record-additional-system-input-file (pathname component parent
)
3598 (let* ((record-on (if parent
3600 :for par
= parent
:then
(component-parent par
)
3602 :do
(setf retval par
)
3603 :finally
(return retval
))
3605 (comp (if (typep record-on
'component
)
3607 ;; at this point there will be no parent for RECORD-ON
3608 (find-component record-on nil
)))
3609 (op (make-operation 'define-op
))
3610 (cell (or (assoc op
(%additional-input-files comp
))
3611 (let ((new-cell (list op
)))
3612 (push new-cell
(%additional-input-files comp
))
3614 (pushnew pathname
(cdr cell
) :test
'pathname-equal
)
3617 ;; Given a form used as :version specification, in the context of a system definition
3618 ;; in a file at PATHNAME, for given COMPONENT with given PARENT, normalize the form
3619 ;; to an acceptable ASDF-format version.
3620 (defun* (normalize-version) (form &key pathname component parent
)
3621 (labels ((invalid (&optional
(continuation "using NIL instead"))
3622 (warn (compatfmt "~@<Invalid :version specifier ~S~@[ for component ~S~]~@[ in ~S~]~@[ from file ~S~]~@[, ~A~]~@:>")
3623 form component parent pathname continuation
))
3624 (invalid-parse (control &rest args
)
3625 (unless (if-let (target (find-component parent component
)) (builtin-system-p target
))
3626 (apply 'warn control args
)
3628 (if-let (v (typecase form
3629 ((or string null
) form
)
3631 (invalid "Substituting a string")
3632 (format nil
"~D" form
)) ;; 1.0 becomes "1.0"
3636 (destructuring-bind (subpath &key
(at 0)) (rest form
)
3637 (let ((path (subpathname pathname subpath
)))
3638 (record-additional-system-input-file path component parent
)
3639 (safe-read-file-form path
3640 :at at
:package
:asdf-user
))))
3642 (destructuring-bind (subpath &key
(at 0)) (rest form
)
3643 (let ((path (subpathname pathname subpath
)))
3644 (record-additional-system-input-file path component parent
)
3645 (safe-read-file-line (subpathname pathname subpath
)
3651 (if-let (pv (parse-version v
#'invalid-parse
))
3652 (unparse-version pv
)
3656 ;;; "inline methods"
3657 (with-upgradability ()
3658 (defparameter* +asdf-methods
+
3659 '(perform-with-restarts perform explain output-files operation-done-p
))
3661 (defun %remove-component-inline-methods
(component)
3662 (dolist (name +asdf-methods
+)
3664 ;; this is inefficient as most of the stored
3665 ;; methods will not be for this particular gf
3666 ;; But this is hardly performance-critical
3668 (remove-method (symbol-function name
) m
))
3669 (component-inline-methods component
)))
3670 (component-inline-methods component
) nil
)
3672 (defun %define-component-inline-methods
(ret rest
)
3673 (loop* :for
(key value
) :on rest
:by
#'cddr
3674 :for name
= (and (keywordp key
) (find key
+asdf-methods
+ :test
'string
=))
3676 (destructuring-bind (op &rest body
) value
3677 (loop :for arg
= (pop body
)
3679 :collect arg
:into qualifiers
3681 (destructuring-bind (o c
) arg
3683 (eval `(defmethod ,name
,@qualifiers
((,o
,op
) (,c
(eql ,ret
))) ,@body
))
3684 (component-inline-methods ret
)))))))
3686 (defun %refresh-component-inline-methods
(component rest
)
3687 ;; clear methods, then add the new ones
3688 (%remove-component-inline-methods component
)
3689 (%define-component-inline-methods component rest
)))
3692 ;;; Main parsing function
3693 (with-upgradability ()
3694 (defun parse-dependency-def (dd)
3698 (unless (= (length dd
) 3)
3699 (sysdef-error "Ill-formed feature dependency: ~s" dd
))
3700 (let ((embedded (parse-dependency-def (third dd
))))
3701 `(:feature
,(second dd
) ,embedded
)))
3703 (sysdef-error "`feature' has been removed from the dependency spec language of ASDF. Use :feature instead in ~s." dd
))
3705 (unless (= (length dd
) 2)
3706 (sysdef-error "Ill-formed require dependency: ~s" dd
))
3709 (unless (= (length dd
) 3)
3710 (sysdef-error "Ill-formed version dependency: ~s" dd
))
3711 `(:version
,(coerce-name (second dd
)) ,(third dd
)))
3712 (otherwise (sysdef-error "Ill-formed dependency: ~s" dd
)))
3715 (defun parse-dependency-defs (dd-list)
3716 "Parse the dependency defs in DD-LIST into canonical form by translating all
3717 system names contained using COERCE-NAME. Return the result."
3718 (mapcar 'parse-dependency-def dd-list
))
3720 (defun* (parse-component-form) (parent options
&key previous-serial-component
)
3722 (type name
&rest rest
&key
3723 (builtin-system-p () bspp
)
3724 ;; the following list of keywords is reproduced below in the
3725 ;; remove-plist-keys form. important to keep them in sync
3726 components pathname perform explain output-files operation-done-p
3727 weakly-depends-on depends-on serial
3728 do-first if-component-dep-fails version
3730 &allow-other-keys
) options
3731 (declare (ignore perform explain output-files operation-done-p builtin-system-p
))
3732 (check-component-input type name weakly-depends-on depends-on components
)
3734 (find-component parent name
)
3735 (not ;; ignore the same object when rereading the defsystem
3736 (typep (find-component parent name
)
3737 (class-for-type parent type
))))
3738 (error 'duplicate-names
:name name
))
3739 (when do-first
(error "DO-FIRST is not supported anymore as of ASDF 3"))
3740 (let* ((name (coerce-name name
))
3743 ,@(when parent
`(:parent
,parent
))
3744 ,@(remove-plist-keys
3745 '(:components
:pathname
:if-component-dep-fails
:version
3746 :perform
:explain
:output-files
:operation-done-p
3747 :weakly-depends-on
:depends-on
:serial
)
3749 (component (find-component parent name
))
3750 (class (class-for-type parent type
)))
3751 (when (and parent
(subtypep class
'system
))
3752 (error 'non-toplevel-system
:parent parent
:name name
))
3753 (if component
; preserve identity
3754 (apply 'reinitialize-instance component args
)
3755 (setf component
(apply 'make-instance class args
)))
3756 (component-pathname component
) ; eagerly compute the absolute pathname
3757 (when (typep component
'system
)
3758 ;; cache information for introspection
3759 (setf (slot-value component
'depends-on
)
3760 (parse-dependency-defs depends-on
)
3761 (slot-value component
'weakly-depends-on
)
3762 ;; these must be a list of systems, cannot be features or versioned systems
3763 (mapcar 'coerce-name weakly-depends-on
)))
3764 (let ((sysfile (system-source-file (component-system component
)))) ;; requires the previous
3765 (when (and (typep component
'system
) (not bspp
))
3766 (setf (builtin-system-p component
) (lisp-implementation-pathname-p sysfile
)))
3767 (setf version
(normalize-version version
:component name
:parent parent
:pathname sysfile
)))
3768 ;; Don't use the accessor: kluge to avoid upgrade issue on CCL 1.8.
3769 ;; A better fix is required.
3770 (setf (slot-value component
'version
) version
)
3771 (when (typep component
'parent-component
)
3772 (setf (component-children component
)
3774 :with previous-component
= nil
3775 :for c-form
:in components
3776 :for c
= (parse-component-form component c-form
3777 :previous-serial-component previous-component
)
3778 :for name
= (component-name c
)
3780 :when serial
:do
(setf previous-component name
)))
3781 (compute-children-by-name component
))
3782 (when previous-serial-component
3783 (push previous-serial-component depends-on
))
3784 (when weakly-depends-on
3785 ;; ASDF4: deprecate this feature and remove it.
3787 (remove-if (complement #'(lambda (x) (find-system x nil
))) weakly-depends-on
)))
3788 ;; Used by POIU. ASDF4: rename to component-depends-on?
3789 (setf (component-sideway-dependencies component
) depends-on
)
3790 (%refresh-component-inline-methods component rest
)
3791 (when if-component-dep-fails
3792 (error "The system definition for ~S uses deprecated ~
3793 ASDF option :IF-COMPONENT-DEP-FAILS. ~
3794 Starting with ASDF 3, please use :IF-FEATURE instead"
3795 (coerce-name (component-system component
))))
3798 (defun register-system-definition
3799 (name &rest options
&key pathname
(class 'system
) (source-file () sfp
)
3800 defsystem-depends-on
&allow-other-keys
)
3801 ;; The system must be registered before we parse the body,
3802 ;; otherwise we recur when trying to find an existing system
3803 ;; of the same name to reuse options (e.g. pathname) from.
3804 ;; To avoid infinite recursion in cases where you defsystem a system
3805 ;; that is registered to a different location to find-system,
3806 ;; we also need to remember it in the asdf-cache.
3808 (with-asdf-session ())
3809 (let* ((name (coerce-name name
))
3810 (source-file (if sfp source-file
(resolve-symlinks* (load-pathname))))))
3811 (flet ((fix-case (x) (if (logical-pathname-p source-file
) (string-downcase x
) x
))))
3812 (let* ((asd-name (and source-file
3813 (equal "asd" (fix-case (pathname-type source-file
)))
3814 (fix-case (pathname-name source-file
))))
3815 (primary-name (primary-system-name name
)))
3816 (when (and asd-name
(not (equal asd-name primary-name
)))
3817 (warn (make-condition 'bad-system-name
:source-file source-file
:name name
))))
3818 (let* (;; NB: handle defsystem-depends-on BEFORE to create the system object,
3819 ;; so that in case it fails, there is no incomplete object polluting the build.
3820 (checked-defsystem-depends-on
3821 (let* ((dep-forms (parse-dependency-defs defsystem-depends-on
))
3822 (deps (loop :for spec
:in dep-forms
3823 :when
(resolve-dependency-spec nil spec
)
3825 (load-systems* deps
)
3827 (system (or (find-system-if-being-defined name
)
3828 (if-let (registered (registered-system name
))
3829 (reset-system-class registered
'undefined-system
3830 :name name
:source-file source-file
)
3831 (register-system (make-instance 'undefined-system
3832 :name name
:source-file source-file
)))))
3835 (remove-plist-keys '(:defsystem-depends-on
:class
) options
)
3836 ;; cache defsystem-depends-on in canonical form
3837 (when checked-defsystem-depends-on
3838 `(:defsystem-depends-on
,checked-defsystem-depends-on
))))
3839 (directory (determine-system-directory pathname
)))
3840 ;; This works hand in hand with asdf/find-system:find-system-if-being-defined:
3841 (set-asdf-cache-entry `(find-system ,name
) (list system
)))
3842 ;; We change-class AFTER we loaded the defsystem-depends-on
3843 ;; since the class might be defined as part of those.
3844 (let ((class (class-for-type nil class
)))
3845 (unless (subtypep class
'system
)
3846 (error 'non-system-system
:name name
:class-name
(class-name class
)))
3847 (unless (eq (type-of system
) class
)
3848 (reset-system-class system class
)))
3849 (parse-component-form nil
(list* :module name
:pathname directory component-options
))))
3851 (defmacro defsystem
(name &body options
)
3852 `(apply 'register-system-definition
',name
',options
)))
3853 ;;;; -------------------------------------------------------------------------
3856 (uiop/package
:define-package
:asdf
/bundle
3857 (:recycle
:asdf
/bundle
:asdf
)
3858 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
3859 :asdf
/component
:asdf
/system
:asdf
/operation
3860 :asdf
/find-component
;; used by ECL
3861 :asdf
/action
:asdf
/lisp-action
:asdf
/plan
:asdf
/operate
:asdf
/parse-defsystem
)
3863 #:bundle-op
#:bundle-type
#:program-system
3864 #:bundle-system
#:bundle-pathname-type
#:direct-dependency-files
3865 #:monolithic-op
#:monolithic-bundle-op
#:operation-monolithic-p
3866 #:basic-compile-bundle-op
#:prepare-bundle-op
3867 #:compile-bundle-op
#:load-bundle-op
#:monolithic-compile-bundle-op
#:monolithic-load-bundle-op
3868 #:lib-op
#:monolithic-lib-op
3869 #:dll-op
#:monolithic-dll-op
3870 #:deliver-asd-op
#:monolithic-deliver-asd-op
3871 #:program-op
#:image-op
#:compiled-file
#:precompiled-system
#:prebuilt-system
3872 #:user-system-p
#:user-system
#:trivial-system-p
3873 #:prologue-code
#:epilogue-code
#:static-library
))
3874 (in-package :asdf
/bundle
)
3876 (with-upgradability ()
3877 (defclass bundle-op
(operation)
3878 ;; NB: use of instance-allocated slots for operations is DEPRECATED
3879 ;; and only supported in a temporary fashion for backward compatibility.
3880 ;; Supported replacement: Define slots on program-system instead.
3881 ((bundle-type :initform
:no-output-file
:reader bundle-type
:allocation
:class
))
3882 (:documentation
"base class for operations that bundle outputs from multiple components"))
3884 (defclass monolithic-op
(operation) ()
3885 (:documentation
"A MONOLITHIC operation operates on a system *and all of its
3886 dependencies*. So, for example, a monolithic concatenate operation will
3887 concatenate together a system's components and all of its dependencies, but a
3888 simple concatenate operation will concatenate only the components of the system
3891 (defclass monolithic-bundle-op
(bundle-op monolithic-op
)
3892 ;; Old style way of specifying prologue and epilogue on ECL: in the monolithic operation.
3893 ;; DEPRECATED. Supported replacement: Define slots on program-system instead.
3894 ((prologue-code :initform nil
:accessor prologue-code
)
3895 (epilogue-code :initform nil
:accessor epilogue-code
))
3896 (:documentation
"operations that are both monolithic-op and bundle-op"))
3898 (defclass program-system
(system)
3899 ;; New style (ASDF3.1) way of specifying prologue and epilogue on ECL: in the system
3900 ((prologue-code :initform nil
:initarg
:prologue-code
:reader prologue-code
)
3901 (epilogue-code :initform nil
:initarg
:epilogue-code
:reader epilogue-code
)
3902 (no-uiop :initform nil
:initarg
:no-uiop
:reader no-uiop
)
3903 (prefix-lisp-object-files :initarg
:prefix-lisp-object-files
3904 :initform nil
:accessor prefix-lisp-object-files
)
3905 (postfix-lisp-object-files :initarg
:postfix-lisp-object-files
3906 :initform nil
:accessor postfix-lisp-object-files
)
3907 (extra-object-files :initarg
:extra-object-files
3908 :initform nil
:accessor extra-object-files
)
3909 (extra-build-args :initarg
:extra-build-args
3910 :initform nil
:accessor extra-build-args
)))
3912 (defmethod prologue-code ((x system
)) nil
)
3913 (defmethod epilogue-code ((x system
)) nil
)
3914 (defmethod no-uiop ((x system
)) nil
)
3915 (defmethod prefix-lisp-object-files ((x system
)) nil
)
3916 (defmethod postfix-lisp-object-files ((x system
)) nil
)
3917 (defmethod extra-object-files ((x system
)) nil
)
3918 (defmethod extra-build-args ((x system
)) nil
)
3920 (defclass link-op
(bundle-op) ()
3921 (:documentation
"Abstract operation for linking files together"))
3923 (defclass gather-operation
(bundle-op)
3924 ((gather-operation :initform nil
:allocation
:class
:reader gather-operation
)
3925 (gather-type :initform
:no-output-file
:allocation
:class
:reader gather-type
))
3926 (:documentation
"Abstract operation for gathering many input files from a system"))
3928 (defun operation-monolithic-p (op)
3929 (typep op
'monolithic-op
))
3931 ;; Dependencies of a gather-op are the actions of the dependent operation
3932 ;; for all the (sorted) required components for loading the system.
3933 ;; Monolithic operations typically use lib-op as the dependent operation,
3934 ;; and all system-level dependencies as required components.
3935 ;; Non-monolithic operations typically use compile-op as the dependent operation,
3936 ;; and all transitive sub-components as required components (excluding other systems).
3937 (defmethod component-depends-on ((o gather-operation
) (s system
))
3938 (let* ((mono (operation-monolithic-p o
))
3939 (go (make-operation (or (gather-operation o
) 'compile-op
)))
3940 (bundle-p (typep go
'bundle-op
))
3941 ;; In a non-mono operation, don't recurse to other systems.
3942 ;; In a mono operation gathering bundles, don't recurse inside systems.
3943 (component-type (if mono
(if bundle-p
'system t
) '(not system
)))
3944 ;; In the end, only keep system bundles or non-system bundles, depending.
3945 (keep-component (if bundle-p
'system
'(not system
)))
3947 ;; Required-components only looks at the dependencies of an action, excluding the action
3948 ;; itself, so it may be safely used by an action recursing on its dependencies (which
3949 ;; may or may not be an overdesigned API, since in practice we never use it that way).
3950 ;; Therefore, if we use :goal-operation 'load-op :keep-operation 'load-op, which looks
3951 ;; cleaner, we will miss the load-op on the requested system itself, which doesn't
3952 ;; matter for a regular system, but matters, a lot, for a package-inferred-system.
3953 ;; Using load-op as the goal operation and basic-compile-op as the keep-operation works
3954 ;; for our needs of gathering all the files we want to include in a bundle.
3955 ;; Note that we use basic-compile-op rather than compile-op so it will still work on
3956 ;; systems that would somehow load dependencies with load-bundle-op.
3957 (required-components
3958 s
:other-systems mono
:component-type component-type
:keep-component keep-component
3959 :goal-operation
'load-op
:keep-operation
'basic-compile-op
)))
3960 `((,go
,@deps
) ,@(call-next-method))))
3962 ;; Create a single fasl for the entire library
3963 (defclass basic-compile-bundle-op
(bundle-op basic-compile-op
)
3964 ((gather-type :initform
#-
(or clasp ecl mkcl
) :fasl
#+(or clasp ecl mkcl
) :object
3966 (bundle-type :initform
:fasb
:allocation
:class
))
3967 (:documentation
"Base class for compiling into a bundle"))
3969 ;; Analog to prepare-op, for load-bundle-op and compile-bundle-op
3970 (defclass prepare-bundle-op
(sideway-operation)
3972 :initform
#+(or clasp ecl mkcl
) 'load-bundle-op
#-
(or clasp ecl mkcl
) 'load-op
3973 :allocation
:class
))
3974 (:documentation
"Operation class for loading the bundles of a system's dependencies"))
3976 (defclass lib-op
(link-op gather-operation non-propagating-operation
)
3977 ((gather-type :initform
:object
:allocation
:class
)
3978 (bundle-type :initform
:lib
:allocation
:class
))
3979 (:documentation
"Compile the system and produce a linkable static library (.a/.lib)
3980 for all the linkable object files associated with the system. Compare with DLL-OP.
3982 On most implementations, these object files only include extensions to the runtime
3983 written in C or another language with a compiler producing linkable object files.
3984 On CLASP, ECL, MKCL, these object files _also_ include the contents of Lisp files
3985 themselves. In any case, this operation will produce what you need to further build
3986 a static runtime for your system, or a dynamic library to load in an existing runtime."))
3988 ;; What works: on ECL, CLASP(?), MKCL, we link the many .o files from the system into the .so;
3989 ;; on other implementations, we combine (usually concatenate) the .fasl files into one.
3990 (defclass compile-bundle-op
(basic-compile-bundle-op selfward-operation gather-operation
3991 #+(or clasp ecl mkcl
) link-op
)
3992 ((selfward-operation :initform
'(prepare-bundle-op) :allocation
:class
))
3993 (:documentation
"This operator is an alternative to COMPILE-OP. Build a system
3994 and all of its dependencies, but build only a single (\"monolithic\") FASL, instead
3995 of one per source file, which may be more resource efficient. That monolithic
3996 FASL should be loaded with LOAD-BUNDLE-OP, rather than LOAD-OP."))
3998 (defclass load-bundle-op
(basic-load-op selfward-operation
)
3999 ((selfward-operation :initform
'(prepare-bundle-op compile-bundle-op
) :allocation
:class
))
4000 (:documentation
"This operator is an alternative to LOAD-OP. Build a system
4001 and all of its dependencies, using COMPILE-BUNDLE-OP. The difference with
4002 respect to LOAD-OP is that it builds only a single FASL, which may be
4003 faster and more resource efficient."))
4005 ;; NB: since the monolithic-op's can't be sideway-operation's,
4006 ;; if we wanted lib-op, dll-op, deliver-asd-op to be sideway-operation's,
4007 ;; we'd have to have the monolithic-op not inherit from the main op,
4008 ;; but instead inherit from a basic-FOO-op as with basic-compile-bundle-op above.
4010 (defclass dll-op
(link-op gather-operation non-propagating-operation
)
4011 ((gather-type :initform
:object
:allocation
:class
)
4012 (bundle-type :initform
:dll
:allocation
:class
))
4013 (:documentation
"Compile the system and produce a dynamic loadable library (.so/.dll)
4014 for all the linkable object files associated with the system. Compare with LIB-OP."))
4016 (defclass deliver-asd-op
(basic-compile-op selfward-operation
)
4017 ((selfward-operation
4018 ;; TODO: implement link-op on all implementations, and make that
4019 ;; '(compile-bundle-op lib-op #-(or clasp ecl mkcl) dll-op)
4020 :initform
'(compile-bundle-op #+(or clasp ecl mkcl
) lib-op
)
4021 :allocation
:class
))
4022 (:documentation
"produce an asd file for delivering the system as a single fasl"))
4025 (defclass monolithic-deliver-asd-op
(deliver-asd-op monolithic-bundle-op
)
4026 ((selfward-operation
4027 ;; TODO: implement link-op on all implementations, and make that
4028 ;; '(monolithic-compile-bundle-op monolithic-lib-op #-(or clasp ecl mkcl) monolithic-dll-op)
4029 :initform
'(monolithic-compile-bundle-op #+(or clasp ecl mkcl
) monolithic-lib-op
)
4030 :allocation
:class
))
4031 (:documentation
"produce fasl and asd files for combined system and dependencies."))
4033 (defclass monolithic-compile-bundle-op
4034 (basic-compile-bundle-op monolithic-bundle-op
4035 #+(or clasp ecl mkcl
) link-op gather-operation non-propagating-operation
)
4037 (:documentation
"Create a single fasl for the system and its dependencies."))
4039 (defclass monolithic-load-bundle-op
(load-bundle-op monolithic-bundle-op
)
4040 ((selfward-operation :initform
'monolithic-compile-bundle-op
:allocation
:class
))
4041 (:documentation
"Load a single fasl for the system and its dependencies."))
4043 (defclass monolithic-lib-op
(lib-op monolithic-bundle-op non-propagating-operation
)
4044 ((gather-type :initform
:object
:allocation
:class
))
4045 (:documentation
"Compile the system and produce a linkable static library (.a/.lib)
4046 for all the linkable object files associated with the system or its dependencies. See LIB-OP."))
4048 (defclass monolithic-dll-op
(dll-op monolithic-bundle-op non-propagating-operation
)
4049 ((gather-type :initform
:object
:allocation
:class
))
4050 (:documentation
"Compile the system and produce a dynamic loadable library (.so/.dll)
4051 for all the linkable object files associated with the system or its dependencies. See LIB-OP"))
4053 (defclass image-op
(monolithic-bundle-op selfward-operation
4054 #+(or clasp ecl mkcl
) link-op
#+(or clasp ecl mkcl
) gather-operation
)
4055 ((bundle-type :initform
:image
:allocation
:class
)
4056 (gather-operation :initform
'lib-op
:allocation
:class
)
4057 #+(or clasp ecl mkcl
) (gather-type :initform
:static-library
:allocation
:class
)
4058 (selfward-operation :initform
'(#-
(or clasp ecl mkcl
) load-op
) :allocation
:class
))
4059 (:documentation
"create an image file from the system and its dependencies"))
4061 (defclass program-op
(image-op)
4062 ((bundle-type :initform
:program
:allocation
:class
))
4063 (:documentation
"create an executable file from the system and its dependencies"))
4065 ;; From the ASDF-internal bundle-type identifier, get a filesystem-usable pathname type.
4066 (defun bundle-pathname-type (bundle-type)
4067 (etypecase bundle-type
4068 ((or null string
) ;; pass through nil or string literal
4070 ((eql :no-output-file
) ;; marker for a bundle-type that has NO output file
4071 (error "No output file, therefore no pathname type"))
4072 ((eql :fasl
) ;; the type of a fasl
4073 (compile-file-type)) ; on image-based platforms, used as input and output
4074 ((eql :fasb
) ;; the type of a fasl
4075 #-
(or clasp ecl mkcl
) (compile-file-type) ; on image-based platforms, used as input and output
4076 #+(or clasp ecl mkcl
) "fasb") ; on C-linking platforms, only used as output for system bundles
4079 #+(and clisp os-windows
) "exe"
4080 #-
(or allegro
(and clisp os-windows
)) "image")
4081 ;; NB: on CLASP and ECL these implementations, we better agree with
4082 ;; (compile-file-type :type bundle-type))
4083 ((eql :object
) ;; the type of a linkable object file
4084 (os-cond ((os-unix-p) "o")
4085 ((os-windows-p) (if (featurep '(:or
:mingw32
:mingw64
)) "o" "obj"))))
4086 ((member :lib
:static-library
) ;; the type of a linkable library
4087 (os-cond ((os-unix-p) "a")
4088 ((os-windows-p) (if (featurep '(:or
:mingw32
:mingw64
)) "a" "lib"))))
4089 ((member :dll
:shared-library
) ;; the type of a shared library
4090 (os-cond ((os-macosx-p) "dylib") ((os-unix-p) "so") ((os-windows-p) "dll")))
4091 ((eql :program
) ;; the type of an executable program
4092 (os-cond ((os-unix-p) nil
) ((os-windows-p) "exe")))))
4094 ;; Compute the output-files for a given bundle action
4095 (defun bundle-output-files (o c
)
4096 (let ((bundle-type (bundle-type o
)))
4097 (unless (or (eq bundle-type
:no-output-file
) ;; NIL already means something regarding type.
4098 (and (null (input-files o c
)) (not (member bundle-type
'(:image
:program
)))))
4099 (let ((name (or (component-build-pathname c
)
4101 (unless (typep o
'program-op
)
4102 ;; "." is no good separator for Logical Pathnames, so we use "--"
4103 (if (operation-monolithic-p o
)
4105 ;; These use a different type .fasb or .a instead of .fasl
4106 #-
(or clasp ecl mkcl
) "--system"))))
4107 (format nil
"~A~@[~A~]" (component-name c
) suffix
))))
4108 (type (bundle-pathname-type bundle-type
)))
4109 (values (list (subpathname (component-pathname c
) name
:type type
))
4110 (eq (class-of o
) (coerce-class (component-build-operation c
)
4111 :package
:asdf
/interface
4115 (defmethod output-files ((o bundle-op
) (c system
))
4116 (bundle-output-files o c
))
4118 #-
(or clasp ecl mkcl
)
4120 (defmethod perform ((o image-op
) (c system
))
4121 (dump-image (output-file o c
) :executable
(typep o
'program-op
)))
4122 (defmethod perform :before
((o program-op
) (c system
))
4123 (setf *image-entry-point
* (ensure-function (component-entry-point c
)))))
4125 (defclass compiled-file
(file-component)
4126 ((type :initform
#-
(or clasp ecl mkcl
) (compile-file-type) #+(or clasp ecl mkcl
) "fasb"))
4127 (:documentation
"Class for a file that is already compiled,
4128 e.g. as part of the implementation, of an outer build system that calls into ASDF,
4129 or of opaque libraries shipped along the source code."))
4131 (defclass precompiled-system
(system)
4132 ((build-pathname :initarg
:fasb
:initarg
:fasl
))
4133 (:documentation
"Class For a system that is delivered as a precompiled fasl"))
4135 (defclass prebuilt-system
(system)
4136 ((build-pathname :initarg
:static-library
:initarg
:lib
4137 :accessor prebuilt-system-static-library
))
4138 (:documentation
"Class for a system delivered with a linkable static library (.a/.lib)")))
4144 ;;; This operation takes all components from one or more systems and
4145 ;;; creates a single output file, which may be
4146 ;;; a FASL, a statically linked library, a shared library, etc.
4147 ;;; The different targets are defined by specialization.
4149 (when-upgrading (:version
"3.2.0")
4150 ;; Cancel any previously defined method
4151 (defmethod initialize-instance :after
((instance bundle-op
) &rest initargs
&key
&allow-other-keys
)
4152 (declare (ignore initargs
))))
4154 (with-upgradability ()
4155 (defgeneric trivial-system-p
(component))
4157 (defun user-system-p (s)
4158 (and (typep s
'system
)
4159 (not (builtin-system-p s
))
4160 (not (trivial-system-p s
)))))
4162 (eval-when (#-lispworks
:compile-toplevel
:load-toplevel
:execute
)
4163 (deftype user-system
() '(and system
(satisfies user-system-p
))))
4166 ;;; First we handle monolithic bundles.
4167 ;;; These are standalone systems which contain everything,
4168 ;;; including other ASDF systems required by the current one.
4169 ;;; A PROGRAM is always monolithic.
4171 ;;; MONOLITHIC SHARED LIBRARIES, PROGRAMS, FASL
4173 (with-upgradability ()
4174 (defun direct-dependency-files (o c
&key
(test 'identity
) (key 'output-files
) &allow-other-keys
)
4175 ;; This function selects output files from direct dependencies;
4176 ;; your component-depends-on method must gather the correct dependencies in the correct order.
4177 (while-collecting (collect)
4178 (map-direct-dependencies
4179 o c
#'(lambda (sub-o sub-c
)
4180 (loop :for f
:in
(funcall key sub-o sub-c
)
4181 :when
(funcall test f
) :do
(collect f
))))))
4183 (defun pathname-type-equal-function (type)
4184 #'(lambda (p) (equalp (pathname-type p
) type
)))
4186 (defmethod input-files ((o gather-operation
) (c system
))
4187 (unless (eq (bundle-type o
) :no-output-file
)
4188 (direct-dependency-files
4189 o c
:key
'output-files
4190 :test
(pathname-type-equal-function (bundle-pathname-type (gather-type o
))))))
4192 ;; Find the operation that produces a given bundle-type
4193 (defun select-bundle-operation (type &optional monolithic
)
4195 ((:dll
:shared-library
)
4196 (if monolithic
'monolithic-dll-op
'dll-op
))
4197 ((:lib
:static-library
)
4198 (if monolithic
'monolithic-lib-op
'lib-op
))
4200 (if monolithic
'monolithic-compile-bundle-op
'compile-bundle-op
))
4209 ;;; This is like ASDF's LOAD-OP, but using bundle fasl files.
4211 (with-upgradability ()
4212 (defmethod component-depends-on ((o load-bundle-op
) (c system
))
4213 `((,o
,@(component-sideway-dependencies c
))
4214 (,(if (user-system-p c
) 'compile-bundle-op
'load-op
) ,c
)
4215 ,@(call-next-method)))
4217 (defmethod input-files ((o load-bundle-op
) (c system
))
4218 (when (user-system-p c
)
4219 (output-files (find-operation o
'compile-bundle-op
) c
)))
4221 (defmethod perform ((o load-bundle-op
) (c system
))
4222 (when (input-files o c
)
4223 (perform-lisp-load-fasl o c
)))
4225 (defmethod mark-operation-done :after
((o load-bundle-op
) (c system
))
4226 (mark-operation-done (find-operation o
'load-op
) c
)))
4229 ;;; PRECOMPILED FILES
4231 ;;; This component can be used to distribute ASDF systems in precompiled form.
4232 ;;; Only useful when the dependencies have also been precompiled.
4234 (with-upgradability ()
4235 (defmethod trivial-system-p ((s system
))
4236 (every #'(lambda (c) (typep c
'compiled-file
)) (component-children s
)))
4238 (defmethod input-files ((o operation
) (c compiled-file
))
4239 (list (component-pathname c
)))
4240 (defmethod perform ((o load-op
) (c compiled-file
))
4241 (perform-lisp-load-fasl o c
))
4242 (defmethod perform ((o load-source-op
) (c compiled-file
))
4243 (perform (find-operation o
'load-op
) c
))
4244 (defmethod perform ((o operation
) (c compiled-file
))
4248 ;;; Pre-built systems
4250 (with-upgradability ()
4251 (defmethod trivial-system-p ((s prebuilt-system
))
4254 (defmethod perform ((o link-op
) (c prebuilt-system
))
4257 (defmethod perform ((o basic-compile-bundle-op
) (c prebuilt-system
))
4260 (defmethod perform ((o lib-op
) (c prebuilt-system
))
4263 (defmethod perform ((o dll-op
) (c prebuilt-system
))
4266 (defmethod component-depends-on ((o gather-operation
) (c prebuilt-system
))
4269 (defmethod output-files ((o lib-op
) (c prebuilt-system
))
4270 (values (list (prebuilt-system-static-library c
)) t
)))
4274 ;;; PREBUILT SYSTEM CREATOR
4276 (with-upgradability ()
4277 (defmethod output-files ((o deliver-asd-op
) (s system
))
4278 (list (make-pathname :name
(component-name s
) :type
"asd"
4279 :defaults
(component-pathname s
))))
4281 (defmethod perform ((o deliver-asd-op
) (s system
))
4282 (let* ((inputs (input-files o s
))
4283 (fasl (first inputs
))
4284 (library (second inputs
))
4285 (asd (first (output-files o s
)))
4286 (name (if (and fasl asd
) (pathname-name asd
) (return-from perform
)))
4287 (version (component-version s
))
4289 (if (operation-monolithic-p o
)
4290 ;; We want only dependencies, and we use basic-load-op rather than load-op so that
4291 ;; this will keep working on systems that load dependencies with load-bundle-op
4292 (remove-if-not 'builtin-system-p
4293 (required-components s
:component-type
'system
4294 :keep-operation
'basic-load-op
))
4295 (while-collecting (x) ;; resolve the sideway-dependencies of s
4296 (map-direct-dependencies
4299 (when (and (typep o
'load-op
) (typep c
'system
))
4301 (depends-on (mapcar 'coerce-name dependencies
)))
4302 (when (pathname-equal asd
(system-source-file s
))
4303 (cerror "overwrite the asd file"
4304 "~/asdf-action:format-action/ is going to overwrite the system definition file ~S ~
4305 which is probably not what you want; you probably need to tweak your output translations."
4307 (with-open-file (s asd
:direction
:output
:if-exists
:supersede
4308 :if-does-not-exist
:create
)
4309 (format s
";;; Prebuilt~:[~; monolithic~] ASDF definition for system ~A~%"
4310 (operation-monolithic-p o
) name
)
4311 (format s
";;; Built for ~A ~A on a ~A/~A ~A~%"
4312 (lisp-implementation-type)
4313 (lisp-implementation-version)
4317 (let ((*package
* (find-package :asdf-user
)))
4318 (pprint `(defsystem ,name
4319 :class prebuilt-system
4321 :depends-on
,depends-on
4322 :components
((:compiled-file
,(pathname-name fasl
)))
4323 ,@(when library
`(:lib
,(file-namestring library
))))
4327 #-
(or clasp ecl mkcl
)
4328 (defmethod perform ((o basic-compile-bundle-op
) (c system
))
4329 (let* ((input-files (input-files o c
))
4330 (fasl-files (remove (compile-file-type) input-files
:key
#'pathname-type
:test-not
#'equalp
))
4331 (non-fasl-files (remove (compile-file-type) input-files
:key
#'pathname-type
:test
#'equalp
))
4332 (output-files (output-files o c
))
4333 (output-file (first output-files
)))
4334 (assert (eq (not input-files
) (not output-files
)))
4336 (when non-fasl-files
4337 (error "On ~A, asdf/bundle can only bundle FASL files, but these were also produced: ~S"
4338 (implementation-type) non-fasl-files
))
4339 (when (or (prologue-code c
) (epilogue-code c
))
4340 (error "prologue-code and epilogue-code are not supported on ~A"
4341 (implementation-type)))
4342 (with-staging-pathname (output-file)
4343 (combine-fasls fasl-files output-file
)))))
4345 (defmethod input-files ((o load-op
) (s precompiled-system
))
4346 (bundle-output-files (find-operation o
'compile-bundle-op
) s
))
4348 (defmethod perform ((o load-op
) (s precompiled-system
))
4349 (perform-lisp-load-fasl o s
))
4351 (defmethod component-depends-on ((o load-bundle-op
) (s precompiled-system
))
4352 `((load-op ,s
) ,@(call-next-method))))
4355 (asdf:defsystem
:precompiled-asdf-utils
:class asdf
::precompiled-system
:fasl
(asdf:apply-output-translations
(asdf:system-relative-pathname
:asdf-utils
"asdf-utils.system.fasl")))
4356 (asdf:load-system
:precompiled-asdf-utils
)
4359 #+(or clasp ecl mkcl
)
4360 (with-upgradability ()
4361 (defun system-module-pathname (module)
4362 (let ((name (coerce-name module
)))
4366 #+clasp
(compile-file-pathname (make-pathname :name name
:defaults
"sys:") :output-type
:object
)
4367 #+ecl
(compile-file-pathname (make-pathname :name name
:defaults
"sys:") :type
:lib
)
4368 #+ecl
(compile-file-pathname (make-pathname :name
(strcat "lib" name
) :defaults
"sys:") :type
:lib
)
4369 #+ecl
(compile-file-pathname (make-pathname :name name
:defaults
"sys:") :type
:object
)
4370 #+mkcl
(make-pathname :name name
:type
(bundle-pathname-type :lib
) :defaults
#p
"sys:")
4371 #+mkcl
(make-pathname :name name
:type
(bundle-pathname-type :lib
) :defaults
#p
"sys:contrib;")))))
4373 (defun make-prebuilt-system (name &optional
(pathname (system-module-pathname name
)))
4374 "Creates a prebuilt-system if PATHNAME isn't NIL."
4376 (make-instance 'prebuilt-system
4377 :name
(coerce-name name
)
4378 :static-library
(resolve-symlinks* pathname
))))
4380 (defun linkable-system (x)
4381 (or (if-let (s (find-system x
))
4382 (and (output-files 'lib-op s
) s
))
4383 (if-let (p (system-module-pathname (coerce-name x
)))
4384 (make-prebuilt-system x p
))))
4386 (defmethod component-depends-on :around
((o image-op
) (c system
))
4387 (let* ((next (call-next-method))
4388 (deps (make-hash-table :test
'equal
))
4389 (linkable (loop* :for
(do . dcs
) :in next
:collect
4391 (loop :for dc
:in dcs
4392 :for dep
= (and dc
(resolve-dependency-spec c dc
))
4394 :do
(setf (gethash (coerce-name (component-system dep
)) deps
) t
)
4395 :collect
(or (and (typep dep
'system
) (linkable-system dep
)) dep
))))))
4397 ,@(unless (no-uiop c
)
4398 (list (linkable-system "cmp")
4399 (unless (or (and (gethash "uiop" deps
) (linkable-system "uiop"))
4400 (and (gethash "asdf" deps
) (linkable-system "asdf")))
4401 (or (linkable-system "uiop")
4402 (linkable-system "asdf")
4406 (defmethod perform ((o link-op
) (c system
))
4407 (let* ((object-files (input-files o c
))
4408 (output (output-files o c
))
4409 (bundle (first output
))
4410 (programp (typep o
'program-op
))
4411 (kind (bundle-type o
)))
4413 (apply 'create-image
4415 (when programp
(prefix-lisp-object-files c
))
4417 (when programp
(postfix-lisp-object-files c
)))
4419 :prologue-code
(when programp
(prologue-code c
))
4420 :epilogue-code
(when programp
(epilogue-code c
))
4421 :build-args
(when programp
(extra-build-args c
))
4422 :extra-object-files
(when programp
(extra-object-files c
))
4423 :no-uiop
(no-uiop c
)
4424 (when programp
`(:entry-point
,(component-entry-point c
))))))))
4425 ;;;; -------------------------------------------------------------------------
4426 ;;;; Concatenate-source
4428 (uiop/package
:define-package
:asdf
/concatenate-source
4429 (:recycle
:asdf
/concatenate-source
:asdf
)
4430 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
4431 :asdf
/component
:asdf
/operation
4433 :asdf
/action
:asdf
/lisp-action
:asdf
/plan
:asdf
/bundle
)
4435 #:concatenate-source-op
4436 #:load-concatenated-source-op
4437 #:compile-concatenated-source-op
4438 #:load-compiled-concatenated-source-op
4439 #:monolithic-concatenate-source-op
4440 #:monolithic-load-concatenated-source-op
4441 #:monolithic-compile-concatenated-source-op
4442 #:monolithic-load-compiled-concatenated-source-op
))
4443 (in-package :asdf
/concatenate-source
)
4446 ;;; Concatenate sources
4448 (with-upgradability ()
4449 ;; Base classes for both regular and monolithic concatenate-source operations
4450 (defclass basic-concatenate-source-op
(bundle-op)
4451 ((bundle-type :initform
"lisp" :allocation
:class
)))
4452 (defclass basic-load-concatenated-source-op
(basic-load-op selfward-operation
) ())
4453 (defclass basic-compile-concatenated-source-op
(basic-compile-op selfward-operation
) ())
4454 (defclass basic-load-compiled-concatenated-source-op
(basic-load-op selfward-operation
) ())
4456 ;; Regular concatenate-source operations
4457 (defclass concatenate-source-op
(basic-concatenate-source-op non-propagating-operation
) ()
4458 (:documentation
"Operation to concatenate all sources in a system into a single file"))
4459 (defclass load-concatenated-source-op
(basic-load-concatenated-source-op)
4460 ((selfward-operation :initform
'(prepare-op concatenate-source-op
) :allocation
:class
))
4461 (:documentation
"Operation to load the result of concatenate-source-op as source"))
4462 (defclass compile-concatenated-source-op
(basic-compile-concatenated-source-op)
4463 ((selfward-operation :initform
'(prepare-op concatenate-source-op
) :allocation
:class
))
4464 (:documentation
"Operation to compile the result of concatenate-source-op"))
4465 (defclass load-compiled-concatenated-source-op
(basic-load-compiled-concatenated-source-op)
4466 ((selfward-operation :initform
'(prepare-op compile-concatenated-source-op
) :allocation
:class
))
4467 (:documentation
"Operation to load the result of compile-concatenated-source-op"))
4469 (defclass monolithic-concatenate-source-op
4470 (basic-concatenate-source-op monolithic-bundle-op non-propagating-operation
) ()
4471 (:documentation
"Operation to concatenate all sources in a system and its dependencies
4472 into a single file"))
4473 (defclass monolithic-load-concatenated-source-op
(basic-load-concatenated-source-op)
4474 ((selfward-operation :initform
'monolithic-concatenate-source-op
:allocation
:class
))
4475 (:documentation
"Operation to load the result of monolithic-concatenate-source-op as source"))
4476 (defclass monolithic-compile-concatenated-source-op
(basic-compile-concatenated-source-op)
4477 ((selfward-operation :initform
'monolithic-concatenate-source-op
:allocation
:class
))
4478 (:documentation
"Operation to compile the result of monolithic-concatenate-source-op"))
4479 (defclass monolithic-load-compiled-concatenated-source-op
4480 (basic-load-compiled-concatenated-source-op)
4481 ((selfward-operation :initform
'monolithic-compile-concatenated-source-op
:allocation
:class
))
4482 (:documentation
"Operation to load the result of monolithic-compile-concatenated-source-op"))
4484 (defmethod input-files ((operation basic-concatenate-source-op
) (s system
))
4485 (loop :with encoding
= (or (component-encoding s
) *default-encoding
*)
4486 :with other-encodings
= '()
4487 :with around-compile
= (around-compile-hook s
)
4488 :with other-around-compile
= '()
4489 :for c
:in
(required-components ;; see note about similar call to required-components
4490 s
:goal-operation
'load-op
;; in bundle.lisp
4491 :keep-operation
'basic-compile-op
4492 :other-systems
(operation-monolithic-p operation
))
4494 (when (typep c
'cl-source-file
)
4495 (let ((e (component-encoding c
)))
4496 (unless (equal e encoding
)
4497 (let ((a (assoc e other-encodings
)))
4498 (if a
(push (component-find-path c
) (cdr a
))
4499 (push (list a
(component-find-path c
)) other-encodings
)))))
4500 (unless (equal around-compile
(around-compile-hook c
))
4501 (push (component-find-path c
) other-around-compile
))
4502 (input-files (make-operation 'compile-op
) c
)) :into inputs
4504 (when other-encodings
4505 (warn "~S uses encoding ~A but has sources that use these encodings:~{ ~A~}"
4507 (mapcar #'(lambda (x) (cons (car x
) (list (reverse (cdr x
)))))
4509 (when other-around-compile
4510 (warn "~S uses around-compile hook ~A but has sources that use these hooks: ~A"
4511 operation around-compile other-around-compile
))
4513 (defmethod output-files ((o basic-compile-concatenated-source-op
) (s system
))
4514 (lisp-compilation-output-files o s
))
4516 (defmethod perform ((o basic-concatenate-source-op
) (s system
))
4517 (let* ((ins (input-files o s
))
4518 (out (output-file o s
))
4519 (tmp (tmpize-pathname out
)))
4520 (concatenate-files ins tmp
)
4521 (rename-file-overwriting-target tmp out
)))
4522 (defmethod perform ((o basic-load-concatenated-source-op
) (s system
))
4523 (perform-lisp-load-source o s
))
4524 (defmethod perform ((o basic-compile-concatenated-source-op
) (s system
))
4525 (perform-lisp-compilation o s
))
4526 (defmethod perform ((o basic-load-compiled-concatenated-source-op
) (s system
))
4527 (perform-lisp-load-fasl o s
)))
4529 ;;;; -------------------------------------------------------------------------
4530 ;;;; Package systems in the style of quick-build or faslpath
4532 (uiop:define-package
:asdf
/package-inferred-system
4533 (:recycle
:asdf
/package-inferred-system
:asdf
/package-system
:asdf
)
4534 (:use
:uiop
/common-lisp
:uiop
4535 :asdf
/upgrade
:asdf
/session
4536 :asdf
/component
:asdf
/system
:asdf
/system-registry
:asdf
/lisp-action
4537 :asdf
/parse-defsystem
)
4539 #:package-inferred-system
#:sysdef-package-inferred-system-search
4540 #:package-system
;; backward compatibility only. To be removed.
4541 #:register-system-packages
4542 #:*defpackage-forms
* #:*package-inferred-systems
* #:package-inferred-system-missing-package-error
))
4543 (in-package :asdf
/package-inferred-system
)
4545 (with-upgradability ()
4546 ;; The names of the recognized defpackage forms.
4547 (defparameter *defpackage-forms
* '(defpackage define-package
))
4549 (defun initial-package-inferred-systems-table ()
4550 ;; Mark all existing packages are preloaded.
4551 (let ((h (make-hash-table :test
'equal
)))
4552 (dolist (p (list-all-packages))
4553 (dolist (n (package-names p
))
4554 (setf (gethash n h
) t
)))
4557 ;; Mapping from package names to systems that provide them.
4558 (defvar *package-inferred-systems
* (initial-package-inferred-systems-table))
4560 (defclass package-inferred-system
(system)
4562 (:documentation
"Class for primary systems for which secondary systems are automatically
4563 in the one-file, one-file, one-system style: system names are mapped to files under the primary
4564 system's system-source-directory, dependencies are inferred from the first defpackage form in
4567 ;; DEPRECATED. For backward compatibility only. To be removed in an upcoming release:
4568 (defclass package-system
(package-inferred-system) ())
4570 ;; Is a given form recognizable as a defpackage form?
4571 (defun defpackage-form-p (form)
4573 (member (car form
) *defpackage-forms
*)))
4575 ;; Find the first defpackage form in a stream, if any
4576 (defun stream-defpackage-form (stream)
4577 (loop :for form
= (read stream nil nil
) :while form
4578 :when
(defpackage-form-p form
) :return form
))
4580 (defun file-defpackage-form (file)
4581 "Return the first DEFPACKAGE form in FILE."
4582 (with-input-file (f file
)
4583 (stream-defpackage-form f
)))
4585 (define-condition package-inferred-system-missing-package-error
(system-definition-error)
4586 ((system :initarg
:system
:reader error-system
)
4587 (pathname :initarg
:pathname
:reader error-pathname
))
4588 (:report
(lambda (c s
)
4589 (format s
(compatfmt "~@<No package form found while ~
4590 trying to define package-inferred-system ~A from file ~A~>")
4591 (error-system c
) (error-pathname c
)))))
4593 (defun package-dependencies (defpackage-form)
4594 "Return a list of packages depended on by the package
4595 defined in DEFPACKAGE-FORM. A package is depended upon if
4596 the DEFPACKAGE-FORM uses it or imports a symbol from it."
4597 (assert (defpackage-form-p defpackage-form
))
4599 (while-collecting (dep)
4600 (loop* :for
(option . arguments
) :in
(cddr defpackage-form
) :do
4602 ((:use
:mix
:reexport
:use-reexport
:mix-reexport
)
4603 (dolist (p arguments
) (dep (string p
))))
4604 ((:import-from
:shadowing-import-from
)
4605 (dep (string (first arguments
))))
4606 ((:nicknames
:documentation
:shadow
:export
:intern
:unintern
:recycle
)))))
4607 :from-end t
:test
'equal
))
4609 (defun package-designator-name (package)
4610 "Normalize a package designator to a string"
4612 (package (package-name package
))
4614 (symbol (string package
))))
4616 (defun register-system-packages (system packages
)
4617 "Register SYSTEM as providing PACKAGES."
4618 (let ((name (or (eq system t
) (coerce-name system
))))
4619 (dolist (p (ensure-list packages
))
4620 (setf (gethash (package-designator-name p
) *package-inferred-systems
*) name
))))
4622 (defun package-name-system (package-name)
4623 "Return the name of the SYSTEM providing PACKAGE-NAME, if such exists,
4624 otherwise return a default system name computed from PACKAGE-NAME."
4625 (check-type package-name string
)
4626 (or (gethash package-name
*package-inferred-systems
*)
4627 (string-downcase package-name
)))
4629 ;; Given a file in package-inferred-system style, find its dependencies
4630 (defun package-inferred-system-file-dependencies (file &optional system
)
4631 (if-let (defpackage-form (file-defpackage-form file
))
4632 (remove t
(mapcar 'package-name-system
(package-dependencies defpackage-form
)))
4633 (error 'package-inferred-system-missing-package-error
:system system
:pathname file
)))
4635 ;; Given package-inferred-system object, check whether its specification matches
4636 ;; the provided parameters
4637 (defun same-package-inferred-system-p (system name directory subpath around-compile dependencies
)
4638 (and (eq (type-of system
) 'package-inferred-system
)
4639 (equal (component-name system
) name
)
4640 (pathname-equal directory
(component-pathname system
))
4641 (equal dependencies
(component-sideway-dependencies system
))
4642 (equal around-compile
(around-compile-hook system
))
4643 (let ((children (component-children system
)))
4644 (and (length=n-p children
1)
4645 (let ((child (first children
)))
4646 (and (eq (type-of child
) 'cl-source-file
)
4647 (equal (component-name child
) "lisp")
4648 (and (slot-boundp child
'relative-pathname
)
4649 (equal (slot-value child
'relative-pathname
) subpath
))))))))
4651 ;; sysdef search function to push into *system-definition-search-functions*
4652 (defun sysdef-package-inferred-system-search (system)
4653 (let ((primary (primary-system-name system
)))
4654 (unless (equal primary system
)
4655 (let ((top (find-system primary nil
)))
4656 (when (typep top
'package-inferred-system
)
4657 (if-let (dir (component-pathname top
))
4658 (let* ((sub (subseq system
(1+ (length primary
))))
4659 (f (probe-file* (subpathname dir sub
:type
"lisp")
4660 :truename
*resolve-symlinks
*)))
4661 (when (file-pathname-p f
)
4662 (let ((dependencies (package-inferred-system-file-dependencies f system
))
4663 (previous (registered-system system
))
4664 (around-compile (around-compile-hook top
)))
4665 (if (same-package-inferred-system-p previous system dir sub around-compile dependencies
)
4667 (eval `(defsystem ,system
4668 :class package-inferred-system
4671 :depends-on
,dependencies
4672 :around-compile
,around-compile
4673 :components
((cl-source-file "lisp" :pathname
,sub
)))))))))))))))
4675 (with-upgradability ()
4676 (pushnew 'sysdef-package-inferred-system-search
*system-definition-search-functions
*)
4677 (setf *system-definition-search-functions
*
4678 (remove (find-symbol* :sysdef-package-system-search
:asdf
/package-system nil
)
4679 *system-definition-search-functions
*)))
4680 ;;;; ---------------------------------------------------------------------------
4681 ;;;; asdf-output-translations
4683 (uiop/package
:define-package
:asdf
/output-translations
4684 (:recycle
:asdf
/output-translations
:asdf
)
4685 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
)
4687 #:*output-translations
* #:*output-translations-parameter
*
4688 #:invalid-output-translation
4689 #:output-translations
#:output-translations-initialized-p
4690 #:initialize-output-translations
#:clear-output-translations
4691 #:disable-output-translations
#:ensure-output-translations
4692 #:apply-output-translations
4693 #:validate-output-translations-directive
#:validate-output-translations-form
4694 #:validate-output-translations-file
#:validate-output-translations-directory
4695 #:parse-output-translations-string
#:wrapping-output-translations
4696 #:user-output-translations-pathname
#:system-output-translations-pathname
4697 #:user-output-translations-directory-pathname
#:system-output-translations-directory-pathname
4698 #:environment-output-translations
#:process-output-translations
4699 #:compute-output-translations
4700 #+abcl
#:translate-jar-pathname
4702 (in-package :asdf
/output-translations
)
4704 ;; (setf output-translations) between 2.27 and 3.0.3 was using a defsetf macro
4705 ;; for the sake of obsolete versions of GCL 2.6. Make sure it doesn't come to haunt us.
4706 (when-upgrading (:version
"3.1.2") (fmakunbound '(setf output-translations
)))
4708 (with-upgradability ()
4709 (define-condition invalid-output-translation
(invalid-configuration warning
)
4710 ((format :initform
(compatfmt "~@<Invalid asdf output-translation ~S~@[ in ~S~]~@{ ~@?~}~@:>"))))
4712 (defvar *output-translations
* ()
4713 "Either NIL (for uninitialized), or a list of one element,
4714 said element itself being a sorted list of mappings.
4715 Each mapping is a pair of a source pathname and destination pathname,
4716 and the order is by decreasing length of namestring of the source pathname.")
4718 (defun output-translations ()
4719 "Return the configured output-translations, if any"
4720 (car *output-translations
*))
4722 ;; Set the output-translations, by sorting the provided new-value.
4723 (defun set-output-translations (new-value)
4724 (setf *output-translations
*
4726 (stable-sort (copy-list new-value
) #'>
4732 (normalize-pathname-directory-component
4733 (pathname-directory (car x
)))))
4734 (if (listp directory
) (length directory
) 0))))))))
4736 (defun (setf output-translations
) (new-value) (set-output-translations new-value
))
4738 (defun output-translations-initialized-p ()
4739 "Have the output-translations been initialized yet?"
4740 (and *output-translations
* t
))
4742 (defun clear-output-translations ()
4743 "Undoes any initialization of the output translations."
4744 (setf *output-translations
* '())
4746 (register-clear-configuration-hook 'clear-output-translations
)
4749 ;;; Validation of the configuration directives...
4751 (defun validate-output-translations-directive (directive)
4752 (or (member directive
'(:enable-user-cache
:disable-cache nil
))
4753 (and (consp directive
)
4754 (or (and (length=n-p directive
2)
4755 (or (and (eq (first directive
) :include
)
4756 (typep (second directive
) '(or string pathname null
)))
4757 (and (location-designator-p (first directive
))
4758 (or (location-designator-p (second directive
))
4759 (location-function-p (second directive
))))))
4760 (and (length=n-p directive
1)
4761 (location-designator-p (first directive
)))))))
4763 (defun validate-output-translations-form (form &key location
)
4764 (validate-configuration-form
4766 :output-translations
4767 'validate-output-translations-directive
4768 :location location
:invalid-form-reporter
'invalid-output-translation
))
4770 (defun validate-output-translations-file (file)
4771 (validate-configuration-file
4772 file
'validate-output-translations-form
:description
"output translations"))
4774 (defun validate-output-translations-directory (directory)
4775 (validate-configuration-directory
4776 directory
:output-translations
'validate-output-translations-directive
4777 :invalid-form-reporter
'invalid-output-translation
))
4780 ;;; Parse the ASDF_OUTPUT_TRANSLATIONS environment variable and/or some file contents
4781 (defun parse-output-translations-string (string &key location
)
4783 ((or (null string
) (equal string
""))
4784 '(:output-translations
:inherit-configuration
))
4785 ((not (stringp string
))
4786 (error (compatfmt "~@<Environment string isn't: ~3i~_~S~@:>") string
))
4787 ((eql (char string
0) #\")
4788 (parse-output-translations-string (read-from-string string
) :location location
))
4789 ((eql (char string
0) #\
()
4790 (validate-output-translations-form (read-from-string string
) :location location
))
4794 :with directives
= ()
4796 :with end
= (length string
)
4798 :with separator
= (inter-directory-separator)
4799 :for i
= (or (position separator string
:start start
) end
) :do
4800 (let ((s (subseq string start i
)))
4803 (push (list source
(if (equal "" s
) nil s
)) directives
)
4807 (error (compatfmt "~@<Only one inherited configuration allowed: ~3i~_~S~@:>")
4810 (push :inherit-configuration directives
))
4816 (error (compatfmt "~@<Uneven number of components in source to destination mapping: ~3i~_~S~@:>")
4819 (push :ignore-inherited-configuration directives
))
4820 (return `(:output-translations
,@(nreverse directives
)))))))))
4823 ;; The default sources of configuration for output-translations
4824 (defparameter* *default-output-translations
*
4825 '(environment-output-translations
4826 user-output-translations-pathname
4827 user-output-translations-directory-pathname
4828 system-output-translations-pathname
4829 system-output-translations-directory-pathname
))
4831 ;; Compulsory implementation-dependent wrapping for the translations:
4832 ;; handle implementation-provided systems.
4833 (defun wrapping-output-translations ()
4834 `(:output-translations
4835 ;; Some implementations have precompiled ASDF systems,
4836 ;; so we must disable translations for implementation paths.
4837 #+(or clasp
#|clozure|
# ecl mkcl sbcl
)
4838 ,@(let ((h (resolve-symlinks* (lisp-implementation-directory))))
4839 (when h
`(((,h
,*wild-path
*) ()))))
4840 #+mkcl
(,(translate-logical-pathname "CONTRIB:") ())
4841 ;; All-import, here is where we want user stuff to be:
4842 :inherit-configuration
4843 ;; These are for convenience, and can be overridden by the user:
4844 #+abcl
(#p
"/___jar___file___root___/**/*.*" (:user-cache
#p
"**/*.*"))
4845 #+abcl
(#p
"jar:file:/**/*.jar!/**/*.*" (:function translate-jar-pathname
))
4846 ;; We enable the user cache by default, and here is the place we do:
4847 :enable-user-cache
))
4849 ;; Relative pathnames of output-translations configuration to XDG configuration directory
4850 (defparameter *output-translations-file
* (parse-unix-namestring "common-lisp/asdf-output-translations.conf"))
4851 (defparameter *output-translations-directory
* (parse-unix-namestring "common-lisp/asdf-output-translations.conf.d/"))
4853 ;; Locating various configuration pathnames, depending on input or output intent.
4854 (defun user-output-translations-pathname (&key
(direction :input
))
4855 (xdg-config-pathname *output-translations-file
* direction
))
4856 (defun system-output-translations-pathname (&key
(direction :input
))
4857 (find-preferred-file (system-config-pathnames *output-translations-file
*)
4858 :direction direction
))
4859 (defun user-output-translations-directory-pathname (&key
(direction :input
))
4860 (xdg-config-pathname *output-translations-directory
* direction
))
4861 (defun system-output-translations-directory-pathname (&key
(direction :input
))
4862 (find-preferred-file (system-config-pathnames *output-translations-directory
*)
4863 :direction direction
))
4864 (defun environment-output-translations ()
4865 (getenv "ASDF_OUTPUT_TRANSLATIONS"))
4868 ;;; Processing the configuration.
4870 (defgeneric process-output-translations
(spec &key inherit collect
))
4872 (defun inherit-output-translations (inherit &key collect
)
4874 (process-output-translations (first inherit
) :collect collect
:inherit
(rest inherit
))))
4876 (defun* (process-output-translations-directive) (directive &key inherit collect
)
4877 (if (atom directive
)
4879 ((:enable-user-cache
)
4880 (process-output-translations-directive '(t :user-cache
) :collect collect
))
4882 (process-output-translations-directive '(t t
) :collect collect
))
4883 ((:inherit-configuration
)
4884 (inherit-output-translations inherit
:collect collect
))
4885 ((:ignore-inherited-configuration
:ignore-invalid-entries nil
)
4887 (let ((src (first directive
))
4888 (dst (second directive
)))
4889 (if (eq src
:include
)
4891 (process-output-translations (pathname dst
) :inherit nil
:collect collect
))
4893 (let ((trusrc (or (eql src t
)
4894 (let ((loc (resolve-location src
:ensure-directory t
:wilden t
)))
4895 (if (absolute-pathname-p loc
) (resolve-symlinks* loc
) loc
)))))
4897 ((location-function-p dst
)
4899 (list trusrc
(ensure-function (second dst
)))))
4900 ((typep dst
'boolean
)
4901 (funcall collect
(list trusrc t
)))
4903 (let* ((trudst (resolve-location dst
:ensure-directory t
:wilden t
)))
4904 (funcall collect
(list trudst t
))
4905 (funcall collect
(list trusrc trudst
)))))))))))
4907 (defmethod process-output-translations ((x symbol
) &key
4908 (inherit *default-output-translations
*)
4910 (process-output-translations (funcall x
) :inherit inherit
:collect collect
))
4911 (defmethod process-output-translations ((pathname pathname
) &key inherit collect
)
4913 ((directory-pathname-p pathname
)
4914 (process-output-translations (validate-output-translations-directory pathname
)
4915 :inherit inherit
:collect collect
))
4916 ((probe-file* pathname
:truename
*resolve-symlinks
*)
4917 (process-output-translations (validate-output-translations-file pathname
)
4918 :inherit inherit
:collect collect
))
4920 (inherit-output-translations inherit
:collect collect
))))
4921 (defmethod process-output-translations ((string string
) &key inherit collect
)
4922 (process-output-translations (parse-output-translations-string string
)
4923 :inherit inherit
:collect collect
))
4924 (defmethod process-output-translations ((x null
) &key inherit collect
)
4925 (inherit-output-translations inherit
:collect collect
))
4926 (defmethod process-output-translations ((form cons
) &key inherit collect
)
4927 (dolist (directive (cdr (validate-output-translations-form form
)))
4928 (process-output-translations-directive directive
:inherit inherit
:collect collect
)))
4931 ;;; Top-level entry-points to configure output-translations
4933 (defun compute-output-translations (&optional parameter
)
4934 "read the configuration, return it"
4936 (while-collecting (c)
4937 (inherit-output-translations
4938 `(wrapping-output-translations ,parameter
,@*default-output-translations
*) :collect
#'c
))
4939 :test
'equal
:from-end t
))
4941 ;; Saving the user-provided parameter to output-translations, if any,
4942 ;; so we can recompute the translations after code upgrade.
4943 (defvar *output-translations-parameter
* nil
)
4945 ;; Main entry-point for users.
4946 (defun initialize-output-translations (&optional
(parameter *output-translations-parameter
*))
4947 "read the configuration, initialize the internal configuration variable,
4948 return the configuration"
4949 (setf *output-translations-parameter
* parameter
4950 (output-translations) (compute-output-translations parameter
)))
4952 (defun disable-output-translations ()
4953 "Initialize output translations in a way that maps every file to itself,
4954 effectively disabling the output translation facility."
4955 (initialize-output-translations
4956 '(:output-translations
:disable-cache
:ignore-inherited-configuration
)))
4958 ;; checks an initial variable to see whether the state is initialized
4959 ;; or cleared. In the former case, return current configuration; in
4960 ;; the latter, initialize. ASDF will call this function at the start
4961 ;; of (asdf:find-system).
4962 (defun ensure-output-translations ()
4963 (if (output-translations-initialized-p)
4964 (output-translations)
4965 (initialize-output-translations)))
4968 ;; Top-level entry-point to _use_ output-translations
4969 (defun* (apply-output-translations) (path)
4973 ((or pathname string
)
4974 (ensure-output-translations)
4975 (loop* :with p
= (resolve-symlinks* path
)
4976 :for
(source destination
) :in
(car *output-translations
*)
4977 :for root
= (when (or (eq source t
)
4978 (and (pathnamep source
)
4979 (not (absolute-pathname-p source
))))
4981 :for absolute-source
= (cond
4982 ((eq source t
) (wilden root
))
4983 (root (merge-pathnames* source root
))
4985 :when
(or (eq source t
) (pathname-match-p p absolute-source
))
4986 :return
(translate-pathname* p absolute-source destination root source
)
4987 :finally
(return p
)))))
4990 ;; Hook into uiop's output-translation mechanism
4992 (setf *output-translation-function
* 'apply-output-translations
)
4995 ;;; Implementation-dependent hacks
4996 #+abcl
;; ABCL: make it possible to use systems provided in the ABCL jar.
4997 (defun translate-jar-pathname (source wildcard
)
4998 (declare (ignore wildcard
))
4999 (flet ((normalize-device (pathname)
5000 (if (find :windows
*features
*)
5002 (make-pathname :defaults pathname
:device
:unspecific
))))
5004 (pathname (first (pathname-device source
))))
5005 (target-root-directory-namestring
5006 (format nil
"/___jar___file___root___/~@[~A/~]"
5007 (and (find :windows
*features
*)
5008 (pathname-device jar
))))
5010 (relativize-pathname-directory source
))
5012 (relativize-pathname-directory (ensure-directory-pathname jar
)))
5013 (target-root-directory
5015 (pathname-directory-pathname
5016 (parse-namestring target-root-directory-namestring
))))
5018 (merge-pathnames* relative-jar target-root-directory
))
5020 (merge-pathnames* relative-source target-root
)))
5021 (normalize-device (apply-output-translations target
))))))
5023 ;;;; -----------------------------------------------------------------
5024 ;;;; Source Registry Configuration, by Francois-Rene Rideau
5025 ;;;; See the Manual and https://bugs.launchpad.net/asdf/+bug/485918
5027 (uiop/package
:define-package
:asdf
/source-registry
5028 ;; NB: asdf/find-system allows upgrade from <=3.2.1 that have initialize-source-registry there
5029 (:recycle
:asdf
/source-registry
:asdf
/find-system
:asdf
)
5030 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/system
:asdf
/system-registry
)
5032 #:*source-registry-parameter
* #:*default-source-registries
*
5033 #:invalid-source-registry
5034 #:source-registry-initialized-p
5035 #:initialize-source-registry
#:clear-source-registry
#:*source-registry
*
5036 #:ensure-source-registry
#:*source-registry-parameter
*
5037 #:*default-source-registry-exclusions
* #:*source-registry-exclusions
*
5038 #:*wild-asd
* #:directory-asd-files
#:register-asd-directory
5039 #:*recurse-beyond-asds
* #:collect-asds-in-directory
#:collect-sub
*directories-asd-files
5040 #:validate-source-registry-directive
#:validate-source-registry-form
5041 #:validate-source-registry-file
#:validate-source-registry-directory
5042 #:parse-source-registry-string
#:wrapping-source-registry
5043 #:default-user-source-registry
#:default-system-source-registry
5044 #:user-source-registry
#:system-source-registry
5045 #:user-source-registry-directory
#:system-source-registry-directory
5046 #:environment-source-registry
#:process-source-registry
#:inherit-source-registry
5047 #:compute-source-registry
#:flatten-source-registry
5048 #:sysdef-source-registry-search
))
5049 (in-package :asdf
/source-registry
)
5051 (with-upgradability ()
5052 (define-condition invalid-source-registry
(invalid-configuration warning
)
5053 ((format :initform
(compatfmt "~@<Invalid source registry ~S~@[ in ~S~]~@{ ~@?~}~@:>"))))
5055 ;; Default list of directories under which the source-registry tree search won't recurse
5056 (defvar *default-source-registry-exclusions
*
5057 '(;;-- Using ack 1.2 exclusions
5059 ;; "~.dep" "~.dot" "~.nib" "~.plst" ; we don't support ack wildcards
5060 ".git" ".hg" ".pc" ".svn" "CVS" "RCS" "SCCS" "_darcs"
5061 "_sgbak" "autom4te.cache" "cover_db" "_build"
5062 ;;-- debian often builds stuff under the debian directory... BAD.
5065 ;; Actual list of directories under which the source-registry tree search won't recurse
5066 (defvar *source-registry-exclusions
* *default-source-registry-exclusions
*)
5068 ;; The state of the source-registry after search in configured locations
5069 (defvar *source-registry
* nil
5070 "Either NIL (for uninitialized), or an equal hash-table, mapping
5071 system names to pathnames of .asd files")
5073 ;; Saving the user-provided parameter to the source-registry, if any,
5074 ;; so we can recompute the source-registry after code upgrade.
5075 (defvar *source-registry-parameter
* nil
)
5077 (defun source-registry-initialized-p ()
5078 (typep *source-registry
* 'hash-table
))
5080 (defun clear-source-registry ()
5081 "Undoes any initialization of the source registry."
5082 (setf *source-registry
* nil
)
5084 (register-clear-configuration-hook 'clear-source-registry
)
5086 (defparameter *wild-asd
*
5087 (make-pathname :directory nil
:name
*wild
* :type
"asd" :version
:newest
))
5089 (defun directory-asd-files (directory)
5090 (directory-files directory
*wild-asd
*))
5092 (defun collect-asds-in-directory (directory collect
)
5093 (let ((asds (directory-asd-files directory
)))
5094 (map () collect asds
)
5097 (defvar *recurse-beyond-asds
* t
5098 "Should :tree entries of the source-registry recurse in subdirectories
5099 after having found a .asd file? True by default.")
5101 ;; When walking down a filesystem tree, if in a directory there is a .cl-source-registry.cache,
5102 ;; read its contents instead of further recursively querying the filesystem.
5103 (defun process-source-registry-cache (directory collect
)
5104 (let ((cache (ignore-errors
5105 (safe-read-file-form (subpathname directory
".cl-source-registry.cache")))))
5106 (when (and (listp cache
) (eq :source-registry-cache
(first cache
)))
5107 (loop :for s
:in
(rest cache
) :do
(funcall collect
(subpathname directory s
)))
5110 (defun collect-sub*directories-asd-files
5111 (directory &key
(exclude *default-source-registry-exclusions
*) collect
5112 (recurse-beyond-asds *recurse-beyond-asds
*) ignore-cache
)
5113 (let ((visited (make-hash-table :test
'equalp
)))
5114 (flet ((collectp (dir)
5115 (unless (and (not ignore-cache
) (process-source-registry-cache directory collect
))
5116 (let ((asds (collect-asds-in-directory dir collect
)))
5117 (or recurse-beyond-asds
(not asds
)))))
5118 (recursep (x) ; x will be a directory pathname
5120 (not (member (car (last (pathname-directory x
))) exclude
:test
#'equal
))
5121 (flet ((pathname-key (x)
5122 (namestring (truename* x
))))
5123 (let ((visitedp (gethash (pathname-key x
) visited
)))
5125 (setf (gethash (pathname-key x
) visited
) t
)))))))
5126 (collect-sub*directories directory
#'collectp
#'recursep
(constantly nil
)))))
5129 ;;; Validate the configuration forms
5131 (defun validate-source-registry-directive (directive)
5132 (or (member directive
'(:default-registry
))
5133 (and (consp directive
)
5134 (let ((rest (rest directive
)))
5135 (case (first directive
)
5136 ((:include
:directory
:tree
)
5137 (and (length=n-p rest
1)
5138 (location-designator-p (first rest
))))
5139 ((:exclude
:also-exclude
)
5140 (every #'stringp rest
))
5141 ((:default-registry
)
5144 (defun validate-source-registry-form (form &key location
)
5145 (validate-configuration-form
5146 form
:source-registry
'validate-source-registry-directive
5147 :location location
:invalid-form-reporter
'invalid-source-registry
))
5149 (defun validate-source-registry-file (file)
5150 (validate-configuration-file
5151 file
'validate-source-registry-form
:description
"a source registry"))
5153 (defun validate-source-registry-directory (directory)
5154 (validate-configuration-directory
5155 directory
:source-registry
'validate-source-registry-directive
5156 :invalid-form-reporter
'invalid-source-registry
))
5159 ;;; Parse the configuration string
5161 (defun parse-source-registry-string (string &key location
)
5163 ((or (null string
) (equal string
""))
5164 '(:source-registry
:inherit-configuration
))
5165 ((not (stringp string
))
5166 (error (compatfmt "~@<Environment string isn't: ~3i~_~S~@:>") string
))
5167 ((find (char string
0) "\"(")
5168 (validate-source-registry-form (read-from-string string
) :location location
))
5172 :with directives
= ()
5174 :with end
= (length string
)
5175 :with separator
= (inter-directory-separator)
5176 :for pos
= (position separator string
:start start
) :do
5177 (let ((s (subseq string start
(or pos end
))))
5179 (unless (absolute-pathname-p dir
)
5180 (error (compatfmt "~@<source-registry string must specify absolute pathnames: ~3i~_~S~@:>") string
))
5183 ((equal "" s
) ; empty element: inherit
5185 (error (compatfmt "~@<Only one inherited configuration allowed: ~3i~_~S~@:>")
5188 (push ':inherit-configuration directives
))
5189 ((string-suffix-p s
"//") ;; TODO: allow for doubling of separator even outside Unix?
5190 (push `(:tree
,(check (subseq s
0 (- (length s
) 2)))) directives
))
5192 (push `(:directory
,(check s
)) directives
))))
5195 (setf start
(1+ pos
)))
5198 (push '(:ignore-inherited-configuration
) directives
))
5199 (return `(:source-registry
,@(nreverse directives
))))))))))
5201 (defun register-asd-directory (directory &key recurse exclude collect
)
5203 (collect-asds-in-directory directory collect
)
5204 (collect-sub*directories-asd-files
5205 directory
:exclude exclude
:collect collect
)))
5207 (defparameter* *default-source-registries
*
5208 '(environment-source-registry
5209 user-source-registry
5210 user-source-registry-directory
5211 default-user-source-registry
5212 system-source-registry
5213 system-source-registry-directory
5214 default-system-source-registry
)
5215 "List of default source registries" "3.1.0.102")
5217 (defparameter *source-registry-file
* (parse-unix-namestring "common-lisp/source-registry.conf"))
5218 (defparameter *source-registry-directory
* (parse-unix-namestring "common-lisp/source-registry.conf.d/"))
5220 (defun wrapping-source-registry ()
5222 #+(or clasp ecl sbcl
) (:tree
,(resolve-symlinks* (lisp-implementation-directory)))
5223 :inherit-configuration
5224 #+mkcl
(:tree
,(translate-logical-pathname "SYS:"))
5225 #+cmucl
(:tree
#p
"modules:")
5226 #+scl
(:tree
#p
"file://modules/")))
5227 (defun default-user-source-registry ()
5229 (:tree
(:home
"common-lisp/"))
5230 #+sbcl
(:directory
(:home
".sbcl/systems/"))
5231 (:directory
,(xdg-data-home "common-lisp/systems/"))
5232 (:tree
,(xdg-data-home "common-lisp/source/"))
5233 :inherit-configuration
))
5234 (defun default-system-source-registry ()
5236 ,@(loop :for dir
:in
(xdg-data-dirs "common-lisp/")
5237 :collect
`(:directory
(,dir
"systems/"))
5238 :collect
`(:tree
(,dir
"source/")))
5239 :inherit-configuration
))
5240 (defun user-source-registry (&key
(direction :input
))
5241 (xdg-config-pathname *source-registry-file
* direction
))
5242 (defun system-source-registry (&key
(direction :input
))
5243 (find-preferred-file (system-config-pathnames *source-registry-file
*)
5244 :direction direction
))
5245 (defun user-source-registry-directory (&key
(direction :input
))
5246 (xdg-config-pathname *source-registry-directory
* direction
))
5247 (defun system-source-registry-directory (&key
(direction :input
))
5248 (find-preferred-file (system-config-pathnames *source-registry-directory
*)
5249 :direction direction
))
5250 (defun environment-source-registry ()
5251 (getenv "CL_SOURCE_REGISTRY"))
5254 ;;; Process the source-registry configuration
5256 (defgeneric process-source-registry
(spec &key inherit register
))
5258 (defun* (inherit-source-registry) (inherit &key register
)
5260 (process-source-registry (first inherit
) :register register
:inherit
(rest inherit
))))
5262 (defun* (process-source-registry-directive) (directive &key inherit register
)
5263 (destructuring-bind (kw &rest rest
) (if (consp directive
) directive
(list directive
))
5266 (destructuring-bind (pathname) rest
5267 (process-source-registry (resolve-location pathname
) :inherit nil
:register register
)))
5269 (destructuring-bind (pathname) rest
5271 (funcall register
(resolve-location pathname
:ensure-directory t
)))))
5273 (destructuring-bind (pathname) rest
5275 (funcall register
(resolve-location pathname
:ensure-directory t
)
5276 :recurse t
:exclude
*source-registry-exclusions
*))))
5278 (setf *source-registry-exclusions
* rest
))
5280 (appendf *source-registry-exclusions
* rest
))
5281 ((:default-registry
)
5282 (inherit-source-registry
5283 '(default-user-source-registry default-system-source-registry
) :register register
))
5284 ((:inherit-configuration
)
5285 (inherit-source-registry inherit
:register register
))
5286 ((:ignore-inherited-configuration
)
5290 (defmethod process-source-registry ((x symbol
) &key inherit register
)
5291 (process-source-registry (funcall x
) :inherit inherit
:register register
))
5292 (defmethod process-source-registry ((pathname pathname
) &key inherit register
)
5294 ((directory-pathname-p pathname
)
5295 (let ((*here-directory
* (resolve-symlinks* pathname
)))
5296 (process-source-registry (validate-source-registry-directory pathname
)
5297 :inherit inherit
:register register
)))
5298 ((probe-file* pathname
:truename
*resolve-symlinks
*)
5299 (let ((*here-directory
* (pathname-directory-pathname pathname
)))
5300 (process-source-registry (validate-source-registry-file pathname
)
5301 :inherit inherit
:register register
)))
5303 (inherit-source-registry inherit
:register register
))))
5304 (defmethod process-source-registry ((string string
) &key inherit register
)
5305 (process-source-registry (parse-source-registry-string string
)
5306 :inherit inherit
:register register
))
5307 (defmethod process-source-registry ((x null
) &key inherit register
)
5308 (inherit-source-registry inherit
:register register
))
5309 (defmethod process-source-registry ((form cons
) &key inherit register
)
5310 (let ((*source-registry-exclusions
* *default-source-registry-exclusions
*))
5311 (dolist (directive (cdr (validate-source-registry-form form
)))
5312 (process-source-registry-directive directive
:inherit inherit
:register register
))))
5315 ;; Flatten the user-provided configuration into an ordered list of directories and trees
5316 (defun flatten-source-registry (&optional
(parameter *source-registry-parameter
*))
5318 (while-collecting (collect)
5319 (with-pathname-defaults () ;; be location-independent
5320 (inherit-source-registry
5321 `(wrapping-source-registry
5323 ,@*default-source-registries
*)
5324 :register
#'(lambda (directory &key recurse exclude
)
5325 (collect (list directory
:recurse recurse
:exclude exclude
))))))
5326 :test
'equal
:from-end t
))
5328 ;; MAYBE: move this utility function to uiop/pathname and export it?
5329 (defun pathname-directory-depth (p)
5330 (length (normalize-pathname-directory-component (pathname-directory p
))))
5332 (defun preferred-source-path-p (x y
)
5333 "Return T iff X is to be preferred over Y as a source path"
5334 (let ((lx (pathname-directory-depth x
))
5335 (ly (pathname-directory-depth y
)))
5338 (string< (namestring x
)
5341 ;; Will read the configuration and initialize all internal variables.
5342 (defun compute-source-registry (&optional
(parameter *source-registry-parameter
*)
5343 (registry *source-registry
*))
5344 (dolist (entry (flatten-source-registry parameter
))
5345 (destructuring-bind (directory &key recurse exclude
) entry
5346 (let* ((h (make-hash-table :test
'equal
))) ; table to detect duplicates
5347 (register-asd-directory
5348 directory
:recurse recurse
:exclude exclude
:collect
5350 (let* ((name (pathname-name asd
))
5351 (name (if (typep asd
'logical-pathname
)
5352 ;; logical pathnames are upper-case,
5353 ;; at least in the CLHS and on SBCL,
5354 ;; yet (coerce-name :foo) is lower-case.
5355 ;; won't work well with (load-system "Foo")
5356 ;; instead of (load-system 'foo)
5357 (string-downcase name
)
5359 (unless (gethash name registry
) ; already shadowed by something else
5360 (if-let (old (gethash name h
))
5361 ;; If the name appears multiple times,
5362 ;; prefer the one with the shallowest directory,
5363 ;; or if they have same depth, compare unix-namestring with string<
5364 (multiple-value-bind (better worse
)
5365 (if (preferred-source-path-p asd old
)
5366 (progn (setf (gethash name h
) asd
) (values asd old
))
5369 (warn (compatfmt "~@<In source-registry entry ~A~@[/~*~] ~
5370 found several entries for ~A - picking ~S over ~S~:>")
5371 directory recurse name better worse
)))
5372 (setf (gethash name h
) asd
))))))
5373 (maphash #'(lambda (k v
) (setf (gethash k registry
) v
)) h
))))
5376 (defun initialize-source-registry (&optional
(parameter *source-registry-parameter
*))
5377 ;; Record the parameter used to configure the registry
5378 (setf *source-registry-parameter
* parameter
)
5379 ;; Clear the previous registry database:
5380 (setf *source-registry
* (make-hash-table :test
'equal
))
5382 (compute-source-registry parameter
))
5384 ;; Checks an initial variable to see whether the state is initialized
5385 ;; or cleared. In the former case, return current configuration; in
5386 ;; the latter, initialize. ASDF will call this function at the start
5387 ;; of (asdf:find-system) to make sure the source registry is initialized.
5388 ;; However, it will do so *without* a parameter, at which point it
5389 ;; will be too late to provide a parameter to this function, though
5390 ;; you may override the configuration explicitly by calling
5391 ;; initialize-source-registry directly with your parameter.
5392 (defun ensure-source-registry (&optional parameter
)
5393 (unless (source-registry-initialized-p)
5394 (initialize-source-registry parameter
))
5397 (defun sysdef-source-registry-search (system)
5398 (ensure-source-registry)
5399 (values (gethash (primary-system-name system
) *source-registry
*))))
5402 ;;;; -------------------------------------------------------------------------
5403 ;;; Internal hacks for backward-compatibility
5405 (uiop/package
:define-package
:asdf
/backward-internals
5406 (:recycle
:asdf
/backward-internals
:asdf
)
5407 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/find-system
)
5408 (:export
#:load-sysdef
))
5409 (in-package :asdf
/backward-internals
)
5411 (with-asdf-deprecation (:style-warning
"3.2" :warning
"3.4")
5412 (defun load-sysdef (name pathname
)
5413 (declare (ignore name pathname
))
5414 ;; Needed for backward compatibility with swank-asdf from SLIME 2015-12-01 or older.
5415 (error "Use asdf:load-asd instead of asdf::load-sysdef")))
5416 ;;;; -------------------------------------------------------------------------
5417 ;;; Backward-compatible interfaces
5419 (uiop/package
:define-package
:asdf
/backward-interface
5420 (:recycle
:asdf
/backward-interface
:asdf
)
5421 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
5422 :asdf
/component
:asdf
/system
:asdf
/system-registry
:asdf
/operation
:asdf
/action
5423 :asdf
/lisp-action
:asdf
/plan
:asdf
/operate
5424 :asdf
/find-system
:asdf
/parse-defsystem
:asdf
/output-translations
:asdf
/bundle
)
5427 #:operation-error
#:compile-error
#:compile-failed
#:compile-warned
5428 #:error-component
#:error-operation
#:traverse
5429 #:component-load-dependencies
5430 #:enable-asdf-binary-locations-compatibility
5431 #:operation-on-failure
#:operation-on-warnings
#:on-failure
#:on-warnings
5432 #:component-property
5434 #:system-definition-pathname
#:system-registered-p
#:require-system
5436 #+ecl
#:make-build
))
5437 (in-package :asdf
/backward-interface
)
5439 ;; NB: the warning status of these functions may have to be distinguished later,
5440 ;; as some get removed faster than the others in client code.
5441 (with-asdf-deprecation (:style-warning
"3.2" :warning
"3.4")
5443 ;; These conditions from ASDF 1 and 2 are used by many packages in Quicklisp;
5444 ;; but ASDF3 replaced them with somewhat different variants of uiop:compile-condition
5445 ;; that do not involve ASDF actions.
5446 ;; TODO: find the offenders and stop them.
5448 (define-condition operation-error
(error) ;; Bad, backward-compatible name
5449 ;; Used by SBCL, cffi-tests, clsql-mysql, clsql-uffi, qt, elephant, uffi-tests, sb-grovel
5450 ((component :reader error-component
:initarg
:component
)
5451 (operation :reader error-operation
:initarg
:operation
))
5452 (:report
(lambda (c s
)
5453 (format s
(compatfmt "~@<~A while invoking ~A on ~A~@:>")
5454 (type-of c
) (error-operation c
) (error-component c
)))))
5455 (define-condition compile-error
(operation-error) ())
5456 (define-condition compile-failed
(compile-error) ())
5457 (define-condition compile-warned
(compile-error) ()))
5459 ;; In Quicklisp 2015-05, still used by lisp-executable, staple, repl-utilities, cffi
5460 (defun component-load-dependencies (component) ;; from ASDF 2.000 to 2.26
5461 "DEPRECATED. Please use COMPONENT-SIDEWAY-DEPENDENCIES instead; or better,
5462 define your operations with proper use of SIDEWAY-OPERATION, SELFWARD-OPERATION,
5463 or define methods on PREPARE-OP, etc."
5464 ;; Old deprecated name for the same thing. Please update your software.
5465 (component-sideway-dependencies component
))
5467 ;; These old interfaces from ASDF1 have never been very meaningful
5468 ;; but are still used in obscure places.
5469 ;; In Quicklisp 2015-05, still used by cl-protobufs and clx.
5470 (defgeneric operation-on-warnings
(operation)
5471 (:documentation
"DEPRECATED. Please use UIOP:*COMPILE-FILE-WARNINGS-BEHAVIOUR* instead."))
5472 (defgeneric operation-on-failure
(operation)
5473 (:documentation
"DEPRECATED. Please use UIOP:*COMPILE-FILE-FAILURE-BEHAVIOUR* instead."))
5474 (defgeneric (setf operation-on-warnings
) (x operation
)
5475 (:documentation
"DEPRECATED. Please SETF UIOP:*COMPILE-FILE-WARNINGS-BEHAVIOUR* instead."))
5476 (defgeneric (setf operation-on-failure
) (x operation
)
5477 (:documentation
"DEPRECATED. Please SETF UIOP:*COMPILE-FILE-FAILURE-BEHAVIOUR* instead."))
5479 (defmethod operation-on-warnings ((o operation
))
5480 *compile-file-warnings-behaviour
*)
5481 (defmethod operation-on-failure ((o operation
))
5482 *compile-file-failure-behaviour
*)
5483 (defmethod (setf operation-on-warnings
) (x (o operation
))
5484 (setf *compile-file-warnings-behaviour
* x
))
5485 (defmethod (setf operation-on-failure
) (x (o operation
))
5486 (setf *compile-file-failure-behaviour
* x
)))
5488 ;; Quicklisp 2015-05: Still used by SLIME's swank-asdf (!), common-lisp-stat,
5489 ;; js-parser, osicat, babel, staple, weblocks, cl-png, plain-odbc, autoproject,
5490 ;; cl-blapack, com.informatimago, cells-gtk3, asdf-dependency-grovel,
5491 ;; cl-glfw, cffi, jwacs, montezuma
5492 (defun system-definition-pathname (x)
5493 ;; As of 2.014.8, we mean to make this function obsolete,
5494 ;; but that won't happen until all clients have been updated.
5495 "DEPRECATED. This function used to expose ASDF internals with subtle
5496 differences with respect to user expectations, that have been refactored
5497 away since. We recommend you use ASDF:SYSTEM-SOURCE-FILE instead for a
5498 mostly compatible replacement that we're supporting, or even
5499 ASDF:SYSTEM-SOURCE-DIRECTORY or ASDF:SYSTEM-RELATIVE-PATHNAME
5500 if that's whay you mean." ;;)
5501 (system-source-file x
))
5503 ;; TRAVERSE is the function used to compute a plan in ASDF 1 and 2.
5504 ;; It was never officially exposed but some people still used it.
5505 (defgeneric traverse
(operation component
&key
&allow-other-keys
)
5507 "DEPRECATED. Use MAKE-PLAN and PLAN-ACTIONS, or REQUIRED-COMPONENTS,
5508 or some other supported interface instead.
5510 Generate and return a plan for performing OPERATION on COMPONENT.
5512 The plan returned is a list of dotted-pairs. Each pair is the CONS
5513 of ASDF operation object and a COMPONENT object. The pairs will be
5514 processed in order by OPERATE."))
5516 (define-convenience-action-methods traverse
(operation component
&key
)))
5517 (defmethod traverse ((o operation
) (c component
) &rest keys
&key plan-class
&allow-other-keys
)
5518 (plan-actions (apply 'make-plan plan-class o c keys
)))
5521 ;; ASDF-Binary-Locations compatibility
5522 ;; This remains supported for legacy user, but not recommended for new users.
5523 ;; We suspect there are no more legacy users in 2016.
5524 (defun enable-asdf-binary-locations-compatibility
5526 (centralize-lisp-binaries nil
)
5527 (default-toplevel-directory
5528 ;; Use ".cache/common-lisp/" instead ???
5529 (subpathname (user-homedir-pathname) ".fasls/"))
5530 (include-per-user-information nil
)
5531 (map-all-source-files (or #+(or clasp clisp ecl mkcl
) t nil
))
5532 (source-to-target-mappings nil
)
5533 (file-types `(,(compile-file-type)
5535 #+clasp
(compile-file-type :output-type
:object
)
5536 #+ecl
(compile-file-type :type
:object
)
5537 #+mkcl
(compile-file-type :fasl-p nil
)
5538 #+clisp
"lib" #+sbcl
"cfasl"
5539 #+sbcl
"sbcl-warnings" #+clozure
"ccl-warnings")))
5540 "DEPRECATED. Use asdf-output-translations instead."
5541 #+(or clasp clisp ecl mkcl
)
5542 (when (null map-all-source-files
)
5543 (error "asdf:enable-asdf-binary-locations-compatibility doesn't support :map-all-source-files nil on CLISP, ECL and MKCL"))
5544 (let* ((patterns (if map-all-source-files
(list *wild-file
*)
5545 (loop :for type
:in file-types
5546 :collect
(make-pathname :type type
:defaults
*wild-file
*))))
5547 (destination-directory
5548 (if centralize-lisp-binaries
5549 `(,default-toplevel-directory
5550 ,@(when include-per-user-information
5551 (cdr (pathname-directory (user-homedir-pathname))))
5552 :implementation
,*wild-inferiors
*)
5553 `(:root
,*wild-inferiors
* :implementation
))))
5554 (initialize-output-translations
5555 `(:output-translations
5556 ,@source-to-target-mappings
5557 #+abcl
(#p
"jar:file:/**/*.jar!/**/*.*" (:function translate-jar-pathname
))
5558 #+abcl
(#p
"/___jar___file___root___/**/*.*" (,@destination-directory
))
5559 ,@(loop :for pattern
:in patterns
5560 :collect
`((:root
,*wild-inferiors
* ,pattern
)
5561 (,@destination-directory
,pattern
)))
5563 :ignore-inherited-configuration
))))
5565 (defmethod operate :before
(operation-class system
&rest args
&key
&allow-other-keys
)
5566 (declare (ignore operation-class system args
))
5567 (when (find-symbol* '#:output-files-for-system-and-operation
:asdf nil
)
5568 (error "ASDF 2 is not compatible with ASDF-BINARY-LOCATIONS, which you are using.
5569 ASDF 2 now achieves the same purpose with its builtin ASDF-OUTPUT-TRANSLATIONS,
5570 which should be easier to configure. Please stop using ASDF-BINARY-LOCATIONS,
5571 and instead use ASDF-OUTPUT-TRANSLATIONS. See the ASDF manual for details.
5572 In case you insist on preserving your previous A-B-L configuration, but
5573 do not know how to achieve the same effect with A-O-T, you may use function
5574 ASDF:ENABLE-ASDF-BINARY-LOCATIONS-COMPATIBILITY as documented in the manual;
5575 call that function where you would otherwise have loaded and configured A-B-L."))))
5578 ;; run-shell-command from ASDF 2, lightly fixed from ASDF 1, copied from MK-DEFSYSTEM. Die!
5579 (defun run-shell-command (control-string &rest args
)
5580 "PLEASE DO NOT USE. This function is not just DEPRECATED, but also dysfunctional.
5581 Please use UIOP:RUN-PROGRAM instead."
5582 #-
(and ecl os-windows
)
5583 (let ((command (apply 'format nil control-string args
)))
5584 (asdf-message "; $ ~A~%" command
)
5587 (nth-value 2 (run-program command
:force-shell t
:ignore-error-status t
5588 :output
*verbose-out
*)))))
5590 ((integer 0 255) exit-code
)
5592 #+(and ecl os-windows
)
5593 (not-implemented-error "run-shell-command" "for ECL on Windows."))
5595 ;; HOW do we get rid of variables??? With a symbol-macro that issues a warning?
5596 ;; In Quicklisp 2015-05, cl-protobufs still uses it, but that should be fixed in next version.
5598 (defvar *asdf-verbose
* nil
)) ;; backward-compatibility with ASDF2 only. Unused.
5600 ;; Do NOT use in new code. NOT SUPPORTED.
5601 ;; NB: When this goes away, remove the slot PROPERTY in COMPONENT.
5602 ;; In Quicklisp 2014-05, it's still used by yaclml, amazon-ecs, blackthorn-engine, cl-tidy.
5603 ;; See TODO for further cleanups required before to get rid of it.
5604 (defgeneric component-property
(component property
))
5605 (defgeneric (setf component-property
) (new-value component property
))
5607 (defmethod component-property ((c component
) property
)
5608 (cdr (assoc property
(slot-value c
'properties
) :test
#'equal
)))
5610 (defmethod (setf component-property
) (new-value (c component
) property
)
5611 (let ((a (assoc property
(slot-value c
'properties
) :test
#'equal
)))
5613 (setf (cdr a
) new-value
)
5614 (setf (slot-value c
'properties
)
5615 (acons property new-value
(slot-value c
'properties
)))))
5619 ;; This method survives from ASDF 1, but really it is superseded by action-description.
5620 (defgeneric explain
(operation component
)
5621 (:documentation
"Display a message describing an action.
5623 DEPRECATED. Use ASDF:ACTION-DESCRIPTION and/or ASDF::FORMAT-ACTION instead."))
5625 (define-convenience-action-methods explain
(operation component
)))
5626 (defmethod explain ((o operation
) (c component
))
5627 (asdf-message (compatfmt "~&~@<; ~@;~A~:>~%") (action-description o c
))))
5629 (with-asdf-deprecation (:style-warning
"3.3")
5630 (defun system-registered-p (name)
5631 "DEPRECATED. Return a generalized boolean that is true if a system of given NAME was registered already.
5632 NAME is a system designator, to be normalized by COERCE-NAME.
5633 The value returned if true is a pair of a timestamp and a system object."
5634 (if-let (system (registered-system name
))
5635 (cons (if-let (primary-system (registered-system (primary-system-name name
)))
5636 (component-operation-time 'define-op primary-system
))
5639 (defun require-system (system &rest keys
&key
&allow-other-keys
)
5640 "Ensure the specified SYSTEM is loaded, passing the KEYS to OPERATE, but do not update the
5641 system or its dependencies if it has already been loaded."
5642 (declare (ignore keys
))
5643 (unless (component-loaded-p system
)
5644 (load-system system
))))
5646 ;;; This function is for backward compatibility with ECL only.
5648 (with-asdf-deprecation (:style-warning
"3.2" :warning
"9999")
5649 (defun make-build (system &rest args
5650 &key
(monolithic nil
) (type :fasl
) (move-here nil move-here-p
)
5651 prologue-code epilogue-code no-uiop
5652 prefix-lisp-object-files postfix-lisp-object-files extra-object-files
5654 (let* ((operation (asdf/bundle
::select-bundle-operation type monolithic
))
5655 (move-here-path (if (and move-here
5656 (typep move-here
'(or pathname string
)))
5657 (ensure-pathname move-here
:namestring
:lisp
:ensure-directory t
)
5658 (system-relative-pathname system
"asdf-output/")))
5659 (extra-build-args (remove-plist-keys
5660 '(:monolithic
:type
:move-here
5661 :prologue-code
:epilogue-code
:no-uiop
5662 :prefix-lisp-object-files
:postfix-lisp-object-files
5663 :extra-object-files
)
5665 (build-system (if (subtypep operation
'image-op
)
5666 (eval `(defsystem "asdf.make-build"
5667 :class program-system
5669 :pathname
,(system-source-directory system
)
5670 :build-operation
,operation
5671 :build-pathname
,(subpathname move-here-path
5672 (file-namestring (first (output-files operation system
))))
5673 :depends-on
(,(coerce-name system
))
5674 :prologue-code
,prologue-code
5675 :epilogue-code
,epilogue-code
5677 :prefix-lisp-object-files
,prefix-lisp-object-files
5678 :postfix-lisp-object-files
,postfix-lisp-object-files
5679 :extra-object-files
,extra-object-files
5680 :extra-build-args
,extra-build-args
))
5682 (files (output-files operation build-system
)))
5683 (operate operation build-system
)
5685 (and (null move-here-p
) (member operation
'(program-op image-op
))))
5686 (loop :with dest-path
= (resolve-symlinks* (ensure-directories-exist move-here-path
))
5688 :for new-f
= (make-pathname :name
(pathname-name f
)
5689 :type
(pathname-type f
)
5690 :defaults dest-path
)
5691 :do
(rename-file-overwriting-target f new-f
)
5694 ;;;; ---------------------------------------------------------------------------
5695 ;;;; Handle ASDF package upgrade, including implementation-dependent magic.
5697 (uiop/package
:define-package
:asdf
/interface
5698 (:nicknames
:asdf
:asdf-utilities
)
5699 (:recycle
:asdf
/interface
:asdf
)
5701 #:loaded-systems
; makes for annoying SLIME completion
5702 #:output-files-for-system-and-operation
) ; ASDF-BINARY-LOCATION function we use to detect ABL
5703 (:use
:uiop
/common-lisp
:uiop
:asdf
/upgrade
:asdf
/session
5704 :asdf
/component
:asdf
/system
:asdf
/system-registry
:asdf
/find-component
5705 :asdf
/operation
:asdf
/action
:asdf
/lisp-action
5706 :asdf
/output-translations
:asdf
/source-registry
5707 :asdf
/forcing
:asdf
/plan
:asdf
/operate
:asdf
/find-system
:asdf
/parse-defsystem
5708 :asdf
/bundle
:asdf
/concatenate-source
5709 :asdf
/backward-internals
:asdf
/backward-interface
:asdf
/package-inferred-system
)
5710 ;; Note: (1) we are NOT automatically reexporting everything from previous packages.
5711 ;; (2) we only reexport UIOP functionality when backward-compatibility requires it.
5713 #:defsystem
#:find-system
#:load-asd
#:locate-system
#:coerce-name
#:primary-system-name
5714 #:oos
#:operate
#:make-plan
#:perform-plan
#:sequential-plan
5715 #:system-definition-pathname
5716 #:search-for-system-definition
#:find-component
#:component-find-path
5717 #:compile-system
#:load-system
#:load-systems
#:load-systems
*
5718 #:require-system
#:test-system
#:clear-system
5719 #:operation
#:make-operation
#:find-operation
5720 #:upward-operation
#:downward-operation
#:sideway-operation
#:selfward-operation
5721 #:non-propagating-operation
5723 #:load-op
#:prepare-op
#:compile-op
5724 #:prepare-source-op
#:load-source-op
#:test-op
#:define-op
5725 #:feature
#:version
#:version-satisfies
#:upgrade-asdf
5726 #:implementation-identifier
#:implementation-type
#:hostname
5727 #:component-depends-on
; backward-compatible name rather than action-depends-on
5728 #:input-files
#:additional-input-files
5729 #:output-files
#:output-file
#:perform
#:perform-with-restarts
5730 #:operation-done-p
#:explain
#:action-description
#:component-sideway-dependencies
5732 #:bundle-op
#:monolithic-bundle-op
#:precompiled-system
#:compiled-file
#:bundle-system
5734 #:basic-compile-bundle-op
#:prepare-bundle-op
5735 #:compile-bundle-op
#:load-bundle-op
#:monolithic-compile-bundle-op
#:monolithic-load-bundle-op
5736 #:lib-op
#:dll-op
#:deliver-asd-op
#:program-op
#:image-op
5737 #:monolithic-lib-op
#:monolithic-dll-op
#:monolithic-deliver-asd-op
5738 #:concatenate-source-op
5739 #:load-concatenated-source-op
5740 #:compile-concatenated-source-op
5741 #:load-compiled-concatenated-source-op
5742 #:monolithic-concatenate-source-op
5743 #:monolithic-load-concatenated-source-op
5744 #:monolithic-compile-concatenated-source-op
5745 #:monolithic-load-compiled-concatenated-source-op
5746 #:operation-monolithic-p
5747 #:required-components
5748 #:component-loaded-p
5749 #:component
#:parent-component
#:child-component
#:system
#:module
5750 #:file-component
#:source-file
#:c-source-file
#:java-source-file
5751 #:cl-source-file
#:cl-source-file.cl
#:cl-source-file.lsp
5752 #:static-file
#:doc-file
#:html-file
5753 #:file-type
#:source-file-type
5754 #:register-preloaded-system
#:sysdef-preloaded-system-search
5755 #:register-immutable-system
#:sysdef-immutable-system-search
5756 #:package-inferred-system
#:register-system-packages
5757 #:component-children
5758 #:component-children-by-name
5759 #:component-pathname
5760 #:component-relative-pathname
5765 #:component-encoding
5766 #:component-external-format
5767 #:system-description
5768 #:system-long-description
5773 #:system-source-file
5774 #:system-source-directory
5775 #:system-relative-pathname
5778 #:system-bug-tracker
5780 #:system-source-control
5782 #:system-defsystem-depends-on
5784 #:system-weakly-depends-on
5785 #:*system-definition-search-functions
* ; variables
5786 #:*central-registry
*
5787 #:*compile-file-warnings-behaviour
*
5788 #:*compile-file-failure-behaviour
*
5789 #:*resolve-symlinks
*
5792 #:compile-condition
#:compile-file-error
#:compile-warned-error
#:compile-failed-error
5793 #:compile-warned-warning
#:compile-failed-warning
5796 #:load-system-definition-error
5797 #:error-component
#:error-operation
5798 #:system-definition-error
5800 #:missing-component-of-version
5801 #:missing-dependency
5802 #:missing-dependency-of-version
5803 #:circular-dependency
; errors
5804 #:duplicate-names
#:non-toplevel-system
#:non-system-system
#:bad-system-name
#:system-out-of-date
5805 #:package-inferred-system-missing-package-error
5806 #:operation-definition-warning
#:operation-definition-error
5807 #:try-recompiling
; restarts
5810 #:coerce-entry-to-directory
5811 #:remove-entry-from-registry
5812 #:clear-configuration-and-retry
5813 #:*encoding-detection-hook
*
5814 #:*encoding-external-format-hook
*
5815 #:*default-encoding
*
5816 #:*utf-8-external-format
*
5817 #:clear-configuration
5818 #:*output-translations-parameter
*
5819 #:initialize-output-translations
5820 #:disable-output-translations
5821 #:clear-output-translations
5822 #:ensure-output-translations
5823 #:apply-output-translations
5825 #:compile-file-pathname
*
5826 #:*warnings-file-type
* #:enable-deferred-warnings-check
#:disable-deferred-warnings-check
5827 #:enable-asdf-binary-locations-compatibility
5828 #:*default-source-registries
*
5829 #:*source-registry-parameter
*
5830 #:initialize-source-registry
5831 #:compute-source-registry
5832 #:clear-source-registry
5833 #:ensure-source-registry
5834 #:process-source-registry
5835 #:registered-system
#:registered-systems
#:already-loaded-systems
5839 #:user-output-translations-pathname
5840 #:system-output-translations-pathname
5841 #:user-output-translations-directory-pathname
5842 #:system-output-translations-directory-pathname
5843 #:user-source-registry
5844 #:system-source-registry
5845 #:user-source-registry-directory
5846 #:system-source-registry-directory
5848 ;; The symbols below are all DEPRECATED, do not use. To be removed in a further release.
5849 #:*asdf-verbose
* #:run-shell-command
5850 #:component-load-dependencies
#:system-registered-p
#:package-system
5852 #:operation-on-warnings
#:operation-on-failure
#:operation-error
5853 #:compile-failed
#:compile-warned
#:compile-error
5854 #:module-components
#:component-property
#:traverse
))
5855 ;;;; ---------------------------------------------------------------------------
5856 ;;;; ASDF-USER, where the action happens.
5858 (uiop/package
:define-package
:asdf
/user
5859 (:nicknames
:asdf-user
)
5860 ;; NB: releases before 3.1.2 this :use'd only uiop/package instead of uiop below.
5861 ;; They also :use'd uiop/common-lisp, that reexports common-lisp and is not included in uiop.
5862 ;; ASDF3 releases from 2.27 to 2.31 called uiop asdf-driver and asdf/foo uiop/foo.
5863 ;; ASDF1 and ASDF2 releases (2.26 and earlier) create a temporary package
5864 ;; that only :use's :cl and :asdf
5865 (:use
:uiop
/common-lisp
:uiop
:asdf
/interface
))
5866 ;;;; -----------------------------------------------------------------------
5867 ;;;; ASDF Footer: last words and cleanup
5869 (uiop/package
:define-package
:asdf
/footer
5870 (:recycle
:asdf
/footer
:asdf
)
5871 (:use
:uiop
/common-lisp
:uiop
5872 :asdf
/system
;; used by ECL
5873 :asdf
/upgrade
:asdf
/system-registry
:asdf
/operate
:asdf
/bundle
)
5874 ;; Happily, all those implementations all have the same module-provider hook interface.
5875 #+(or abcl clasp cmucl clozure ecl mkcl sbcl
)
5876 (:import-from
#+abcl
:sys
#+(or clasp cmucl ecl
) :ext
#+clozure
:ccl
#+mkcl
:mk-ext
#+sbcl sb-ext
5877 #:*module-provider-functions
*
5878 #+ecl
#:*load-hooks
*)
5879 #+(or clasp mkcl
) (:import-from
:si
#:*load-hooks
*))
5881 (in-package :asdf
/footer
)
5883 ;;;; Register ASDF itself and all its subsystems as preloaded.
5884 (with-upgradability ()
5885 (dolist (s '("asdf" "uiop" "asdf-package-system"))
5886 ;; Don't bother with these system names, no one relies on them anymore:
5887 ;; "asdf-utils" "asdf-bundle" "asdf-driver" "asdf-defsystem"
5888 (register-preloaded-system s
:version
*asdf-version
*)))
5891 ;;;; Hook ASDF into the implementation's REQUIRE and other entry points.
5892 #+(or abcl clasp clisp clozure cmucl ecl mkcl sbcl
)
5893 (with-upgradability ()
5894 ;; Hook into CL:REQUIRE.
5895 #-clisp
(pushnew 'module-provide-asdf
*module-provider-functions
*)
5896 #+clisp
(if-let (x (find-symbol* '#:*module-provider-functions
* :custom nil
))
5897 (eval `(pushnew 'module-provide-asdf
,x
)))
5899 #+(or clasp ecl mkcl
)
5901 (pushnew '("fasb" . si
::load-binary
) *load-hooks
* :test
'equal
:key
'car
)
5904 (unless (assoc "asd" *load-hooks
* :test
'equal
)
5905 (appendf *load-hooks
* '(("asd" . si
::load-source
))))
5907 ;; Wrap module provider functions in an idempotent, upgrade friendly way
5908 (defvar *wrapped-module-provider
* (make-hash-table))
5909 (setf (gethash 'module-provide-asdf
*wrapped-module-provider
*) 'module-provide-asdf
)
5910 (defun wrap-module-provider (provider name
)
5911 (let ((results (multiple-value-list (funcall provider name
))))
5912 (when (first results
) (register-preloaded-system (coerce-name name
)))
5913 (values-list results
)))
5914 (defun wrap-module-provider-function (provider)
5915 (ensure-gethash provider
*wrapped-module-provider
*
5917 #'(lambda (module-name)
5918 (wrap-module-provider provider module-name
)))))
5919 (setf *module-provider-functions
*
5920 (mapcar #'wrap-module-provider-function
*module-provider-functions
*))))
5922 #+cmucl
;; Hook into the CMUCL herald.
5923 (with-upgradability ()
5924 (defun herald-asdf (stream)
5925 (format stream
" ASDF ~A" (asdf-version)))
5926 (setf (getf ext
:*herald-items
* :asdf
) '(herald-asdf)))
5930 (with-upgradability ()
5931 #+allegro
;; restore *w-o-n-r-c* setting as saved in uiop/common-lisp
5932 (when (boundp 'excl
:*warn-on-nested-reader-conditionals
*)
5933 (setf excl
:*warn-on-nested-reader-conditionals
* uiop
/common-lisp
::*acl-warn-save
*))
5935 ;; Advertise the features we provide.
5936 (dolist (f '(:asdf
:asdf2
:asdf3
:asdf3.1
:asdf3.2
:asdf3.3
)) (pushnew f
*features
*))
5938 ;; Provide both lowercase and uppercase, to satisfy more people, especially LispWorks users.
5939 (provide "asdf") (provide "ASDF")
5941 ;; Finally, call a function that will cleanup in case this is an upgrade of an older ASDF.
5942 (cleanup-upgraded-asdf))
5944 (when *load-verbose
*
5945 (asdf-message ";; ASDF, version ~a~%" (asdf-version)))