Previous: , Up: Components   [Contents][Index]

7.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.

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)

Function asdf:implementation-type (exported since 2.014.14) 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))
   (parse-unix-namestring (format nil "~(~A~)/" (asdf:implementation-type)))

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

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