首页 > 解决方案 > 使用 ASDF 加载可选组件

问题描述

您如何告诉 ASDF 仅在组件文件存在时才处理它(因此,如果它尚不存在,则不会生成错误)。

(asdf:defsystem "my-system"
  :components ((:file "utilities")
               (:file "temp-file" :depends-on ("utilities"))))

我的解决方法是使用阅读器宏#。开,(probe-file "temp-file")但无法让它发挥作用。

标签: common-lispasdf

解决方案


我认为你真正想要做的是让 ASDF 只是警告你而不是在编译错误期间启动调试器。更改*compile-file-warnings-behaviour**compile-file-failure-behaviour*,并阅读手册中有关错误处理的部分

这个答案的其余部分是如何检查整个系统。您可以将可能加载文件打包到他们自己的系统中,并在下面这样做。

来自ASDF 手册第 6.3.8 节

6.3.8 弱依赖

我们不建议您使用此功能。

所以无论如何你都可以使用它。像这样:

(defpackage :foo-system
  (:use :cl :asdf))
(in-package :foo-system)
(defsystem foo
  :description "The main package that maybe loads bar if it exists."
  :weakly-depends-on (:bar)
  :components ((:file "foo")))

简单吧?

以下是他们的推荐:

如果您想编写一个弱依赖于系统栏的系统 foo,我们建议您改为以参数方式编写系统 foo,并提供一些特殊变量和/或一些钩子来专门化其行为;那么你应该编写一个系统 foo+bar 来将事物连接在一起。

我从来没有在野外见过其中的一个,可能是因为这样做是一个可怕的混乱混乱。

(defpackage :bar-system
  (:use :cl :asdf))
(in-package :bar-system)
(defsystem bar
  :description "The package that maybe exists and is needed by foo."
  :components ((:file "bar")))

(defpackage :foo+bar-system
  (:use :cl :asdf))
(in-package :foo+bar-system)
(defsystem foo+bar
  :version      "0.1.0"
  :description  "Hook together foo and bar."
  :author       "Spenser Truex <web@spensertruex.com>"
  :serial       t
  :components ((:file "foo+bar")))

(defpackage :foo-system
  (:use :cl :asdf))
(in-package :foo-system)
(defsystem foo
  :description "The main package that maybe loads bar if it exists."
  :depends-on (:foo+bar)
  :components ((:file "foo")))

推荐阅读