使用 ASDF 加载可选组件
Loading an Optional Component with ASDF
如何告诉 ASDF 仅在组件文件存在时才对其进行处理(因此如果组件文件尚不存在则不会生成错误)。
(asdf:defsystem "my-system"
:components ((:file "utilities")
(:file "temp-file" :depends-on ("utilities"))))
我的解决方法是使用 reader 宏#。在 (probe-file "temp-file")
上,但无法正常工作。
我认为您真正想要做的是让 ASDF 只是警告您,而不是在编译错误期间启动调试器。更改*compile-file-warnings-behaviour*
和*compile-file-failure-behaviour*
,并阅读手册中的the section on error handling。
这个答案的其余部分是如何检查整个系统。您可以将 maybe-to-load 文件打包到他们自己的系统中,然后按照下面的方式进行。
6.3.8 Weakly depends on
We do NOT recommend you use this feature.
所以你无论如何都可以使用它。像这样:
(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")))
简单吧?
这是他们的推荐:
If you are tempted to write a system foo that weakly-depends-on a
system bar, we recommend that you should instead write system foo in a
parametric way, and offer some special variable and/or some hook to
specialize its behaviour; then you should write a system foo+bar that
does the hooking of things together.
我从来没有在野外见过其中一个,可能是因为那样做会让人感到非常混乱。
(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")))
如何告诉 ASDF 仅在组件文件存在时才对其进行处理(因此如果组件文件尚不存在则不会生成错误)。
(asdf:defsystem "my-system"
:components ((:file "utilities")
(:file "temp-file" :depends-on ("utilities"))))
我的解决方法是使用 reader 宏#。在 (probe-file "temp-file")
上,但无法正常工作。
我认为您真正想要做的是让 ASDF 只是警告您,而不是在编译错误期间启动调试器。更改*compile-file-warnings-behaviour*
和*compile-file-failure-behaviour*
,并阅读手册中的the section on error handling。
这个答案的其余部分是如何检查整个系统。您可以将 maybe-to-load 文件打包到他们自己的系统中,然后按照下面的方式进行。
6.3.8 Weakly depends on
We do NOT recommend you use this feature.
所以你无论如何都可以使用它。像这样:
(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")))
简单吧?
这是他们的推荐:
If you are tempted to write a system foo that weakly-depends-on a system bar, we recommend that you should instead write system foo in a parametric way, and offer some special variable and/or some hook to specialize its behaviour; then you should write a system foo+bar that does the hooking of things together.
我从来没有在野外见过其中一个,可能是因为那样做会让人感到非常混乱。
(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")))