diff --git a/asdf.lisp b/asdf.lisp index c328d72..0e605b2 100755 --- a/asdf.lisp +++ b/asdf.lisp @@ -348,6 +348,7 @@ ;; Utilities #:absolute-pathname-p + #:call-with-package-renamings ;; #:aif #:it ;; #:appendf #:coerce-name @@ -2250,6 +2251,36 @@ recursive calls to traverse.") (defmethod perform :after ((operation operation) (c component)) (mark-operation-done operation c)) +(defun set-renamings (renamings) + (let ((saved-nicknames nil)) + (loop for rename-entry in renamings + do (let* ((package (first rename-entry)) + (rename-def (second rename-entry)) + (old-nicknames (package-nicknames package)) + (new-nicknames (union old-nicknames + (if (listp rename-def) + rename-def + (list rename-def)) + :test #'string-equal))) + (push (list package old-nicknames) saved-nicknames) + (rename-package package package new-nicknames))) + saved-nicknames)) + +(defun clear-renamings (saved-renamings) + (loop for rename-entry in saved-renamings + do (let ((package (first rename-entry))) + (rename-package package package (second rename-entry))))) + +(defmacro call-with-package-renamings (renamings &body body) + "Apply package RENAMINGS around BODY. The specified package nicknames + should not cause any conflicts, otherwise the consequences are the same + as for the RENAME-PACKAGE function." + (let ((saved-renamings (gensym))) + `(let ((,saved-renamings (set-renamings ',renamings))) + (unwind-protect + (progn ,@body) + (clear-renamings ,saved-renamings))))) + (defgeneric* call-with-around-compile-hook (component thunk)) (defgeneric* around-compile-hook (component))