Re: on the loading of preference files

Gary King <[email protected]>
Newsgroups gmane.lisp.cclan.general
Message-ID <[email protected]>
Here is the current diff for adding preference loading to ASDF. The  
diff does the following:

* defines and exports two generic functions: load-preferences and  
preference-file-for-system/operation. Both of these
take two parameters: an operation and a component.
* Adds a call to load-preferences to the perform :after for  
operation / component.
* defines a new class 'basic-load-op' from which both load-op and  
load-source-op inherit
* defines a method on load-preferences that dispatches on basic-load- 
op and system

this is setup so that preferences are to be found in a file names  
<system-name>.lisp in the directory ~/.asdf. Of course, one could  
change that by writing another preference-file-for-system/operation.

comments welcome...

thanks,


> Index: asdf.lisp
> ===================================================================
> RCS file: /cvsroot/cclan/asdf/asdf.lisp,v
> retrieving revision 1.99
> diff -u -w -u -r1.99 asdf.lisp
> --- asdf.lisp	16 Jun 2006 20:17:01 -0000	1.99
> +++ asdf.lisp	27 Jun 2006 12:01:49 -0000
> @@ -101,6 +101,8 @@
> 	   #:retry
> 	   #:accept                     ; restarts
> 	
> +           #:preference-file-for-system/operation
> +           #:load-preferences
> 	   )
>    (:use :cl))
> @@ -732,7 +734,8 @@
> (defmethod perform :after ((operation operation) (c component))
>    (setf (gethash (type-of operation) (component-operation-times c))
> -	(get-universal-time)))
> +	(get-universal-time))
> +  (load-preferences c operation))
> ;;; perform is required to check output-files to find out where to put
> ;;; its answers, in case it has been overridden for site policy
> @@ -773,7 +776,9 @@
> ;;; load-op
> -(defclass load-op (operation) ())
> +(defclass basic-load-op (operation) ())
> +
> +(defclass load-op (basic-load-op) ())
> (defmethod perform ((o load-op) (c cl-source-file))
>    (mapcar #'load (input-files o c)))
> @@ -792,7 +797,7 @@
> ;;; load-source-op
> -(defclass load-source-op (operation) ())
> +(defclass load-source-op (basic-load-op) ())
> (defmethod perform ((o load-source-op) (c cl-source-file))
>    (let ((source (component-pathname c)))
> @@ -827,6 +832,38 @@
> (defmethod perform ((operation test-op) (c component))
>    nil)
> +(defgeneric load-preferences (system operation)
> +  (:documentation "Called to load system preferences after  
> <perform operation system>. Typical uses are to set parameters that  
> don't exist until after the system has been loaded."))
> +
> +(defgeneric preference-file-for-system/operation (system operation)
> +  (:documentation "Returns the pathname of the preference file for  
> this system. Called by 'load-preferences to determine what file to  
> load."))
> +
> +(defmethod load-preferences ((s t) (operation t))
> +  ;; do nothing
> +  (values))
> +
> +(defmethod load-preferences ((s system) (operation basic-load-op))
> +  (let* ((*package* (find-package :common-lisp))
> +         (file (probe-file (preference-file-for-system/operation s  
> operation))))
> +    (when file
> +      (when *verbose-out*
> +	(format *verbose-out*
> +		"~&~@<; ~@;loading preferences for ~A/~(~A~) from ~A~@:>~%"
> +		(component-name s)
> +		(type-of operation) file))
> +      (load file))))
> +
> +(defmethod preference-file-for-system/operation ((system t)  
> (operation t))
> +  ;; cope with anything other than systems
> +  (preference-file-for-system/operation (find-system system t)  
> operation))
> +
> +(defmethod preference-file-for-system/operation ((s system)  
> (operation t))
> +  (merge-pathnames
> +   (make-pathname :name (component-name s)
> +                  :type "lisp"
> +                  :directory '(:relative ".asdf"))
> +   (truename (user-homedir-pathname))))
> +
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;; invoking operations
>


On Jun 20, 2006, at 10:45 AM, Christophe Rhodes wrote:


> Gary King <[email protected]> writes:
>
>
>>> +(defgeneric load-preferences (system)
>>> +  (:documentation "Called to load system preferences after
>>> <perform load-op system>. Typical uses are to set parameters that
>>> don't exist until after the system has been loaded."))
>>> +
>>> +(defgeneric preference-file-for-system (system)
>>> +  (:documentation "Returns the pathname of the preference file for
>>> this system. Called by 'load-preferences to determine what file to
>>> load."))
>>>
>
> I think that both of these should have an operation argument
> additionally.  It's not just after performing a load-op that a
> preferences file should be loaded -- consider a load-source operation,
> not to mention possible user-specified operations.
>
> Alternatively, if you believe that there's one and only one
> preference-file-loading operation, then it probably deserves to be an
> operation in and of itself.
>
> Cheers,
>
> Christophe
>


-- 
Gary Warren King
metabang.com
http://www.metabang.com/
(413) 210 7511
gwking on #lisp (occasionally)



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.