跳转到内容

通用Lisp/外部库/ASDF/配置ASDF

来自维基教科书,开放世界中的开放书籍

配置ASDF

[编辑 | 编辑源代码]

最常见的是,您将在Lisp系统的配置文件中添加ASDF设置。例如,SBCL使用~/.sbclrc,而CMUCL使用~/.cmucl-init。最重要的设置是下面描述的中心注册表。大多数其他配置设置是可选的。

asdf:*central-registry*

[编辑 | 编辑源代码]

中心注册表是将被搜索以查找系统定义(.asd)文件的目录列表,这是您需要了解的有关配置ASDF的最低限度信息。修改asdf:*central-registry*的最安全方法是使用pushnew将新目录推入列表中。

(pushnew "/Path/to/asd/files/" asdf:*central-registry*)

自动更新过时的fasl文件

[编辑 | 编辑源代码]

来自 http://www.cliki.net/asdf

;;; If the fasl was stale, try to recompile and load (once). Since only SBCL
;;; has a separate condition for bogus fasls we retry on any old error
;;; on other lisps. Actually, Allegro has a similar condition, but it's 
;;; unexported.  Works nicely for the ACL7 upgrade, though.
;;; CMUCL has an invalid-fasl condition as of 19c.
(defmethod asdf:perform :around ((o asdf:load-op) (c asdf:cl-source-file))
  (handler-case (call-next-method o c)
    (#+sbcl sb-ext:invalid-fasl 
     #+allegro excl::file-incompatible-fasl-error
     #+lispworks conditions:fasl-error
     #+cmu ext:invalid-fasl
     #-(or sbcl allegro lispworks cmu) error ()
     (asdf:perform (make-instance 'asdf:compile-op) c)
     (call-next-method))))

符号链接的替代方案,递归搜索目录

[编辑 | 编辑源代码]

将库添加到ASDF的标准方法包括以下两种方法:

  1. asdf:*central-registry*中列出的目录中创建.asd文件的符号链接,或者
  2. 将目录添加到asdf:*central-registry*中。

以下代码片段显示了如何递归地搜索子目录以查找ASDF包。

来自 http://www.cliki.net/asdf

;; An alternative to the standard sysdef search can be defined.  This                
;; code below can be dropped into your Lisp init files and customized.               
;; It will search for all ASDF systems in subdirectories of the                      
;; specified directories.  That lets you simply "drop-in" new packages               
;; into one of the specified directories, and it will be available for               
;; loading without any further steps.                                                
(in-package #:asdf)
(defvar *subdir-search-registry* '(#p"/my/lisp/libraries/")
  "List of directories to search subdirectories within.")
(defvar *subdir-search-wildcard* :wild
  "Value of :wild means search only one level of subdirectories; value of :wild-inferiors means search
 all levels of subdirectories (I don't advise using this in big directories!)")
(defun sysdef-subdir-search (system)
  (let ((latter-path (make-pathname :name (coerce-name system)
                                    :directory (list :relative
                                                     *subdir-search-wildcard*)
                                    :type "asd"
                                    :version :newest
                                    :case :local)))
    (dolist (d *subdir-search-registry*)
      (let* ((wild-path (merge-pathnames latter-path d))
             (files (directory wild-path)))
        (when files
          (return (first files)))))))
(pushnew 'sysdef-subdir-search *system-definition-search-functions*)

参考文献

[编辑 | 编辑源代码]
华夏公益教科书