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
| | ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 by Amar Singh <nly@disroot.org>
;;;
;;; This file is 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 <https://www.gnu.org/licenses/>.
(define-module (guix import golang))
(use-modules
(guix import github) ;; latest-release
(guix download) ;; download-to-store
((guix import utils) #:prefix utils:) ;; hash
(guix packages) ;; packages
(guix build-system go) ;; go-build-system
(guix store) ;; with-store
(gnu packages golang) ;; inherit (simple) go package
(ice-9 textual-ports) ;; to parse readme.md
)
(define go-name* "github.com/gohugoio/hugo") ;; for tests
(define (go-name->url go-name)
(string-append "https://" go-name))
(define (go-name->tarball go-name version)
(string-append (go-name->url go-name) "/archive/v" version
".tar.gz"))
;;; Possible remove @@ if upstream exports the symbols
(define (go-name->name go-name)
((@@ (guix import github) github-repository)
(go-name->url go-name)))
;;; Slow; accesses the network
(define (latest-release go-name)
((@@ (guix import github) latest-released-version)
(go-name->url go-name)
(go-name->name go-name)))
;;; Slow; downloads the url from network;
(define (url->store url)
(with-store store
(download-to-store store
url)))
;;; Slow; download the source tarball from network and returns base32
;;; nix-hash
(define (go-name->sha256 go-name version)
(utils:guix-hash-url (url->store (go-name->tarball go-name version))))
;;; Towards go-name->synopsis,description
(define (go-name->readme go-name)
(string-append "https://raw.githubusercontent.com"
(substring go-name
(string-length "github.com"))
"/master/"
"README.md"))
;;; Slow; network access
(define (go-name->readme-string go-name)
"Slow; network access."
(call-with-input-file (url->store (go-name->readme go-name))
(lambda (port) (get-string-n port 4096))))
;;; Maybe try to match the first sentence.
(define (go-name->synopsis go-name readme-string)
(string-append (go-name->name go-name)
(substring readme-string 0 100)))
;;; Maybe try to match the the next two sentences.
(define (go-name->description go-name readme-string)
(string-append (go-name->name go-name)
(substring readme-string 100 300)))
(define-public (make-go-package go-name)
;; Do the expensive operations only once; query network for latest version
(let* ((version (latest-release go-name))
(sha256 (go-name->sha256 go-name version))
(readme-string (go-name->readme-string go-name)))
(package (inherit go-github-com-alsm-ioprogress)
(name (string-append "go-" (go-name->name go-name)))
(version version)
(source (origin (method url-fetch)
(uri (go-name->tarball go-name version))
(sha256 (base32
sha256))))
(home-page (go-name->url go-name))
(build-system go-build-system)
(arguments
`(#:import-path ,go-name))
;; TODO: inputs
(synopsis
(go-name->synopsis go-name readme-string))
(description (go-name->description go-name readme-string))
;; TODO: license
)))
;;; STATUS
;;; 1. latest-release DONE
;;; 1.b latest-commit PENDING/STALLED
;;; 2. go-name->name DONE
;;; 4. go-name->url DONE
;;; 4.b go-name->tarball DONE
;;; 5. go-name->sha256 (go-name version) DONE
;;; 6. go-name->synopsis DONE
;;; 7. go-name->description DONE
;;; 6-7.b try to extract sentences. TODO
;;; 8. go-name->license TODO
;;; 9. go-name->inputs TODO
;;; golang.scm ends here
|