common-lisp - 使用 ASDF 加载可选组件
问题描述
您如何告诉 ASDF 仅在组件文件存在时才处理它(因此,如果它尚不存在,则不会生成错误)。
(asdf:defsystem "my-system"
:components ((:file "utilities")
(:file "temp-file" :depends-on ("utilities"))))
我的解决方法是使用阅读器宏#。开,(probe-file "temp-file")
但无法让它发挥作用。
解决方案
我认为你真正想要做的是让 ASDF 只是警告你而不是在编译错误期间启动调试器。更改*compile-file-warnings-behaviour*
和*compile-file-failure-behaviour*
,并阅读手册中有关错误处理的部分。
这个答案的其余部分是如何检查整个系统。您可以将可能加载文件打包到他们自己的系统中,并在下面这样做。
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")))
推荐阅读
- cocoa - 如何使 NSScrollView 中的 MTKView 显示滚动条
- python - 为网页抓取时不存在的项目添加值
- android - Google Place API - 如何使用地点 ID 获取特定地点的内容
- javascript - 当我尝试通过 Laravel 存储来自 Vue.JS 的数据时出现错误 500
- r - 在数据框中的滑动窗口中拆分字符串
- matlab - 在 MATLAB 中使用三角函数最小化方程和约束
- latex - 如何将乳胶独立包与knitr一起使用?
- sql - 在 oracle 中更改表添加 guid 列
- javascript - React — componentDidUpdate 作为一个承诺/回调。是否可以?
- swift - KVO Swift:newValue 始终为 nil