-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathupstream.lisp
262 lines (218 loc) · 8.8 KB
/
upstream.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
;;;; upstream.lisp
(in-package #:quicklisp-controller)
(defclass upstream-source ()
((source-file
:initarg :source-file
:accessor source-file)
(project-name
:initarg :project-name
:accessor project-name)
(location
:initarg :location
:accessor location)))
(defgeneric github-issue (object)
(:method (source)
(setf source (source-designator source))
(qlc-github-issues:matching-issue (name source))))
(defgeneric github-issue-number (object)
(:method (source)
(setf source (source-designator source))
(getf (github-issue source) :number)))
(defmethod base-directory ((source upstream-source))
(pathname (directory-namestring (source-file source))))
(defgeneric days-old (source)
(:method (source)
(truncate (- (get-universal-time)
(file-write-date (source-file source)))
86400)))
(defgeneric print-source (source stream)
(:method (source stream)
(format stream "~S ~S"
(project-name source)
(location source))))
(defmethod print-object ((source upstream-source) stream)
(print-unreadable-object (source stream :type t)
(print-source source stream)))
(defgeneric module-name (source)
(:method (source)
(project-name source)))
(defgeneric source-description (source)
(:documentation "Return a line suitable for describing approximately
how to get SOURCE yourself."))
(defgeneric release-tarball-prefix (source)
(:method (source)
(format nil "~A/" (project-name source))))
(defgeneric make-release-tarball (source output-file))
(defun release-maker (directory)
(lambda (source)
(let ((tarball (make-pathname :name (project-name source)
:type "tgz"
:defaults directory)))
(unless (probe-file tarball)
(format *trace-output* "~&; Creating ~A~%" tarball)
(make-release-tarball source tarball)))))
(defgeneric create-source-cache (source)
(:documentation "Unconditionaly get and cache data for building SOURCE."))
(defgeneric find-source-cache (source)
(:documentation "Return the cached build data for SOURCE, or nil if
no cached data is available."))
(defgeneric ensure-source-cache (source)
(:documentation "Ensure data needed to build releases for SOURCE are
cached. If cached data already exists for SOURCE, do not update
it.")
(:method (source)
(or (find-source-cache source)
(create-source-cache source))))
(defgeneric update-source-cache (source)
(:documentation "Try to update cached data for SOURCE."))
(defgeneric source-cache-timestamp (source)
(:documentation "Return the timestamp, as a universal time, at which
the source cache was last updated by the upstream. Return NIL if the
timestamp can't be determined.")
(:method ((source t))
nil))
(defgeneric source-cache-age-or-nil (source)
(:documentation "Return the age, in days, of the source's cached
data. For VCS, it is the age of commit. For HTTP/HTTPS, it's the
date on the last-modified. If the age can't be determined, return
NIL.")
(:method (source)
(let ((time (source-cache-timestamp source)))
(and time
(/ (- (get-universal-time) (source-cache-timestamp source))
86400.0)))))
;;;
;;; Loading & mapping sources from the quicklisp-projects directory.
;;;
(defun split-into-initargs (line initargs)
(let ((values (split-spaces line)))
(unless (eql (length values) (length initargs))
(error "Initarg/value mismatch between ~S and ~S"
initargs values))
(mapcan #'list initargs values)))
(defgeneric source-location-initargs (source)
(:method (source)
(list :location)))
(defgeneric source-host (source)
(:method (source)
(puri:uri-host (puri:parse-uri (location source)))))
(defgeneric parse-location (source location-string)
(:documentation "Update an instance by parsing its location value.")
(:method (source location-string)
(let ((initargs (split-into-initargs location-string
(source-location-initargs source))))
(apply #'reinitialize-instance source initargs))))
(defun pathname-project-name (pathname)
(first (last (pathname-directory pathname))))
(defun make-source (class project location)
(parse-location (make-instance class :project-name project)
location))
(defun load-source-file (project file)
"Create a source from the description in FILE."
(with-open-file (stream file)
(let* ((line (read-line stream))
(space (position #\Space line)))
(unless space
(error "Malformed source line in ~A" file))
(let* ((source-name (subseq line 0 space))
(source-class-name (format nil "~:@(~A-source~)" source-name))
(source-class (find-symbol source-class-name
(load-time-value *package*)))
(location (subseq line (1+ space))))
(when (not source-class)
(error "No source class for ~S (loading ~S)" source-class-name file))
(let ((source (make-source source-class project location)))
(setf (source-file source) file)
source)))))
(defvar *current-mapped-source* nil)
(defun map-source (fun source)
(let ((*current-mapped-source* (project-name source)))
(with-simple-restart (skip "Skip ~A source" *current-mapped-source*)
(funcall fun source))))
(defun map-sources (fun)
(with-simple-restart (abort "Give up entirely")
(dolist (source-file
(directory #p"quicklisp-controller:projects;projects;**;source.txt"))
(let ((project-name (pathname-project-name source-file)))
(map-source fun (load-source-file project-name source-file))))))
(defun collect-sources-if (fun)
(let ((result '()))
(map-sources (lambda (source)
(when (funcall fun source)
(push source result))))
(sort result 'string< :key 'name)))
(defun pmap-sources (fun &key (parallel-key #'source-host)
(test #'identity))
(let ((dependency-tree (lparallel:make-ptree))
(parallel-key-dependency (make-hash-table :test 'equal))
(i 0))
(map-sources (lambda (source)
(let ((testp (funcall test source))
(pkey (funcall parallel-key source)))
(when testp
(lparallel:ptree-fn i (gethash pkey
parallel-key-dependency)
(lambda (&optional arg)
(declare (ignore arg))
(map-source fun source))
dependency-tree)
(setf (gethash pkey parallel-key-dependency)
(list i))
(incf i)))))
(lparallel:ptree-fn 'everything (loop for j below i collect j)
(constantly nil) dependency-tree)
(lparallel:call-ptree 'everything dependency-tree)
nil))
(defun project-name-source-file (project-name)
(merge-pathnames
(make-pathname :defaults "" :directory (list :relative :back project-name))
(translate-logical-pathname
(make-pathname :host "quicklisp-controller"
:directory (list :absolute "projects" "projects" "stub")
:name "source"
:type "txt"))))
(defun fresh-cache-p (source)
(not
(not
(probe-file
(make-pathname :type nil :name "fresh-cache"
:defaults (project-name-source-file (name source)) )))))
(defun find-source (project-name)
(let* ((name (string-downcase project-name))
(file (probe-file (project-name-source-file name))))
(when file
(load-source-file name file))))
(defun edit-source (name)
(let ((source (find-source name)))
(when source
(ed (source-file source)))))
(defun source-designator (source)
(if (typep source 'upstream-source)
source
(find-source source)))
(defun map-sources-of-type (type fun)
(map-sources (lambda (source)
(when (typep source type)
(funcall fun source)))))
(defun all-of-type (type)
(let ((result '()))
(map-sources-of-type type (lambda (source)
(push source result)))
result))
(defun random-of-type (type)
(random-element (coerce (all-of-type type) 'vector)))
(defgeneric command (source)
(:method (source)
nil))
(defun missing-commands ()
(let ((missing '())
(tried (make-string-table)))
(map-sources
(lambda (source)
(let ((command (command source)))
(when command
(unless (gethash command tried)
(setf (gethash command tried) t)
(unless (ignore-errors (run command "--version"))
(push command missing)))))))
missing))