From: Volkan YAZICI
Subject: Optional Package Dependency (WEAKLY-DEPENDS-ON of ASDF)
Date: 
Message-ID: <760cc42b-bbca-4b70-8374-d25ee659f0a7@l2g2000vba.googlegroups.com>
Hi,

I have a weak dependency to MYMP package in my ASDF file. Accordingly,
I want to alter my code just before the compilation with respect to
the availability of MYMP. For instance, consider below case.

  (defclass server (mymp:thread) ...)

  (defmethod print-object ((self server) stream) ...)

  (defun start-server (...) ... (mymp:start-thread server) ...)

How can I make above SERVER class and START-SERVER definitions to
utilize the availability of MYMP? What are the approaches of
experienced users to similar optional package dependency problems?


Regards.

From: Robert Uhl
Subject: Re: Optional Package Dependency (WEAKLY-DEPENDS-ON of ASDF)
Date: 
Message-ID: <m3hby2lx4c.fsf@latakia.octopodial-chrome.com>
Volkan YAZICI <·············@gmail.com> writes:
>
> I have a weak dependency to MYMP package in my ASDF file. Accordingly,
> I want to alter my code just before the compilation with respect to
> the availability of MYMP. For instance, consider below case.
>
>   (defclass server (mymp:thread) ...)
>
>   (defmethod print-object ((self server) stream) ...)
>
>   (defun start-server (...) ... (mymp:start-thread server) ...)
>
> How can I make above SERVER class and START-SERVER definitions to
> utilize the availability of MYMP? What are the approaches of
> experienced users to similar optional package dependency problems?

So SERVER is a subclass of MYMP:THREAD?  Are you sure that you want an
IS-A relationship instead of a HAS-A?  That is, should SERVER actually
_be_ a thread?

What I'd do if that's what you really want is this:

  (defclass server () ...)

  (defmethod start-server ((server server) ...) ...)

  #+mymp (defclass threaded-server ((server mymp:server) ...) ...)

  #+mymp (defmethod start-server ((server threaded-server) ...) ...)

You probably want START-SERVER specialsied on THREADED-SERVER to be a
:before, :after or :around method:

  (defmethod start-server :before ((server threaded-server) ...)
    (mymp:start-thread server))

or:

  (defmethod start-server :after ((server threaded-server) ...)
    (mymp:start-thread server))

or if you have some other stuff you need to do:

  (defmethod start-server :around ((server threaded-server) ...)
    ;; do some stuff, maybe start the thread
    (call-next-method) ;; call START-SERVER specialised on SERVER
    (do-stuff-with-server))

But I'm really not convinced that you want your server objects to be
threads.

-- 
Why Windows NT Server 4.0 continues to exist in the enterprise
would be a topic appropriate for an investigative report in the
field of psychology or marketing, not an article on information
technology.                                        --John Kirch
From: D Herring
Subject: Re: Optional Package Dependency (WEAKLY-DEPENDS-ON of ASDF)
Date: 
Message-ID: <4a456934$0$29140$6e1ede2f@read.cnntp.org>
Volkan YAZICI wrote:
> Hi,
> 
> I have a weak dependency to MYMP package in my ASDF file. Accordingly,
> I want to alter my code just before the compilation with respect to
> the availability of MYMP. For instance, consider below case.
> 
>   (defclass server (mymp:thread) ...)
> 
>   (defmethod print-object ((self server) stream) ...)
> 
>   (defun start-server (...) ... (mymp:start-thread server) ...)
> 
> How can I make above SERVER class and START-SERVER definitions to
> utilize the availability of MYMP? What are the approaches of
> experienced users to similar optional package dependency problems?

(begin-rant)
ASDF weak dependencies and the like are evil.  If MYMP is installed 
after your server has compiled, will ASDF recompile everything properly?

After years of experience, GNU autotools and many other build systems 
settled on a successful model for packaging software.

- configure
- build
- [test]
- install

ASDF purports to wrap these up all-in-one; but it only really does the 
build step ("install" happens first).  This leaves users to roll their 
own configuration mechanism, often scattering ad-hoc code throughout 
the sources where it is inaccessible to the end-user.
(end-rant)


My recommendation is to avoid the ASDF trickery and do it the 
old-school way:  have the user edit a config file if they want to 
enable the optional dependencies.  Unfortunately, this often means 
editing project.asd directly (to control which files get loaded).

Here's an example from cl-pdf.asd
;;;Choose the zlib implementation you want to use (only one!)
(eval-when (:load-toplevel :compile-toplevel :execute)
   ;;(pushnew :use-salza2-zlib *features*)
   ;;(pushnew :use-salza-zlib *features*)
   ;;(pushnew :use-uffi-zlib *features*)
   ;;(pushnew :use-abcl-zlib *features*)
   (pushnew :use-no-zlib *features*)
   )
...
(defsystem :cl-pdf
...
   :depends-on (:iterate #+use-salza-zlib :salza #+use-salza2-zlib 
:salza2))


- Daniel