1

Is there a way to make a configurable ASDF system that loads different lisp files depending on user configuration variables? Preferably, the loading process would fail with a legible error message if a required config var was not provided. How would one set such variables conveniently when loading the system? (Manually, through quicklisp, or from another system definition file)

user3026691
  • 497
  • 2
  • 11

2 Answers2

2

Not out of the box but you could arrange something akin to that. The easiest way to change files a system loads would be using #+/- in combination with *features*.

One way to add features would be in .sbclrc (or your implementations startup file) if you want something more project specific you could define a perform :before load-op on your system that would call a function that would read a file and depending on its content's it could modify *features* so that different components are read. I use this scheme for loading variables with configuration files.

So if my system is foo

(defsystem #:foo
  ...
  :dependencies (#:foo-config)
 ...)

(defmethod perform :after ((op load-op)
                           (system (eql (find-system :foo-config))))
  (asdf/package:symbol-call :foo/config-loader 'load-config
                            (system-relative-pathname :foo-config
                                                      #P"foo.config")))

Because #+/- works at read-time I'm guessing it wouldn't work because the features would be modified after reading the system definition. A hacky way around this could be to just require the config system and make the after method require the system after setting up the features.

My 2c.

PuercoPop
  • 6,707
  • 4
  • 30
  • 40
2

Please do not use #+ and #- in the defsystem form, but :if-feature instead.

Also, it's much better to do runtime-differentiation or to have a different system target altogether depending on features than to have a target that changes its meaning in an unaccountable way that the build system can't see.

Faré
  • 952
  • 5
  • 4
  • didn't know about :if-feature, guess I should rtfm one of this days – PuercoPop Apr 10 '15 at 22:15
  • @Faré, could you elaborate on what you mean by changing the target in a way the build system can't see? Do you mean that reloading the system with new config vars could result in required files not being compiled? – user3026691 Apr 11 '15 at 09:24
  • Since there doesn't seem to be a clean and safe way to do it, and there's only one variable in my case anyway, I'll just go with your suggestion of using two different system definitions. – user3026691 Apr 11 '15 at 19:27