How do you tell ASDF to process a component file only if it exists (so it doesn't generate an error if it doesn't exist yet).
(asdf:defsystem "my-system"
:components ((:file "utilities")
(:file "temp-file" :depends-on ("utilities"))))
My workaround is using a reader macro #. on (probe-file "temp-file")
but can't get that to work.
I think what you really are trying to do is have ASDF merely warn you instead of bringing up the debugger during compilation errors. Change *compile-file-warnings-behaviour*
and *compile-file-failure-behaviour*
, and read the section on error handling in the manual.
The rest of this answer is how to check for a whole system. You could package the maybe-to-load files into their own systems and do it this way below.
From the ASDF Manual section 6.3.8.
6.3.8 Weakly depends on
We do NOT recommend you use this feature.
So you could just use it anyway. Like this:
(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")))
Simple right?
Here is what they recommend:
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.
I've never seen one of these in the wild, probably because it is a horrible confusing mess to do it that way.
(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 <[email protected]>"
: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")))