-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquicklisp.scm
115 lines (106 loc) · 4.54 KB
/
quicklisp.scm
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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021-2022 Sharlatan Hellseher <[email protected]>
;;;
;;; This file is NOT part of GNU Guix.
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;
;;; Commentary:
;;; to add this file to Guile import path:
;;;
;;; (add-to-load-path "/mnt/library/projects/prj/guix-channel")
;;; Code:
(define-module (guix import quicklisp)
#:use-module (ice-9 popen)
#:use-module ((ice-9 rdelim) #:select (read-string read-line))
#:use-module (web uri)
#:use-module ((guix download) #:select (download-to-store))
#:use-module (guix utils)
#:use-module (guix git)
#:use-module (guix ui)
#:use-module (guix upstream)
#:use-module (guix packages)
#:use-module (gnu packages)
#:export (distinfo->alist
parse-systems
distribution-spec))
(define %distributions
'(("quicklisp" . "https://beta.quicklisp.org/dist/quicklisp.txt")
("bodge" . "https://bodge.borodust.org/dist/org.borodust.bodge.txt")
("ultralisp" . "http://dist.ultralisp.org/")
("shirakumo" . "http://dist.tymoon.eu/shirakumo.txt")))
(define (distinfo->alist distinfo)
"Convert a DISTINFO string into an alist."
(let ((lines (string-split distinfo #\newline)))
(map (lambda (line)
(let* ((pos (string-index line #\:))
(key (string-take line pos))
(value (string-drop line (+ 1 pos))))
(cons key (string-trim-both value))))
lines)))
(define (parse-systems systems)
"Parse SYSTEMS string and return a list of metadata list and dependencies list
of the given project. Each field of the SYSTEMS strings separated by a single
space and have following sequence.
The first line starting with # of the file is a header with following format:
- <field-0> :: project
- <field-1> :: system file
- <field-2> :: system name
- <field-3...n> :: list of dependencies"
(let ((lines (cdr (string-split systems #\newline))))
(map (lambda (line)
(let ((spec (string-split line #\space)))
(append
(list (list-head spec 3)
(if (= (length spec) 3)
(list)
(list-tail spec 3))))))
lines)))
(define* (distribution-spec #:optional (distribution "quicklisp"))
"Return the latest verion of distribution specification.
name: <distribution-name>
version: <destribution-release-version-date>
system-index-url: <url-to-systems-list>
release-index-url: <url-to-release-packages>
archive-base-url: <url-base>
canonical-distinfo-url: <url-to-released-dist-info>
distinfo-subscription-url: <url-to-current-distribution-info-file>"
(let ((url (string->uri (assoc-ref %distributions distribution))))
(guard (c ((http-get-error? c)
(warning (G_ "Failed to retrieve distinfo from ~a: ~a (~a)~%")
(uri->string (http-get-error-uri c))
(http-get-error-code c)
(http-get-error-reason c))
#f))
(map (lambda (chunk)
(distinfo->alist (string-join chunk "\n")))
(let* ((port (http-fetch/cached url))
(lines (read-lines port)))
(close-port port)
(chunk-lines lines))))))
(define* (system-spec #:optional system distribution)
"Return the latest verion of distribution specification."
(let ((url (string->uri (assoc-ref (car (distribution-spec)) "system-index-url"))))
(guard (c ((http-get-error? c)
(warning (G_ "Failed to retrieve distinfo from ~a: ~a (~a)~%")
(uri->string (http-get-error-uri c))
(http-get-error-code c)
(http-get-error-reason c))
#f))
(map (lambda (chunk)
(parse-systems (string-join chunk "\n")))
(let* ((port (http-fetch/cached url))
(lines (read-lines port)))
(close-port port)
(chunk-lines lines))))))