|
| 1 | +(cl:in-package #:cl-user) |
| 2 | + |
| 3 | +(eval-when (:compile-toplevel :load-toplevel :execute) |
| 4 | + (require "asdf") |
| 5 | + (unless (find-package '#:asdf) |
| 6 | + (error "ASDF could not be loaded"))) |
| 7 | + |
| 8 | +(let ((indicator '#:ql-bundle-v1) |
| 9 | + (searcher-name '#:ql-bundle-searcher) |
| 10 | + (base (make-pathname :name nil :type nil |
| 11 | + :defaults #. (or *compile-file-truename* |
| 12 | + *load-truename*)))) |
| 13 | + (labels ((file-lines (file) |
| 14 | + (with-open-file (stream file) |
| 15 | + (loop for line = (read-line stream nil) |
| 16 | + while line |
| 17 | + collect line))) |
| 18 | + (relative (pathname) |
| 19 | + (merge-pathnames pathname base)) |
| 20 | + (pathname-timestamp (pathname) |
| 21 | + #+clisp |
| 22 | + (nth-value 2 (ext:probe-pathname pathname)) |
| 23 | + #-clisp |
| 24 | + (file-write-date pathname)) |
| 25 | + (system-table (table pathnames) |
| 26 | + (dolist (pathname pathnames table) |
| 27 | + (setf (gethash (pathname-name pathname) table) |
| 28 | + (relative pathname)))) |
| 29 | + |
| 30 | + (initialize-bundled-systems-table (table data-source) |
| 31 | + (system-table table (file-lines data-source))) |
| 32 | + |
| 33 | + (local-projects-system-pathnames (data-source) |
| 34 | + (let ((files (directory (merge-pathnames "**/*.asd" |
| 35 | + data-source)))) |
| 36 | + (stable-sort (sort files #'string< :key #'namestring) |
| 37 | + #'< |
| 38 | + :key (lambda (file) |
| 39 | + (length (namestring file)))))) |
| 40 | + (initialize-local-projects-table (table data-source) |
| 41 | + (system-table table (local-projects-system-pathnames data-source))) |
| 42 | + |
| 43 | + (make-table (&key data-source init-function) |
| 44 | + (let ((table (make-hash-table :test 'equalp))) |
| 45 | + (setf (gethash "/data-source" table) |
| 46 | + data-source |
| 47 | + (gethash "/timestamp" table) |
| 48 | + (pathname-timestamp data-source) |
| 49 | + (gethash "/init" table) |
| 50 | + init-function) |
| 51 | + table)) |
| 52 | + |
| 53 | + (tcall (table key &rest args) |
| 54 | + (let ((fun (gethash key table))) |
| 55 | + (unless (and fun (functionp fun)) |
| 56 | + (error "Unknown function key ~S" key)) |
| 57 | + (apply fun args))) |
| 58 | + (created-timestamp (table) |
| 59 | + (gethash "/timestamp" table)) |
| 60 | + (data-source-timestamp (table) |
| 61 | + (pathname-timestamp (data-source table))) |
| 62 | + (data-source (table) |
| 63 | + (gethash "/data-source" table)) |
| 64 | + |
| 65 | + (stalep (table) |
| 66 | + ;; FIXME: Handle newly missing data sources? |
| 67 | + (< (created-timestamp table) |
| 68 | + (data-source-timestamp table))) |
| 69 | + (meta-key-p (key) |
| 70 | + (and (stringp key) |
| 71 | + (< 0 (length key)) |
| 72 | + (char= (char key 0) #\/))) |
| 73 | + (clear (table) |
| 74 | + ;; Don't clear "/foo" keys |
| 75 | + (maphash (lambda (key value) |
| 76 | + (declare (ignore value)) |
| 77 | + (unless (meta-key-p key) |
| 78 | + (remhash key table))) |
| 79 | + table)) |
| 80 | + (initialize (table) |
| 81 | + (tcall table "/init" table (data-source table)) |
| 82 | + (setf (gethash "/timestamp" table) |
| 83 | + (pathname-timestamp (data-source table))) |
| 84 | + table) |
| 85 | + (update (table) |
| 86 | + (clear table) |
| 87 | + (initialize table)) |
| 88 | + (lookup (system-name table) |
| 89 | + (when (stalep table) |
| 90 | + (update table)) |
| 91 | + (values (gethash system-name table))) |
| 92 | + |
| 93 | + (search-function (system-name) |
| 94 | + (let ((tables (get searcher-name indicator))) |
| 95 | + (dolist (table tables) |
| 96 | + (let* ((result (lookup system-name table)) |
| 97 | + (probed (and result (probe-file result)))) |
| 98 | + (when probed |
| 99 | + (return probed)))))) |
| 100 | + |
| 101 | + (make-bundled-systems-table () |
| 102 | + (initialize |
| 103 | + (make-table :data-source (relative "system-index.txt") |
| 104 | + :init-function #'initialize-bundled-systems-table))) |
| 105 | + (make-local-projects-table () |
| 106 | + (initialize |
| 107 | + (make-table :data-source (relative "local-projects/") |
| 108 | + :init-function #'initialize-local-projects-table))) |
| 109 | + |
| 110 | + (check-for-existing-searcher (searchers) |
| 111 | + (block done |
| 112 | + (dolist (searcher searchers) |
| 113 | + (when (symbolp searcher) |
| 114 | + (let ((plist (symbol-plist searcher))) |
| 115 | + (loop for key in plist by #'cddr |
| 116 | + when |
| 117 | + (and (symbolp key) (string= key indicator)) |
| 118 | + do |
| 119 | + (setf indicator key) |
| 120 | + (setf searcher-name searcher) |
| 121 | + (return-from done t)))))))) |
| 122 | + (let ((existing (check-for-existing-searcher |
| 123 | + asdf:*system-definition-search-functions*))) |
| 124 | + (push (make-bundled-systems-table) (get searcher-name indicator)) |
| 125 | + (push (make-local-projects-table) (get searcher-name indicator)) |
| 126 | + (unless existing |
| 127 | + (setf (symbol-function searcher-name) #'search-function) |
| 128 | + (push searcher-name asdf:*system-definition-search-functions*))) |
| 129 | + t)) |
0 commit comments