Newer
Older
;;; -*- mode: Common-Lisp; Base: 10 ; Syntax: ANSI-Common-Lisp -*-
Francois-Rene Rideau
committed
;;; This is ASDF 2.20.4: Another System Definition Facility.
Daniel Barlow
committed
;;;
Francois-Rene Rideau
committed
;;; Feedback, bug reports, and patches are all welcome:
;;; please mail to <asdf-devel@common-lisp.net>.
;;; Note first that the canonical source for ASDF is presently
Francois-Rene Rideau
committed
;;; <URL:http://common-lisp.net/project/asdf/>.
Daniel Barlow
committed
;;;
;;; If you obtained this copy from anywhere else, and you experience
;;; trouble using it, or find bugs, you may want to check at the
;;; location above for a more recent version (and for documentation
;;; and test files, if your copy came without them) before reporting
Francois-Rene Rideau
committed
;;; bugs. There are usually two "supported" revisions - the git master
;;; branch is the latest development version, whereas the git release
;;; branch may be slightly older but is considered `stable'
Daniel Barlow
committed
;;; (This is the MIT / X Consortium license as taken from
;;; http://www.opensource.org/licenses/mit-license.html on or about
;;; Monday; July 13, 2009)
;;;
;;; Copyright (c) 2001-2011 Daniel Barlow and contributors
Daniel Barlow
committed
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining
;;; a copy of this software and associated documentation files (the
;;; "Software"), to deal in the Software without restriction, including
;;; without limitation the rights to use, copy, modify, merge, publish,
;;; distribute, sublicense, and/or sell copies of the Software, and to
;;; permit persons to whom the Software is furnished to do so, subject to
;;; the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
;;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
;;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
;;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Daniel Barlow
committed
;;; The problem with writing a defsystem replacement is bootstrapping:
;;; we can't use defsystem to compile it. Hence, all in one file.
(cl:in-package #-genera :common-lisp-user #+genera :future-common-lisp-user)
#-(or abcl allegro clisp clozure cmu cormanlisp ecl gcl genera lispworks mcl sbcl scl xcl)
(error "ASDF is not supported on your implementation. Please help us port it.")
;;;; Create and setup packages in a way that is compatible with hot-upgrade.
;;;; See https://bugs.launchpad.net/asdf/+bug/485687
;;;; See these two eval-when forms, and more near the end of the file.
Francois-Rene Rideau
committed
#+gcl (defpackage :asdf (:use :cl)) ;; GCL treats defpackage magically and needs this
(eval-when (:load-toplevel :compile-toplevel :execute)
;;; Before we do anything, some implementation-dependent tweaks
;; (declaim (optimize (speed 1) (debug 3) (safety 3))) ; NO: trust implementation defaults.
Francois-Rene Rideau
committed
#+allegro
(setf excl::*autoload-package-name-alist*
(remove "asdf" excl::*autoload-package-name-alist*
:test 'equalp :key 'car)) ; need that BEFORE any mention of package ASDF as below
#+gcl ;; Debian's GCL 2.7 has bugs with compiling multiple-value stuff, but can run ASDF 2.011
(when (or (< system::*gcl-major-version* 2) ;; GCL 2.6 fails to fully compile ASDF at all
(and (= system::*gcl-major-version* 2)
(< system::*gcl-minor-version* 7)))
(pushnew :gcl-pre2.7 *features*))
;;; make package if it doesn't exist yet.
;;; DEFPACKAGE may cause errors on discrepancies, so we avoid it.
(unless (find-package :asdf)
(make-package :asdf :use '(:common-lisp))))
(eval-when (:load-toplevel :compile-toplevel :execute)
;;; This would belong amongst implementation-dependent tweaks above,
;;; except that the defun has to be asdf.
#+ecl (defun use-ecl-byte-compiler-p () (and (member :ecl-bytecmp *features*) t))
#+ecl (unless (use-ecl-byte-compiler-p) (require :cmp))
;;; Package setup, step 2.
(defvar *asdf-version* nil)
(defvar *upgraded-p* nil)
(defvar *asdf-verbose* nil) ; was t from 2.000 to 2.014.12.
(defun find-symbol* (s p)
(find-symbol (string s) p))
;; Strip out formatting that is not supported on Genera.
;; Has to be inside the eval-when to make Lispworks happy (!)
(defun strcat (&rest strings)
(apply 'concatenate 'string strings))
(defmacro compatfmt (format)
#-(or gcl genera) format
#+(or gcl genera)
(loop :for (unsupported . replacement) :in
(append
'(("~3i~_" . ""))
#+genera '(("~@<" . "") ("; ~@;" . "; ") ("~@:>" . "") ("~:>" . ""))) :do
(loop :for found = (search unsupported format) :while found :do
(setf format (strcat (subseq format 0 found) replacement
(subseq format (+ found (length unsupported)))))))
(let* (;; For bug reporting sanity, please always bump this version when you modify this file.
;; Please also modify asdf.asd to reflect this change. The script bin/bump-version
;; can help you do these changes in synch (look at the source for documentation).
Francois-Rene Rideau
committed
;; Relying on its automation, the version is now redundantly present on top of this file.
;; "2.345" would be an official release
;; "2.345.6" would be a development version in the official upstream
Francois-Rene Rideau
committed
;; "2.345.0.7" would be your seventh local modification of official release 2.345
;; "2.345.6.7" would be your seventh local modification of development version 2.345.6
Francois-Rene Rideau
committed
(asdf-version "2.20.4")
(existing-asdf (find-class 'component nil))
(existing-version *asdf-version*)
(already-there (equal asdf-version existing-version)))
(unless (and existing-asdf already-there)
(when (and existing-asdf *asdf-verbose*)
(format *trace-output*
(compatfmt "~&~@<; ~@;Upgrading ASDF ~@[from version ~A ~]to version ~A~@:>~%")
existing-version asdf-version))
((present-symbol-p (symbol package)
(member (nth-value 1 (find-symbol* symbol package)) '(:internal :external)))
(present-symbols (package)
;; #-genera (loop :for s :being :the :present-symbols :in package :collect s) #+genera
(let (l)
(do-symbols (s package)
(when (present-symbol-p s package) (push s l)))
(reverse l)))
(unlink-package (package)
Francois-Rene Rideau
committed
(let ((u (find-package package)))
(when u
(ensure-unintern u (present-symbols u))
Francois-Rene Rideau
committed
(loop :for p :in (package-used-by-list u) :do
(unuse-package u p))
(delete-package u))))
Francois-Rene Rideau
committed
(let ((previous
(remove-duplicates
(mapcar #'find-package (cons name nicknames))
:from-end t)))
;; do away with packages with conflicting (nick)names
(map () #'unlink-package (cdr previous))
;; reuse previous package with same name
(let ((p (car previous)))
(cond
(p
(rename-package p name nicknames)
(ensure-use p use)
Francois-Rene Rideau
committed
p)
(t
(make-package name :nicknames nicknames :use use))))))
(intern* (symbol package)
(intern (string symbol) package))
(remove-symbol (symbol package)
(let ((sym (find-symbol* symbol package)))
#-cormanlisp (unexport sym package)
(unintern sym package)
sym)))
(loop :with packages = (list-all-packages)
:for sym :in symbols
:for removed = (remove-symbol sym package)
:when removed :do
(loop :for p :in packages :do
(unintern removed p)))))
(ensure-shadow (package symbols)
(shadow symbols package))
(ensure-use (package use)
(dolist (used (reverse use))
(do-external-symbols (sym used)
(unless (eq sym (find-symbol* sym package))
(remove-symbol sym package)))
(use-package used package)))
(ensure-fmakunbound (package symbols)
(loop :for name :in symbols
:when sym :do (fmakunbound sym)))
(ensure-export (package export)
(let ((formerly-exported-symbols nil)
(bothly-exported-symbols nil)
(newly-exported-symbols nil))
(do-external-symbols (sym package)
(if (member sym export :test 'string-equal)
(push sym bothly-exported-symbols)
(push sym formerly-exported-symbols)))
(loop :for sym :in export :do
(unless (member sym bothly-exported-symbols :test 'equal)
(push sym newly-exported-symbols)))
(loop :for user :in (package-used-by-list package)
:for shadowing = (package-shadowing-symbols user) :do
(loop :for new :in newly-exported-symbols
:when (and old (not (member old shadowing)))
:do (unintern old user)))
(loop :for x :in newly-exported-symbols :do
(export (intern* x package)))))
Francois-Rene Rideau
committed
(ensure-package (name &key nicknames use unintern
shadow export redefined-functions)
(let* ((p (ensure-exists name nicknames use)))
(ensure-unintern p unintern)
(ensure-shadow p shadow)
(ensure-export p export)
Francois-Rene Rideau
committed
(ensure-fmakunbound p redefined-functions)
p)))
(macrolet
((pkgdcl (name &key nicknames use export
Francois-Rene Rideau
committed
redefined-functions unintern shadow)
Francois-Rene Rideau
committed
`(ensure-package
',name :nicknames ',nicknames :use ',use :export ',export
:shadow ',shadow
Francois-Rene Rideau
committed
:unintern ',unintern
Francois-Rene Rideau
committed
:redefined-functions ',redefined-functions)))
Francois-Rene Rideau
committed
:nicknames (:asdf-utilities) ;; DEPRECATED! Do not use, for backward compatibility only.
:redefined-functions
(#:perform #:explain #:output-files #:operation-done-p
#:perform-with-restarts #:component-relative-pathname
Francois-Rene Rideau
committed
#:system-source-file #:operate #:find-component #:find-system
#:apply-output-translations #:translate-pathname* #:resolve-location
Francois-Rene Rideau
committed
#:system-relative-pathname
#:inherit-source-registry #:process-source-registry
#:process-source-registry-directive
#:compile-file* #:source-file-type)
:unintern
(#:*asdf-revision* #:around #:asdf-method-combination
#:split #:make-collector #:do-dep #:do-one-dep
Francois-Rene Rideau
committed
#:resolve-relative-location-component #:resolve-absolute-location-component
#:output-files-for-system-and-operation) ; obsolete ASDF-BINARY-LOCATION function
(#:defsystem #:oos #:operate #:find-system #:locate-system #:run-shell-command
Francois-Rene Rideau
committed
#:system-definition-pathname #:with-system-definitions
#:search-for-system-definition #:find-component #:component-find-path
#:compile-system #:load-system #:load-systems #:test-system #:clear-system
#:operation #:compile-op #:load-op #:load-source-op #:test-op
#:feature #:version #:version-satisfies
#:upgrade-asdf
Francois-Rene Rideau
committed
#:implementation-identifier #:implementation-type
#:input-files #:output-files #:output-file #:perform
#:operation-done-p #:explain
#:component #:source-file
#:c-source-file #:cl-source-file #:java-source-file
#:cl-source-file.cl #:cl-source-file.lsp
#:static-file
#:doc-file
#:html-file
#:text-file
#:source-file-type
#:module ; components
#:system
#:unix-dso
#:module-components ; component accessors
#:module-components-by-name ; component accessors
#:component-pathname
#:component-relative-pathname
#:component-name
#:component-version
#:component-parent
#:component-property
#:component-system
#:*utf-8-external-format*
Francois-Rene Rideau
committed
#:component-encoding
#:*encoding-external-format-hook*
#:component-depends-on
#:system-description
#:system-long-description
#:system-author
#:system-maintainer
#:system-license
#:system-licence
#:system-source-file
#:system-source-directory
#:system-relative-pathname
#:map-systems
#:operation-on-warnings
#:operation-on-failure
;;#:*component-parent-pathname*
#:*system-definition-search-functions*
#:*central-registry* ; variables
#:*compile-file-warnings-behaviour*
#:*compile-file-failure-behaviour*
#:*resolve-symlinks*
#:*require-asdf-operator*
#:asdf-version
#:operation-error #:compile-failed #:compile-warned #:compile-error
#:error-name
#:error-pathname
#:load-system-definition-error
#:error-component #:error-operation
#:system-definition-error
#:missing-component
#:missing-component-of-version
#:missing-dependency
#:missing-dependency-of-version
#:circular-dependency ; errors
#:duplicate-names
#:try-recompiling
#:retry
#:accept ; restarts
#:coerce-entry-to-directory
#:remove-entry-from-registry
#:clear-configuration
#:*output-translations-parameter*
#:initialize-output-translations
#:disable-output-translations
#:clear-output-translations
#:ensure-output-translations
#:apply-output-translations
#:compile-file*
#:compile-file-pathname*
#:enable-asdf-binary-locations-compatibility
#:*default-source-registries*
#:*source-registry-parameter*
#:initialize-source-registry
#:compute-source-registry
#:clear-source-registry
#:ensure-source-registry
#:system-registered-p
#:asdf-message
Francois-Rene Rideau
committed
#:user-output-translations-pathname
#:system-output-translations-pathname
#:user-output-translations-directory-pathname
#:system-output-translations-directory-pathname
#:user-source-registry
#:system-source-registry
#:user-source-registry-directory
#:system-source-registry-directory
Gary King
committed
;; Utilities
#:absolute-pathname-p
;; #:aif #:it
;; #:appendf #:orf
#:coerce-name
#:directory-pathname-p
#:ensure-directory-pathname
#:getenv
;; #:find-symbol*
#:merge-pathnames* #:coerce-pathname #:subpathname
#:pathname-directory-pathname
#:read-file-forms
;; #:remove-keys
;; #:remove-keyword
#:resolve-symlinks
#:split-string
#:component-name-to-pathname-components
#:split-name-type
Francois-Rene Rideau
committed
#:subdirectories
#:truenamize
#:while-collecting)))
#+genera (import 'scl:boolean :asdf)
(setf *asdf-version* asdf-version
*upgraded-p* (if existing-version
(cons existing-version *upgraded-p*)
*upgraded-p*))))))
Francois-Rene Rideau
committed
;;;; -------------------------------------------------------------------------
;;;; User-visible parameters
;;;;
(defvar *resolve-symlinks* t
"Determine whether or not ASDF resolves symlinks when defining systems.
Francois-Rene Rideau
committed
Defaults to T.")
Francois-Rene Rideau
committed
(defvar *compile-file-warnings-behaviour*
(or #+clisp :ignore :warn)
"How should ASDF react if it encounters a warning when compiling a file?
Valid values are :error, :warn, and :ignore.")
Francois-Rene Rideau
committed
(defvar *compile-file-failure-behaviour*
(or #+sbcl :error #+clisp :ignore :warn)
"How should ASDF react if it encounters a failure (per the ANSI spec of COMPILE-FILE)
when compiling a file? Valid values are :error, :warn, and :ignore.
Note that ASDF ALWAYS raises an error if it fails to create an output file when compiling.")
(defvar *verbose-out* nil)
Daniel Barlow
committed
Gary King
committed
(defparameter +asdf-methods+
Francois-Rene Rideau
committed
'(perform-with-restarts perform explain output-files operation-done-p))
Gary King
committed
#+allegro
(eval-when (:compile-toplevel :execute)
(defparameter *acl-warn-save*
(when (boundp 'excl:*warn-on-nested-reader-conditionals*)
excl:*warn-on-nested-reader-conditionals*))
(when (boundp 'excl:*warn-on-nested-reader-conditionals*)
(setf excl:*warn-on-nested-reader-conditionals* nil)))
;;;; -------------------------------------------------------------------------
;;;; Resolve forward references
(declaim (ftype (function (t) t)
format-arguments format-control
error-name error-pathname error-condition
duplicate-names-name
error-component error-operation
module-components module-components-by-name
circular-dependency-components
condition-arguments condition-form
condition-format condition-location
coerce-name)
Francois-Rene Rideau
committed
(ftype (function (&optional t) (values)) initialize-source-registry)
#-(or cormanlisp gcl-pre2.7)
(ftype (function (t t) t) (setf module-components-by-name)))
;;;; -------------------------------------------------------------------------
;;;; Compatibility various implementations
#+cormanlisp
(progn
(deftype logical-pathname () nil)
(defun make-broadcast-stream () *error-output*)
(defun file-namestring (p)
(format nil "~@[~A~]~@[.~A~]" (pathname-name p) (pathname-type p))))
#.(or #+mcl ;; the #$ doesn't work on other lisps, even protected by #+mcl
(read-from-string
"(eval-when (:compile-toplevel :load-toplevel :execute)
(ccl:define-entry-point (_getenv \"getenv\") ((name :string)) :string)
(ccl:define-entry-point (_system \"system\") ((name :string)) :int)
;; Note: ASDF may expect user-homedir-pathname to provide
;; the pathname of the current user's home directory, whereas
;; MCL by default provides the directory from which MCL was started.
;; See http://code.google.com/p/mcl/wiki/Portability
(defun current-user-homedir-pathname ()
(ccl::findfolder #$kuserdomain #$kCurrentUserFolderType))
(defun probe-posix (posix-namestring)
\"If a file exists for the posix namestring, return the pathname\"
(ccl::with-cstrs ((cpath posix-namestring))
(ccl::rlet ((is-dir :boolean)
(fsref :fsref))
(when (eq #$noerr (#_fspathmakeref cpath fsref is-dir))
(ccl::%path-from-fsref fsref is-dir))))))"))
;;;; -------------------------------------------------------------------------
;;;; General Purpose Utilities
(macrolet
((defdef (def* def)
`(defmacro ,def* (name formals &rest rest)
`(progn
#+(or ecl (and gcl (not gcl-pre2.7))) (fmakunbound ',name)
#-gcl ; gcl 2.7.0 notinline functions lose secondary return values :-(
,(when (and #+ecl (symbolp name)) ; fails for setf functions on ecl
`(declaim (notinline ,name)))
(,',def ,name ,formals ,@rest)))))
(defdef defgeneric* defgeneric)
(defdef defun* defun))
Francois-Rene Rideau
committed
(defmacro while-collecting ((&rest collectors) &body body)
"COLLECTORS should be a list of names for collections. A collector
defines a function that, when applied to an argument inside BODY, will
add its argument to the corresponding collection. Returns multiple values,
a list for each collection, in order.
E.g.,
\(while-collecting \(foo bar\)
\(dolist \(x '\(\(a 1\) \(b 2\) \(c 3\)\)\)
\(foo \(first x\)\)
\(bar \(second x\)\)\)\)
Returns two values: \(A B C\) and \(1 2 3\)."
(let ((vars (mapcar #'(lambda (x) (gensym (symbol-name x))) collectors))
(initial-values (mapcar (constantly nil) collectors)))
`(let ,(mapcar #'list vars initial-values)
(flet ,(mapcar #'(lambda (c v) `(,c (x) (push x ,v) (values))) collectors vars)
,@body
(values ,@(mapcar #'(lambda (v) `(reverse ,v)) vars))))))
(defmacro aif (test then &optional else)
`(let ((it ,test)) (if it ,then ,else)))
(defun* pathname-directory-pathname (pathname)
"Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
and NIL NAME, TYPE and VERSION components"
Francois-Rene Rideau
committed
(when pathname
(make-pathname :name nil :type nil :version nil :defaults pathname)))
(defun* normalize-pathname-directory-component (directory)
(cond
#-(or cmu sbcl scl)
((stringp directory) `(:absolute ,directory) directory)
#+gcl
((and (consp directory) (stringp (first directory)))
`(:absolute ,@directory))
((or (null directory)
(and (consp directory) (member (first directory) '(:absolute :relative))))
directory)
(t
(error (compatfmt "~@<Unrecognized pathname directory component ~S~@:>") directory))))
(defun* merge-pathname-directory-components (specified defaults)
(let ((directory (normalize-pathname-directory-component specified)))
(ecase (first directory)
((nil) defaults)
(:absolute specified)
(:relative
(let ((defdir (normalize-pathname-directory-component defaults))
(reldir (cdr directory)))
(cond
((null defdir)
directory)
((not (eq :back (first reldir)))
(append defdir reldir))
(t
(loop :with defabs = (first defdir)
:with defrev = (reverse (rest defdir))
:while (and (eq :back (car reldir))
(or (and (eq :absolute defabs) (null defrev))
(stringp (car defrev))))
:do (pop reldir) (pop defrev)
:finally (return (cons defabs (append (reverse defrev) reldir)))))))))))
(defun* ununspecific (x)
(if (eq x :unspecific) nil x))
(defun* merge-pathnames* (specified &optional (defaults *default-pathname-defaults*))
"MERGE-PATHNAMES* is like MERGE-PATHNAMES except that
if the SPECIFIED pathname does not have an absolute directory,
then the HOST and DEVICE both come from the DEFAULTS, whereas
if the SPECIFIED pathname does have an absolute directory,
then the HOST and DEVICE both come from the SPECIFIED.
Also, if either argument is NIL, then the other argument is returned unmodified."
(when (null specified) (return-from merge-pathnames* defaults))
(when (null defaults) (return-from merge-pathnames* specified))
#+scl
(ext:resolve-pathname specified defaults)
#-scl
(let* ((specified (pathname specified))
(defaults (pathname defaults))
(directory (normalize-pathname-directory-component (pathname-directory specified)))
(name (or (pathname-name specified) (pathname-name defaults)))
(type (or (pathname-type specified) (pathname-type defaults)))
(version (or (pathname-version specified) (pathname-version defaults))))
(labels ((unspecific-handler (p)
Francois-Rene Rideau
committed
(if (typep p 'logical-pathname) #'ununspecific #'identity)))
(multiple-value-bind (host device directory unspecific-handler)
Francois-Rene Rideau
committed
(ecase (first directory)
Francois-Rene Rideau
committed
((:absolute)
(values (pathname-host specified)
(pathname-device specified)
directory
(unspecific-handler specified)))
Francois-Rene Rideau
committed
(values (pathname-host defaults)
(pathname-device defaults)
(merge-pathname-directory-components directory (pathname-directory defaults))
Francois-Rene Rideau
committed
(unspecific-handler defaults))))
(make-pathname :host host :device device :directory directory
:name (funcall unspecific-handler name)
:type (funcall unspecific-handler type)
:version (funcall unspecific-handler version))))))
(defun* pathname-parent-directory-pathname (pathname)
"Returns a new pathname with same HOST, DEVICE, DIRECTORY as PATHNAME,
and NIL NAME, TYPE and VERSION components"
(when pathname
(make-pathname :name nil :type nil :version nil
:directory (merge-pathname-directory-components
'(:relative :back) (pathname-directory pathname))
:defaults pathname)))
(define-modify-macro appendf (&rest args)
append "Append onto list") ;; only to be used on short lists.
(define-modify-macro orf (&rest args)
or "or a flag")
(defun* first-char (s)
Francois-Rene Rideau
committed
(and (stringp s) (plusp (length s)) (char s 0)))
(defun* last-char (s)
Francois-Rene Rideau
committed
(and (stringp s) (plusp (length s)) (char s (1- (length s)))))
(defun* asdf-message (format-string &rest format-args)
(declare (dynamic-extent format-args))
(apply 'format *verbose-out* format-string format-args))
(defun* split-string (string &key max (separator '(#\Space #\Tab)))
Francois-Rene Rideau
committed
"Split STRING into a list of components separated by
any of the characters in the sequence SEPARATOR.
If MAX is specified, then no more than max(1,MAX) components will be returned,
starting the separation from the end, e.g. when called with arguments
\"a.b.c.d.e\" :max 3 :separator \".\" it will return (\"a.b.c\" \"d\" \"e\")."
(let ((list nil) (words 0) (end (length string)))
(flet ((separatorp (char) (find char separator))
(done () (throw nil (cons (subseq string 0 end) list))))
(loop
:for start = (if (and max (>= words (1- max)))
(done)
(position-if #'separatorp string :end end :from-end t)) :do
(when (null start)
(done))
(push (subseq string (1+ start) end) list)
(incf words)
(setf end start))))))
(defun* split-name-type (filename)
Francois-Rene Rideau
committed
(let ((unspecific
;; Giving :unspecific as argument to make-pathname is not portable.
;; See CLHS make-pathname and 19.2.2.2.3.
;; We only use it on implementations that support it.
(or #+(or clozure gcl lispworks sbcl) :unspecific)))
(destructuring-bind (name &optional (type unspecific))
(split-string filename :max 2 :separator ".")
(if (equal name "")
(values filename unspecific)
(values name type)))))
Francois-Rene Rideau
committed
Francois-Rene Rideau
committed
(defun* component-name-to-pathname-components (s &key force-directory force-relative)
"Splits the path string S, returning three values:
A flag that is either :absolute or :relative, indicating
how the rest of the values are to be interpreted.
A directory path --- a list of strings, suitable for
use with MAKE-PATHNAME when prepended with the flag
value.
A filename with type extension, possibly NIL in the
case of a directory pathname.
FORCE-DIRECTORY forces S to be interpreted as a directory
pathname \(third return value will be NIL, final component
of S will be treated as part of the directory path.
The intention of this function is to support structured component names,
e.g., \(:file \"foo/bar\"\), which will be unpacked to relative
pathnames."
Francois-Rene Rideau
committed
(when (find #\: s)
(error (compatfmt "~@<A portable ASDF pathname designator cannot include a #\: character: ~3i~_~S~@:>") s))
(let* ((components (split-string s :separator "/"))
(last-comp (car (last components))))
(multiple-value-bind (relative components)
(if (equal (first components) "")
(if (equal (first-char s) #\/)
Francois-Rene Rideau
committed
(progn
(when force-relative
(error (compatfmt "~@<Absolute pathname designator not allowed: ~3i~_~S~@:>") s))
Francois-Rene Rideau
committed
(values :absolute (cdr components)))
(values :relative nil))
(values :relative components))
(setf components (remove-if #'(lambda (x) (member x '("" ".") :test #'equal)) components))
(setf components (substitute :back ".." components :test #'equal))
(cond
((equal last-comp "")
(values relative components nil)) ; "" already removed
(force-directory
(values relative components nil))
(t
(values relative (butlast components) last-comp))))))
(defun* remove-keys (key-names args)
(loop :for (name val) :on args :by #'cddr
:unless (member (symbol-name name) key-names
:key #'symbol-name :test 'equal)
:append (list name val)))
(defun* remove-keyword (key args)
(loop :for (k v) :on args :by #'cddr
:unless (eq k key)
:append (list k v)))
Francois-Rene Rideau
committed
(defun* getenv (x)
(declare (ignorable x))
#+(or abcl clisp ecl xcl) (ext:getenv x)
#+allegro (sys:getenv x)
#+clozure (ccl:getenv x)
#+(or cmu scl) (cdr (assoc x ext:*environment-list* :test #'string=))
#+cormanlisp
(let* ((buffer (ct:malloc 1))
(cname (ct:lisp-string-to-c-string x))
(needed-size (win:getenvironmentvariable cname buffer 0))
(buffer1 (ct:malloc (1+ needed-size))))
(prog1 (if (zerop (win:getenvironmentvariable cname buffer1 needed-size))
nil
(ct:c-string-to-lisp-string buffer1))
(ct:free buffer)
(ct:free buffer1)))
#+gcl (system:getenv x)
#+genera nil
#+lispworks (lispworks:environment-variable x)
#+mcl (ccl:with-cstrs ((name x))
(let ((value (_getenv name)))
(unless (ccl:%null-ptr-p value)
(ccl:%get-cstring value))))
#+sbcl (sb-ext:posix-getenv x)
#-(or abcl allegro clisp clozure cmu cormanlisp ecl gcl genera lispworks mcl sbcl scl xcl)
(error "~S is not supported on your implementation" 'getenv))
(defun* directory-pathname-p (pathname)
Francois-Rene Rideau
committed
"Does PATHNAME represent a directory?
A directory-pathname is a pathname _without_ a filename. The three
Francois-Rene Rideau
committed
ways that the filename components can be missing are for it to be NIL,
:UNSPECIFIC or the empty string.
Francois-Rene Rideau
committed
Note that this does _not_ check to see that PATHNAME points to an
Francois-Rene Rideau
committed
(when pathname
(let ((pathname (pathname pathname)))
(flet ((check-one (x)
(member x '(nil :unspecific "") :test 'equal)))
(and (not (wild-pathname-p pathname))
(check-one (pathname-name pathname))
(check-one (pathname-type pathname))
t)))))
(defun* ensure-directory-pathname (pathspec)
"Converts the non-wild pathname designator PATHSPEC to directory form."
Francois-Rene Rideau
committed
(cond
((stringp pathspec)
(ensure-directory-pathname (pathname pathspec)))
Francois-Rene Rideau
committed
((not (pathnamep pathspec))
(error (compatfmt "~@<Invalid pathname designator ~S~@:>") pathspec))
Francois-Rene Rideau
committed
((wild-pathname-p pathspec)
(error (compatfmt "~@<Can't reliably convert wild pathname ~3i~_~S~@:>") pathspec))
Francois-Rene Rideau
committed
((directory-pathname-p pathspec)
pathspec)
(t
(make-pathname :directory (append (or (pathname-directory pathspec)
(list :relative))
(list (file-namestring pathspec)))
:name nil :type nil :version nil
:defaults pathspec))))
#+genera
(unless (fboundp 'ensure-directories-exist)
(defun* ensure-directories-exist (path)
(fs:create-directories-recursively (pathname path))))
(defun* absolute-pathname-p (pathspec)
(and (typep pathspec '(or pathname string))
(eq :absolute (car (pathname-directory (pathname pathspec))))))
Francois-Rene Rideau
committed
(defun* length=n-p (x n) ;is it that (= (length x) n) ?
Francois-Rene Rideau
committed
(check-type n (integer 0 *))
(loop
:for l = x :then (cdr l)
:for i :downfrom n :do
(cond
((zerop i) (return (null l)))
((not (consp l)) (return nil)))))
(defun* ends-with (s suffix)
Francois-Rene Rideau
committed
(check-type s string)
(check-type suffix string)
(let ((start (- (length s) (length suffix))))
(and (<= 0 start)
(string-equal s suffix :start1 start))))
(defun* read-file-forms (file)
Francois-Rene Rideau
committed
(with-open-file (in file)
(loop :with eof = (list nil)
:for form = (read in nil eof)
:until (eq form eof)
:collect form)))
(defun* pathname-root (pathname)
Francois-Rene Rideau
committed
(make-pathname :directory '(:absolute)
:name nil :type nil :version nil
:defaults pathname ;; host device, and on scl, *some*
;; scheme-specific parts: port username password, not others:
Francois-Rene Rideau
committed
. #.(or #+scl '(:parameters nil :query nil :fragment nil))))
Francois-Rene Rideau
committed
(defun* probe-file* (p)
Francois-Rene Rideau
committed
"when given a pathname P, probes the filesystem for a file or directory
with given pathname and if it exists return its truename."
(null nil)
(string (probe-file* (parse-namestring p)))
(pathname (unless (wild-pathname-p p)
#.(or #+(or allegro clozure cmu cormanlisp ecl lispworks sbcl scl)
'(probe-file p)
#+clisp (aif (find-symbol* '#:probe-pathname :ext)
`(ignore-errors (,it p)))
'(ignore-errors (truename p)))))))
Francois-Rene Rideau
committed
(defun* truenamize (pathname &optional (defaults *default-pathname-defaults*))
Francois-Rene Rideau
committed
"Resolve as much of a pathname as possible"
(block nil
(when (typep pathname '(or null logical-pathname)) (return pathname))
(let ((p (merge-pathnames* pathname defaults)))
(when (typep p 'logical-pathname) (return p))
Francois-Rene Rideau
committed
(let ((found (probe-file* p)))
(when found (return found)))
(unless (absolute-pathname-p p)
(let ((true-defaults (ignore-errors (truename defaults))))
(when true-defaults
(setf p (merge-pathnames pathname true-defaults)))))
(unless (absolute-pathname-p p) (return p))
Francois-Rene Rideau
committed
(let ((sofar (probe-file* (pathname-root p))))
(unless sofar (return p))
(flet ((solution (directories)
(merge-pathnames*
(make-pathname :host nil :device nil
:directory `(:relative ,@directories)
:name (pathname-name p)
:type (pathname-type p)
:version (pathname-version p))
(loop :with directory = (normalize-pathname-directory-component
(pathname-directory p))
:for component :in (cdr directory)
Francois-Rene Rideau
committed
:for more = (probe-file*
(merge-pathnames*
(make-pathname :directory `(:relative ,component))
sofar)) :do
(return (solution rest)))
:finally
(return (solution nil))))))))
Francois-Rene Rideau
committed
(defun* resolve-symlinks (path)
Francois-Rene Rideau
committed
#-allegro (truenamize path)
#+allegro (if (typep path 'logical-pathname)
path
(excl:pathname-resolve-symbolic-links path)))
Francois-Rene Rideau
committed
(defun* resolve-symlinks* (path)
(if *resolve-symlinks*
(and path (resolve-symlinks path))
path))
(defun* ensure-pathname-absolute (path)
(cond
((absolute-pathname-p path) path)
((stringp path) (ensure-pathname-absolute (pathname path)))
((not (pathnamep path)) (error "not a valid pathname designator ~S" path))
(t (let ((resolved (resolve-symlinks path)))
(assert (absolute-pathname-p resolved))
resolved))))
(defun* default-directory ()
Francois-Rene Rideau
committed
(truenamize (pathname-directory-pathname *default-pathname-defaults*)))
(defun* lispize-pathname (input-file)
(make-pathname :type "lisp" :defaults input-file))
(defparameter *wild* #-cormanlisp :wild #+cormanlisp "*")
Francois-Rene Rideau
committed
(defparameter *wild-file*
(make-pathname :name *wild* :type *wild*
:version (or #-(or abcl xcl) *wild*) :directory nil))
Francois-Rene Rideau
committed
(defparameter *wild-directory*
(make-pathname :directory `(:relative ,*wild*) :name nil :type nil :version nil))
Francois-Rene Rideau
committed
(defparameter *wild-inferiors*
(make-pathname :directory '(:relative :wild-inferiors) :name nil :type nil :version nil))
Francois-Rene Rideau
committed
(defparameter *wild-path*
Francois-Rene Rideau
committed
(merge-pathnames *wild-file* *wild-inferiors*))
Francois-Rene Rideau
committed
(defun* wilden (path)
Francois-Rene Rideau
committed
(merge-pathnames* *wild-path* path))
(defun* directory-separator-for-host (&optional (pathname *default-pathname-defaults*))
(let ((foo (make-pathname :directory '(:absolute "FOO") :defaults pathname)))
(last-char (namestring foo))))
(defun* directorize-pathname-host-device (pathname)
Francois-Rene Rideau
committed
(let* ((root (pathname-root pathname))
(wild-root (wilden root))
(absolute-pathname (merge-pathnames* pathname root))
(separator (directory-separator-for-host root))
Francois-Rene Rideau
committed
(root-namestring (namestring root))
(root-string
(substitute-if #\/
#'(lambda (x) (or (eql x #\:)
(eql x separator)))
Francois-Rene Rideau
committed
root-namestring)))
(multiple-value-bind (relative path filename)
Francois-Rene Rideau
committed
(component-name-to-pathname-components root-string :force-directory t)
Francois-Rene Rideau
committed
(declare (ignore relative filename))
(let ((new-base
(make-pathname :defaults root
:directory `(:absolute ,@path))))
(translate-pathname absolute-pathname wild-root (wilden new-base))))))
#+scl
(defun* directorize-pathname-host-device (pathname)
(let ((scheme (ext:pathname-scheme pathname))
(host (pathname-host pathname))
(port (ext:pathname-port pathname))
(directory (pathname-directory pathname)))
(if (or (ununspecific port)
(and (ununspecific host) (plusp (length host)))
(ununspecific scheme))
(let ((prefix ""))
(when (ununspecific port)
(setf prefix (format nil ":~D" port)))
(when (and (ununspecific host) (plusp (length host)))
(setf prefix (strcat host prefix)))
(setf prefix (strcat ":" prefix))
(when (ununspecific scheme)
(setf prefix (strcat scheme prefix)))
(assert (and directory (eq (first directory) :absolute)))
(make-pathname :directory `(:absolute ,prefix ,@(rest directory))
:defaults pathname)))
pathname))
;;;; -------------------------------------------------------------------------
;;;; ASDF Interface, in terms of generic functions.
(defgeneric* find-system (system &optional error-p))
(defgeneric* perform-with-restarts (operation component))
(defgeneric* perform (operation component))
(defgeneric* operation-done-p (operation component))
Francois-Rene Rideau
committed
(defgeneric* mark-operation-done (operation component))
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
(defgeneric* explain (operation component))
(defgeneric* output-files (operation component))
(defgeneric* input-files (operation component))
(defgeneric* component-operation-time (operation component))
(defgeneric* operation-description (operation component)
(:documentation "returns a phrase that describes performing this operation
on this component, e.g. \"loading /a/b/c\".
You can put together sentences using this phrase."))
(defgeneric* system-source-file (system)
(:documentation "Return the source file in which system is defined."))
(defgeneric* component-system (component)
(:documentation "Find the top-level system containing COMPONENT"))
(defgeneric* component-pathname (component)
(:documentation "Extracts the pathname applicable for a particular component."))
(defgeneric* component-relative-pathname (component)
(:documentation "Returns a pathname for the component argument intended to be
interpreted relative to the pathname of that component's parent.
Despite the function's name, the return value may be an absolute
pathname, because an absolute pathname may be interpreted relative to
another pathname in a degenerate way."))
(defgeneric* component-property (component property))
(defgeneric* (setf component-property) (new-value component property))
Francois-Rene Rideau
committed
(defgeneric* component-encoding (component))
Francois-Rene Rideau
committed
(defgeneric* (setf component-encoding) (new-value component))
(eval-when (#-gcl :compile-toplevel :load-toplevel :execute)
(defgeneric* (setf module-components-by-name) (new-value module)))
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(defgeneric* version-satisfies (component version))
(defgeneric* find-component (base path)
(:documentation "Finds the component with PATH starting from BASE module;
if BASE is nil, then the component is assumed to be a system."))
(defgeneric* source-file-type (component system))
(defgeneric* operation-ancestor (operation)
(:documentation
"Recursively chase the operation's parent pointer until we get to
the head of the tree"))
(defgeneric* component-visited-p (operation component)
(:documentation "Returns the value stored by a call to
VISIT-COMPONENT, if that has been called, otherwise NIL.
This value stored will be a cons cell, the first element
of which is a computed key, so not interesting. The
CDR wil be the DATA value stored by VISIT-COMPONENT; recover
it as (cdr (component-visited-p op c)).
In the current form of ASDF, the DATA value retrieved is
effectively a boolean, indicating whether some operations are
to be performed in order to do OPERATION X COMPONENT. If the
data value is NIL, the combination had been explored, but no
operations needed to be performed."))
(defgeneric* visit-component (operation component data)
(:documentation "Record DATA as being associated with OPERATION
and COMPONENT. This is a side-effecting function: the association
will be recorded on the ROOT OPERATION \(OPERATION-ANCESTOR of the
OPERATION\).
No evidence that DATA is ever interesting, beyond just being
non-NIL. Using the data field is probably very risky; if there is
already a record for OPERATION X COMPONENT, DATA will be quietly
discarded instead of recorded.
Starting with 2.006, TRAVERSE will store an integer in data,