3

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.

davypough
  • 1,847
  • 11
  • 21
  • 1
    [This looks somewhat promising](https://github.com/fare/asdf/blob/master/doc/best_practices.md#conditional_code). No idea whether it does what you want, so not putting it as answer. Why do you want to do this, anyway? –  Jun 06 '19 at 19:17
  • Yeah, this looks like you're generating source files, which I personally regard as an antipattern. What are you actually trying to achieve? – Svante Jun 06 '19 at 21:06
  • It's strictly a development convenience to sometimes bypass compiling & loading a problem specification file along with the system. I guess I could create a dummy specification, but thought it would be easier to just check if a specification file exists. – davypough Jun 07 '19 at 04:04
  • Why not `#|...code...|#` comment syntax around the file contents if you are aiming to block out a file? ASDF would succeed upon loading an "empty" (according to the lisp reader) file. – Spenser Truex Jun 19 '19 at 00:42

1 Answers1

1

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 <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")))
Spenser Truex
  • 963
  • 8
  • 24