script-support.lisp 9.29 KB
Newer Older
1 2 3 4 5
(defpackage :asdf-test
  (:use :common-lisp)
  (:export
   #:*test-directory* #:*asdf-directory*
   #:load-asdf
6
   #:register-directory #:asdf-load
7 8 9 10 11
   #:load-asdf-lisp #:compile-asdf #:load-asdf-fasl #:compile-load-asdf #:load-asdf-system
   #:quit-on-error #:test-asdf
   #:native-namestring
   #:exit-lisp #:leave-lisp
   #:quietly))
12

13
(in-package :asdf-test)
14

15 16
(declaim (optimize (speed 2) (safety 3) #-(or allegro gcl) (debug 3)))
(proclaim '(optimize (speed 2) (safety 3) #-(or allegro gcl) (debug 3)))
17

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
18
;;(format t "Evaluating asdf/test/script-support~%")
19

20
;; We can't use asdf::merge-pathnames* because ASDF isn't loaded yet.
21
;; We still want to work despite and host/device funkiness.
22 23
(defparameter *test-directory*
  (make-pathname :name nil :type nil :version nil
24 25
                 :defaults (or #+gcl (truename system:*load-pathname*)
                               *load-truename* *compile-file-truename*)))
26
(defparameter *asdf-directory*
27 28 29 30
  (truename
   (merge-pathnames
    (make-pathname :directory '(#-gcl :relative #-gcl :back #+gcl :parent) :defaults *test-directory*)
    *test-directory*)))
31 32 33
(defparameter *asdf-lisp*
  (make-pathname :name "asdf" :type "lisp" :defaults *asdf-directory*))
(defparameter *asdf-fasl*
34
  (compile-file-pathname
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
35
   (let ((impl (string-downcase
36 37 38
                (or #+allegro
                    (ecase excl:*current-case-mode*
                      (:case-sensitive-lower :mlisp)
39
                      (:case-insensitive-upper :alisp))
40 41 42 43 44 45 46 47 48
                    #+armedbear :abcl
                    #+clisp :clisp
                    #+clozure :ccl
                    #+cmu :cmucl
                    #+corman :cormanlisp
                    #+digitool :mcl
                    #+ecl :ecl
                    #+gcl :gcl
                    #+lispworks :lispworks
49
		    #+mkcl :mkcl
50
                    #+sbcl :sbcl
51 52
                    #+scl :scl
                    #+xcl :xcl))))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
53
     (merge-pathnames
54
      (make-pathname :directory `(#-gcl :relative "tmp" "fasls" ,impl)
55
                     :defaults *asdf-directory*)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
56
      *asdf-lisp*))))
57

58 59 60
(defun load-old-asdf (tag)
  (let ((old-asdf
          (merge-pathnames
61
           (make-pathname :directory `(#-gcl :relative "tmp")
62 63 64 65 66 67
                          :name (format nil "asdf-~A" tag)
                          :defaults *asdf-directory*)
           *asdf-lisp*)))
    (handler-bind (#+sbcl (sb-kernel:redefinition-warning #'muffle-warning))
      (load old-asdf))))

68 69 70 71 72 73
(defun configure-asdf ()
  (funcall (find-symbol (string :initialize-source-registry) :asdf)
           `(:source-registry :ignore-inherited-configuration))
  (let ((registry (find-symbol (string :*central-registry*) :asdf)))
    (set registry `(,*asdf-directory* ,*test-directory*))))

74
(defun load-asdf ()
75 76
  (load *asdf-fasl*)
  (use-package :asdf :asdf-test)
77 78
  ;;(import 'DBG :asdf)
  (configure-asdf)
79 80
  (setf *package* (find-package :asdf-test)))

81 82 83 84
(defun hash-table->alist (table)
  (loop :for key :being :the :hash-keys :of table :using (:hash-value value)
    :collect (cons key value)))

85 86
(defun common-lisp-user::load-asdf ()
  (load-asdf))
87

88 89 90
#+allegro
(setf excl:*warn-on-nested-reader-conditionals* nil)

91
(defun native-namestring (x)
92
  (let ((p (pathname x)))
93
    #+clozure (ccl:native-translated-namestring p)
94
    #+(or cmu scl) (ext:unix-namestring p nil)
95 96 97
    #+sbcl (sb-ext:native-namestring p)
    #-(or clozure cmu sbcl scl) (namestring p)))

98
;;; code adapted from cl-launch http://www.cliki.net/cl-launch
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
99
(defun exit-lisp (return)
100 101 102 103 104
  #+allegro
  (excl:exit return)
  #+clisp
  (ext:quit return)
  #+(or cmu scl)
105
  (unix:unix-exit return)
106
  #+ecl
107 108
  (si:quit return)
  #+gcl
109
  (lisp:quit return)
110
  #+lispworks
111
  (lispworks:quit :status return :confirm nil :return nil :ignore-errors-p t)
112 113
  #+(or openmcl mcl)
  (ccl::quit return)
114 115
  #+mkcl
  (mk-ext:quit :exit-code return)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
116 117 118 119 120
  #+sbcl #.(let ((exit (find-symbol "EXIT" :sb-ext))
                 (quit (find-symbol "QUIT" :sb-ext)))
             (cond
               (exit `(,exit :code return :abort t))
               (quit `(,quit :unix-status return :recklessly-p t))))
121
  #+(or abcl xcl)
122
  (ext:quit :status return)
123 124
  (error "Don't know how to quit Lisp; wanting to use exit code ~a" return))

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
125 126 127 128 129 130 131 132
(defun leave-lisp (message return)
  (fresh-line *error-output*)
  (when message
    (format *error-output* message)
    (terpri *error-output*))
  (finish-output *error-output*)
  (finish-output *standard-output*)
  (exit-lisp return))
133

134 135 136 137
(defmacro assert-equal (x y)
  `(assert (equal ,x ,y) () "These two expressions are not equal:~% ~S evaluates to ~S~% ~S evaluates to ~S~%"
           ',x ,x ',y ,y))

138
(defmacro quit-on-error (&body body)
139 140 141
  `(call-quitting-on-error (lambda () ,@body)))

(defun call-quitting-on-error (thunk)
142 143 144
  "Unless the environment variable DEBUG_ASDF_TEST
is bound, write a message and exit on an error.  If
*asdf-test-debug* is true, enter the debugger."
145 146
  (handler-bind
      ((error (lambda (c)
147
                (format *error-output* "~&~a~&" c)
148 149 150 151
                (cond
                  ((ignore-errors (funcall (find-symbol "GETENV" :asdf) "DEBUG_ASDF_TEST"))
                   (break))
                  (t
152 153
                   (finish-output *standard-output*)
                   (finish-output *trace-output*)
154
                   (format *error-output* "~&ABORTING:~% ~A~%" c)
155
                   (finish-output *error-output*)
156 157
                   #+sbcl (sb-debug:backtrace 69)
                   #+clozure (ccl:print-call-history :count 69 :start-frame-number 1)
158
                   #+clisp (system::print-backtrace)
159
                   (format *error-output* "~&ABORTING:~% ~A~%" c)
160
                   (finish-output *error-output*)
161 162
                   (finish-output *standard-output*)
                   (finish-output *trace-output*)
163
                   (leave-lisp "Script failed" 1))))))
164
    (funcall thunk)
165
    (leave-lisp "Script succeeded" 0)))
166 167 168 169 170 171 172 173 174 175 176 177 178 179


;;; These are used by the upgrade tests

(defmacro quietly (&body body)
  `(call-quietly #'(lambda () ,@body)))

(defun call-quietly (thunk)
  (handler-bind (#+sbcl (sb-kernel:redefinition-warning #'muffle-warning))
    (funcall thunk)))

(defun load-asdf-lisp ()
  (load *asdf-lisp*))

180 181 182 183 184 185 186
#+(or gcl genera)
(unless (fboundp 'ensure-directories-exist)
  (defun ensure-directories-exist (path)
    #+genera (fs:create-directories-recursively (pathname path))
    #+gcl (lisp:system (format nil "mkdir -p ~S" (namestring (make-pathname :name nil :type nil :defaults path))))))

(defun compile-asdf (&optional (output *asdf-fasl*))
187
  (ensure-directories-exist *asdf-fasl*)
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  ;; style warnings shouldn't abort the compilation [2010/02/03:rpg]
  (handler-bind (#+sbcl (sb-c::simple-compiler-note #'muffle-warning)
                 #+(and ecl (not ecl-bytecmp))
                 ((or c:compiler-note c::compiler-debug-note
                      c:compiler-warning) ;; ECL emits more serious warnings than it should.
                   #'muffle-warning)
                 #+mkcl
                 ((or compiler:compiler-note)
                   #'muffle-warning)
                 #-(or cmu scl)
                 (style-warning
                   #'(lambda (w)
                       ;; escalate style-warnings to warnings - we don't want them.
                       (warn "Can you please fix ASDF to not emit style-warnings? Got a ~S:~%~A"
                             (type-of w) w)
                       (muffle-warning w))))
    (compile-file *asdf-lisp* :output-file output #-gcl :verbose #-gcl t :print t)))
205 206 207 208 209 210 211 212 213 214 215 216 217

(defun load-asdf-fasl ()
  (load *asdf-fasl*))

(defun compile-load-asdf ()
  ;; emulate the way asdf upgrades itself: load source, compile, load fasl.
  (load-asdf-lisp)
  (compile-asdf)
  (load-asdf-fasl))

(defun register-directory (dir)
  (pushnew dir (symbol-value (find-symbol (string :*central-registry*) :asdf))))

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
218
(defun asdf-load (x &key verbose)
219
  (let ((xoos (find-symbol (string :oos) :asdf))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
220 221 222 223
        (xload-op (find-symbol (string :load-op) :asdf))
        (*load-print* verbose)
        (*load-verbose* verbose))
    (funcall xoos xload-op x :verbose verbose)))
224

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
225
(defun load-asdf-system (&rest keys)
226 227
  (quietly
   (register-directory *asdf-directory*)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
228
   (apply 'asdf-load :asdf keys)))
229 230 231 232 233 234 235 236 237 238

(defun testing-asdf (thunk)
  (quit-on-error
   (quietly
    (funcall thunk)
    (register-directory *test-directory*)
    (asdf-load :test-module-depend))))

(defmacro test-asdf (&body body)
  `(testing-asdf #'(lambda () ,@body)))
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

(defmacro DBG (tag &rest exprs)
  "simple debug statement macro:
outputs a tag plus a list of variable and their values, returns the last value"
  ;"if not in debugging mode, just compute and return last value"
  ; #-do-test (declare (ignore tag)) #-do-test (car (last exprs)) #+do-test
  (let ((res (gensym))(f (gensym)))
  `(let (,res (*print-readably* nil))
    (flet ((,f (fmt &rest args) (apply #'format *error-output* fmt args)))
      (,f "~&~A~%" ,tag)
      ,@(mapcan
         #'(lambda (x)
            `((,f "~&  ~S => " ',x)
              (,f "~{~S~^ ~}~%" (setf ,res (multiple-value-list ,x)))))
         exprs)
      (apply 'values ,res)))))

256 257
(pushnew :DBG *features*)

258 259 260 261 262 263
#+gcl
(eval-when (:compile-toplevel :load-toplevel :execute)
  (DBG :script-support *package* *test-directory* *asdf-directory* *asdf-lisp* *asdf-fasl*
       ))


264
#|
265
(DBG :cas o c just-done base-stamp stamp-lookup out-files in-files out-op op-time dep-stamp out-stamps in-stamps missing-in missing-out all-present earliest-out latest-in up-to-date-p done-stamp (operation-done-p o c))
266
|#