guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modified load-path proposal


From: Neil Jerram
Subject: Modified load-path proposal
Date: Thu, 13 Oct 2005 19:21:13 +0100
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I think this meets everyone's desires ... please let me know what you
think!

        Neil

                      -*- scheme -*-

;; 1. Format and example contents of
;; $sysconfdir/guile/$EFFECTIVE_VERSION/config.scm
;;
;; The format is a single alist expression which Guile reads.
;; (config.scm is not a file which Guile loads, and which could
;; therefore contain arbitrary code, because (i) it is used before
;; boot-9.scm is loaded, which means that bits of Scheme are not
;; available yet, and (ii) the specification of a standard format
;; allows us to use automated tools for updating the contents of the
;; file.)
;;
;; Each element of the alist is (INFO-TYPE . INFO), where the only
;; currently supported INFO-TYPE is load-path.  The alist format
;; allows us to extend the use of the config.scm in future, but in a
;; way that should not require existing code and tools (if well
;; written) to be updated.
;;
;; When INFO-TYPE is load-path, the form of INFO is (DEFAULT-TAG (TAG
;; DIRECTORY DESCRIPTION) ...), where:
;;
;; - DEFAULT-TAG is the tag of the default install location for Guile
;; packages.  In other words, it identifies the location that
;; GUILE_SCHEME_DIR will return if a package's ./configure is run
;; without a --with-guile-scheme-dir option.
;;
;; - TAG is an arbitrary symbol which can be used to uniquely identify
;; each load path directory.
;;
;; - DIRECTORY is a load path directory (as a string).
;;
;; - DESCRIPTION is a string describing the use of that load path
;; directory.

((load-path
  local
  (guile-1.6
   "/usr/share/guile/1.6"
   "Install location for Guile 1.6's own Scheme files")
  (site
   "/usr/share/guile/site"
   "Install location for site-specific Scheme files")
  (gnome
   "/opt/gnome/guile"
   "Install location for GNOME-related Scheme files")
  (local
   "/usr/local/share/guile"
   "Version-independent non-distribution-managed Scheme files")
  (local-1.6
   "/usr/local/share/guile/1.6"
   "1.6-dependent non-distribution-managed Scheme files")))


;; 2. Guile's startup logic
;;
;; Normal location of config.scm is hardcoded into Guile, based on the
;; setting of $sysconfdir at ./configure time.
;;
;; This location can be overridden at runtime by a --config=FILE
;; option (which we need to add).  This will be needed by
;; pre-inst-guile (during a Guile build), for example.
;;
;; Guile will abort if config.scm is not found, or cannot be read, or
;; there are any errors in the format of the information in it.
;;
;; Otherwise, Guile sets %load-path to:
;;
;;     (map cadr (cddr (assq 'load-path config)))
;;
;; (but in C code, not in Scheme).
;;
;; Thereafter %load-path is used as presently for the loading of
;; boot-9.scm, init.scm and so on.


;; 3. Code for guile-config add-load-path TAG DIRECTORY DESCRIPTION
;;
;; (To be integrated into guile-config, and will in practice need
;; error handling.)

(define (add-load-path tag directory description)
  (let* ((config (with-input-from-file %sys-config-file read))
         (load-path-info (assq 'load-path config)))
    (set-cdr! load-path-info
              (append! (cdr load-path-info)
                       (list (list tag
                                   directory
                                   description))))
    (with-output-to-file %sys-config-file
      (lambda ()
        (pretty-print config)))))


;; 4. Code for guile-config get-load-path ARG
;;
;; Where ARG is the string that was given to --with-guile-scheme-dir,
;; or an empty string if --with-guile-scheme-dir was not used.
;;
;; (To be integrated into guile-config, and will in practice need
;; error handling.)

(define (get-load-path arg)
  ;; If ARG begins with "/", use it directly.
  (if (and (>= (string-length arg) 1)
           (char=? (string-ref arg 0) #\/))
      arg
      ;; Otherwise we need to read config.
      (let* ((config (with-input-from-file %sys-config-file read))
             (load-path-info (assq 'load-path config))
             (tag (if (zero? (string-length arg))
                      ;; Use the default tag.
                      (cadr load-path-info)
                      ;; ARG should be a tag.
                      (string->symbol arg))))
        ;; Return the directory for the chosen tag.
        (cadr (assq tag (cddr load-path-info))))))


;; 5. Code for GUILE_SCHEME_DIR autoconf macro
;;
;; To be written, with these features/requirements:
;;
;; - Will check for a --with-guile-scheme-dir=ARG option.
;;
;; - Will use `guile-config get-load-path ARG` to get the appropriate
;; install directory.
;;
;; - Will NOT take a default-tag argument (in configure.in) as I
;; suggested before, because there is no way for the package author to
;; know what tags will be available on the distribution(s) where the
;; package is built.
;;
;; - Should fall back to other sensible mechanisms if `guile-config
;; get-load-path ARG` is not available.
;;
;;   + Recent Guile distributions have the GUILE_SITE_DIR macro.  In
;;   my view this is better than nothing, but it feels wrong for Guile
;;   package code to go under .../site.  So my preference if using
;;   GUILE_SITE_DIR would be to install to ${GUILE_SITE_DIR}/..
;;
;;   + One could run Guile to discover its %load-path, and decide
;;   heuristically which of those directories to install under.
;;
;;   + Note that there's no point in falling back to
;;   $prefix/share/guile, because if the package author wanted that
;;   they could have specified that directly instead of using
;;   GUILE_SCHEME_DIR.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]