Previous: Pre-defined subclasses of component, Up: Components


3.2.3 Creating new component types

New component types are defined by subclassing one of the existing component classes and specializing methods on the new component class.

FIXME: this should perhaps be explained more throughly, not only by example ...

As an example, suppose we have some implementation-dependent functionality that we want to isolate in one subdirectory per Lisp implementation our system supports. We create a subclass of cl-source-file:

     (defclass unportable-cl-source-file (cl-source-file)
         ())

A hypothetical function system-dependent-dirname gives us the name of the subdirectory. All that's left is to define how to calculate the pathname of an unportable-cl-source-file.

     (defmethod component-pathname ((component unportable-cl-source-file))
       (let ((pathname (call-next-method))
             (name (string-downcase (system-dependent-dirname))))
         (merge-pathnames
          (make-pathname :directory (list :relative name))
          pathname)))

The new component type is used in a defsystem form in this way:

     (defsystem :foo
         :components
         ((:file "packages")
          ...
          (:unportable-cl-source-file "threads"
           :depends-on ("packages" ...))
          ...
         )