system.lisp 3.61 KB
Newer Older
1 2 3
;;;; -------------------------------------------------------------------------
;;;; Systems

4
(asdf/package:define-package :asdf/system
5
  (:recycle :asdf :asdf/system)
6
  (:use :common-lisp :asdf/driver :asdf/upgrade :asdf/component)
7 8
  (:intern #:children #:children-by-name #:default-component-class
           #:author #:maintainer #:licence #:source-file #:defsystem-depends-on)
9
  (:export
10
   #:system #:proto-system
11 12 13 14
   #:system-source-file #:system-source-directory #:system-relative-pathname
   #:reset-system #:builtin-system-p
   #:system-description #:system-long-description
   #:system-author #:system-maintainer #:system-licence #:system-license
15
   #:find-system ;; forward-reference, defined in find-system
16 17 18 19
   #:system-defsystem-depends-on))
(in-package :asdf/system)

(defgeneric* find-system (system &optional error-p))
20 21
(defgeneric* system-source-file (system)
  (:documentation "Return the source file in which system is defined."))
22

23
;;;; The system class
24 25 26 27

(defclass proto-system () ; slots to keep when resetting a system
  ;; To preserve identity for all objects, we'd need keep the components slots
  ;; but also to modify parse-component-form to reset the recycled objects.
28
  ((name) (source-file) #|(children) (children-by-names)|#))
29 30 31 32

(defclass system (module proto-system)
  ;; Backward-compatibility: inherit from module. ASDF3: only inherit from parent-component.
  (;; {,long-}description is now inherited from component, but we add the legacy accessors
33 34
   (description :accessor system-description)
   (long-description :accessor system-long-description)
35 36 37 38
   (author :accessor system-author :initarg :author)
   (maintainer :accessor system-maintainer :initarg :maintainer)
   (licence :accessor system-licence :initarg :licence
            :accessor system-license :initarg :license)
39
   (source-file :initform nil :initarg :source-file :accessor system-source-file)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
   (defsystem-depends-on :reader system-defsystem-depends-on :initarg :defsystem-depends-on)))

(defun* reset-system (system &rest keys &key &allow-other-keys)
  (change-class (change-class system 'proto-system) 'system)
  (apply 'reinitialize-instance system keys))


;;;; Pathnames

(defmethod system-source-file ((system-name string))
  (system-source-file (find-system system-name)))
(defmethod system-source-file ((system-name symbol))
  (system-source-file (find-system system-name)))

(defun* system-source-directory (system-designator)
55 56
  "Return a pathname object corresponding to the directory
in which the system specification (.asd file) is located."
57 58 59 60 61
  (pathname-directory-pathname (system-source-file system-designator)))

(defun* system-relative-pathname (system name &key type)
  (subpathname (system-source-directory system) name :type type))

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
(defmethod component-pathname ((system system))
  (or (call-next-method)
      (system-source-directory system)))

(defmethod component-relative-pathname ((system system))
  (parse-unix-namestring
   (and (slot-boundp system 'relative-pathname)
        (slot-value system 'relative-pathname))
   :want-relative t
   :type :directory
   :ensure-absolute t
   :defaults (system-source-directory system)))

(defmethod component-parent-pathname ((system system))
  (system-source-directory system))


79 80 81 82 83
;;;; Beware of builtin systems
(defgeneric* builtin-system-p (system))
(defmethod builtin-system-p ((s system))
  (let* ((system (find-system s nil))
         (sysdir (and system (component-pathname system)))
84 85 86 87 88 89
         (truesysdir (truename* sysdir))
         (impdir (lisp-implementation-directory))
         (trueimpdir (truename* impdir)))
    (and sysdir impdir
         (or (subpathp sysdir impdir)
             (subpathp truesysdir trueimpdir)))))