-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcheck.lisp
197 lines (188 loc) · 8.96 KB
/
check.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
(defpackage #:qlot/check
(:use #:cl)
(:import-from #:qlot/source
#:source=
#:source-project-name
#:source-dist-name
#:source-version
#:source-local
#:source-asdf
#:defrost-source
#:make-source)
(:import-from #:qlot/parser
#:find-lock
#:parse-qlfile-lock
#:read-qlfile-for-install
#:read-qlfile-for-outdated)
(:import-from #:qlot/server
#:with-qlot-server)
(:import-from #:qlot/logger
#:message)
(:import-from #:qlot/logger
#:whisper
#:clear-whisper)
(:import-from #:qlot/utils
#:with-package-functions)
(:import-from #:qlot/utils/ql
#:with-quicklisp-home
#:quicklisp-distinfo-url)
(:import-from #:qlot/utils/qlot
#:dump-source-registry-conf)
(:import-from #:qlot/utils/project
#:check-local-quicklisp
#:*qlot-directory*
#:*default-qlfile*
#:ensure-qlfile-pathname
#:local-quicklisp-home)
(:import-from #:qlot/utils/tmp
#:with-tmp-directory)
(:import-from #:qlot/errors
#:qlfile-not-found
#:qlfile-lock-not-found
#:missing-projects
#:unnecessary-projects
#:outdated-projects)
(:export #:check-qlfile
#:check-project
#:available-update-project))
(in-package #:qlot/check)
(defun check-qlfile (qlfile &key quiet)
(unless (uiop:file-exists-p qlfile)
(error 'qlfile-not-found :path qlfile))
(let* ((sources (read-qlfile-for-install qlfile :silent t))
(qlfile.lock (find-lock qlfile))
(project-root (uiop:pathname-directory-pathname qlfile))
(qlhome (merge-pathnames *qlot-directory* project-root)))
(unless (uiop:file-exists-p qlfile.lock)
(error 'qlfile-lock-not-found :path qlfile.lock))
(check-local-quicklisp project-root)
;; Check if qlfile.lock is up-to-date
(let* ((lock-sources (parse-qlfile-lock qlfile.lock))
(lock-sources (mapcar #'defrost-source lock-sources))
(old-sources
(remove-if (lambda (source)
(let ((lock-source
(find (source-project-name source) lock-sources
:key #'source-project-name
:test #'string=)))
(and lock-source
(source= source lock-source))))
sources)))
(when old-sources
(error 'missing-projects
:projects (mapcar #'source-project-name old-sources))))
(unless (find-package '#:ql)
(load (merge-pathnames #P"setup.lisp" qlhome)))
;; Check if all dists are installed and up-to-date
(let ((source-registry-up-to-date
(or (not (find-if (lambda (source)
(typep source 'source-local))
sources))
(and (uiop:file-exists-p (merge-pathnames #P"source-registry.conf" qlhome))
(let ((source-registry-conf
(with-output-to-string (s)
(dump-source-registry-conf s sources))))
(equal source-registry-conf
(uiop:read-file-string (merge-pathnames #P"source-registry.conf" qlhome))))))))
(with-quicklisp-home qlhome
(with-package-functions #:ql-dist (find-dist version)
(let ((old-sources
(remove-if (lambda (source)
(typecase source
(source-local
source-registry-up-to-date)
(source-asdf
(let ((asdf-dir (merge-pathnames #P"local-projects/asdf/" qlhome)))
(and (uiop:directory-exists-p asdf-dir)
(let ((version-file (merge-pathnames #P"version.lisp-expr" asdf-dir)))
;; XXX: Skip if the version file doesn't exist.
(or (not (uiop:file-exists-p version-file))
(ignore-errors
(equal (uiop:read-file-form version-file)
(source-version source))))))))
(otherwise
(let ((dist (find-dist (source-dist-name source))))
(and dist
(slot-boundp source 'qlot/source/base::version)
(equal (version dist)
(source-version source)))))))
sources)))
(when old-sources
(error 'missing-projects
:projects (mapcar #'source-project-name old-sources)))))
(with-package-functions #:ql-dist (all-dists name)
(let ((extra-dists
(append
(remove-if (lambda (dist-name)
(find dist-name sources :test #'string= :key #'source-dist-name))
(mapcar #'name (all-dists)))
(and (not (find-if (lambda (source)
(typep source 'source-asdf))
sources))
(let ((asdf-dir (merge-pathnames #P"local-projects/asdf/" qlhome)))
(and (uiop:directory-exists-p asdf-dir)
(list "asdf")))))))
(when extra-dists
(error 'unnecessary-projects
:projects extra-dists)))))))
(unless quiet
(message "Lock file is up-to-date.")))
(defun check-project (object &key quiet)
(etypecase object
((or symbol string)
(check-project (asdf:find-system object) :quiet quiet))
(asdf:system
(check-qlfile (asdf:system-relative-pathname object *default-qlfile*) :quiet quiet))
(pathname
(check-qlfile (ensure-qlfile-pathname object) :quiet quiet))))
(defun available-update-project (object &key projects)
(etypecase object
((or symbol string)
(available-update-project (asdf:find-system object)))
(asdf:system
(available-update-project (asdf:system-relative-pathname object *default-qlfile*)))
(pathname
(check-local-quicklisp object)
(let* ((qlfile (ensure-qlfile-pathname object))
(sources (read-qlfile-for-outdated qlfile))
(sources
(if (null projects)
sources
(remove-if-not (lambda (source)
(find (source-project-name source) projects
:test 'equal))
sources)))
(quicklisp-home (local-quicklisp-home object))
(new-update-projects '()))
(when projects
(let ((missing (set-difference projects (mapcar #'source-project-name sources)
:test 'equal)))
(when missing
(error 'missing-projects :projects missing))))
(unless (find-package '#:ql)
(load (merge-pathnames #P"setup.lisp" quicklisp-home)))
(with-quicklisp-home quicklisp-home
(with-tmp-directory (tmp-dir)
(dolist (source sources)
(with-package-functions #:ql-dist (find-dist version available-update)
(let ((dist (find-dist (source-dist-name source))))
(if dist
(progn
(whisper "Checking update of ~S..." (source-project-name source))
(with-qlot-server (source :destination tmp-dir
:distinfo-only t
:silent t)
(let ((new-dist (available-update dist)))
(if new-dist
(progn
(push (source-project-name source) new-update-projects)
(message "New version of ~S is available.~% Current: ~A~% Latest: ~A"
(source-project-name source)
(version dist)
(version new-dist)))
(clear-whisper)))))
(message "~S is not installed yet. Skipped."
(source-project-name source))))))
(when new-update-projects
(error 'outdated-projects
:projects (reverse new-update-projects)))))))))