PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/quicklisp/setup.lisp

https://gitlab.com/dto/ecl-android-games-src
Lisp | 135 lines | 105 code | 18 blank | 12 comment | 5 complexity | bc380ac2e8296a67caba954802998bd4 MD5 | raw file
  1. (defpackage #:ql-setup
  2. (:use #:cl)
  3. (:export #:*quicklisp-home*
  4. #:qmerge
  5. #:qenough))
  6. (in-package #:ql-setup)
  7. (unless *load-truename*
  8. (error "This file must be LOADed to set up quicklisp."))
  9. (defvar *quicklisp-home*
  10. (make-pathname :name nil :type nil
  11. :defaults *load-truename*))
  12. (defun qmerge (pathname)
  13. "Return PATHNAME merged with the base Quicklisp directory."
  14. (merge-pathnames pathname *quicklisp-home*))
  15. (defun qenough (pathname)
  16. (enough-namestring pathname *quicklisp-home*))
  17. ;;; ASDF is a hard requirement of quicklisp. Make sure it's either
  18. ;;; already loaded or load it from quicklisp's bundled version.
  19. (defvar *required-asdf-version* "2.26")
  20. ;;; Put ASDF's fasls in a separate directory
  21. (defun implementation-signature ()
  22. "Return a string suitable for discriminating different
  23. implementations, or similar implementations with possibly-incompatible
  24. FASLs."
  25. ;; XXX Will this have problems with stuff like threads vs
  26. ;; non-threads fasls?
  27. (let ((*print-pretty* nil))
  28. (format nil "lisp-implementation-type: ~A~%~
  29. lisp-implementation-version: ~A~%~
  30. machine-type: ~A~%~
  31. machine-version: ~A~%"
  32. (lisp-implementation-type)
  33. (lisp-implementation-version)
  34. (machine-type)
  35. (machine-version))))
  36. (defun dumb-string-hash (string)
  37. "Produce a six-character hash of STRING."
  38. (let ((hash #xD13CCD13))
  39. (loop for char across string
  40. for value = (char-code char)
  41. do
  42. (setf hash (logand #xFFFFFFFF
  43. (logxor (ash hash 5)
  44. (ash hash -27)
  45. value))))
  46. (subseq (format nil "~(~36,6,'0R~)" (mod hash 88888901))
  47. 0 6)))
  48. (defun asdf-fasl-pathname ()
  49. "Return a pathname suitable for storing the ASDF FASL, separated
  50. from ASDF FASLs from incompatible implementations. Also, save a file
  51. in the directory with the implementation signature, if it doesn't
  52. already exist."
  53. (let* ((implementation-signature (implementation-signature))
  54. (original-fasl (compile-file-pathname (qmerge "asdf.lisp")))
  55. (fasl
  56. (qmerge (make-pathname
  57. :defaults original-fasl
  58. :directory
  59. (list :relative
  60. "cache"
  61. "asdf-fasls"
  62. (dumb-string-hash implementation-signature)))))
  63. (signature-file (merge-pathnames "signature.txt" fasl)))
  64. (ensure-directories-exist fasl)
  65. (unless (probe-file signature-file)
  66. (with-open-file (stream signature-file :direction :output)
  67. (write-string implementation-signature stream)))
  68. fasl))
  69. (defun ensure-asdf-loaded ()
  70. "Try several methods to make sure that a sufficiently-new ASDF is
  71. loaded: first try (require 'asdf), then loading the ASDF FASL, then
  72. compiling asdf.lisp to a FASL and then loading it."
  73. (let ((source (qmerge "asdf.lisp")))
  74. (labels ((asdf-symbol (name)
  75. (let ((asdf-package (find-package '#:asdf)))
  76. (when asdf-package
  77. (find-symbol (string name) asdf-package))))
  78. (version-satisfies (version)
  79. (let ((vs-fun (asdf-symbol '#:version-satisfies))
  80. (vfun (asdf-symbol '#:asdf-version)))
  81. (when (and vs-fun vfun
  82. (fboundp vs-fun)
  83. (fboundp vfun))
  84. (funcall vs-fun (funcall vfun) version)))))
  85. (block nil
  86. (macrolet ((try (&body asdf-loading-forms)
  87. `(progn
  88. (handler-bind ((warning #'muffle-warning))
  89. (ignore-errors
  90. ,@asdf-loading-forms))
  91. (when (version-satisfies *required-asdf-version*)
  92. (return t)))))
  93. (try)
  94. (try (require 'asdf))
  95. (let ((fasl (asdf-fasl-pathname)))
  96. (try (load fasl :verbose nil))
  97. (try (load (compile-file source :verbose nil :output-file fasl))))
  98. (error "Could not load ASDF ~S or newer" *required-asdf-version*))))))
  99. (ensure-asdf-loaded)
  100. ;;;
  101. ;;; Quicklisp sometimes must upgrade ASDF. Ugrading ASDF will blow
  102. ;;; away existing ASDF methods, so e.g. FASL recompilation :around
  103. ;;; methods would be lost. This config file will make it possible to
  104. ;;; ensure ASDF can be configured before loading Quicklisp itself via
  105. ;;; ASDF. Thanks to Nikodemus Siivola for pointing out this issue.
  106. ;;;
  107. (let ((asdf-init (probe-file (qmerge "asdf-config/init.lisp"))))
  108. (when asdf-init
  109. (with-simple-restart (skip "Skip loading ~S" asdf-init)
  110. (load asdf-init :verbose nil :print nil))))
  111. (push (qmerge "quicklisp/") asdf:*central-registry*)
  112. (let ((*compile-print* nil)
  113. (*compile-verbose* nil)
  114. (*load-verbose* nil)
  115. (*load-print* nil))
  116. (asdf:oos 'asdf:load-op "quicklisp" :verbose nil))
  117. (quicklisp:setup)