-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rkt
90 lines (76 loc) · 2.77 KB
/
build.rkt
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
#lang racket/base
(require racket/runtime-path
racket/file
racket/system
net/ftp
file/gunzip
file/untar)
(define FILENAMES '("tzcode-latest.tar.gz"
"tzdata-latest.tar.gz"))
(define-runtime-path pkg-base-path ".")
(define build-dir (build-path pkg-base-path "build"))
(define src-dir (build-path build-dir "tzinstall" "usr" "share" "zoneinfo"))
(define install-dir (build-path pkg-base-path "tzinfo" "tzdata" "zoneinfo"))
(define info-file (build-path pkg-base-path "tzinfo" "info.rkt"))
(define (clean)
(delete-directory/files build-dir #:must-exist? #f))
(define (make-build-dir)
(make-directory build-dir))
(define (download)
(define con (ftp-establish-connection "ftp.iana.org" 21 "anonymous" ""))
(ftp-cd con "tz")
(for ([name (in-list FILENAMES)])
(ftp-download-file con build-dir name))
(ftp-close-connection con))
(define (unarchive)
(for ([name (in-list FILENAMES)])
(with-input-from-file (build-path build-dir name)
(λ ()
(define-values (in out) (make-pipe))
(gunzip-through-ports (current-input-port) out)
(untar in #:dest build-dir)))))
(define (make)
(parameterize ([current-directory build-dir])
;; The "fat" build creates some number of future transitions.
;; The resulting files are larger, but tzinfo doesn't yet
;; (as of 2021-12-03) handle future cases without those extra
;; transitions. See https://github.com/97jaz/tzinfo/issues/18
(or (system "make TOPDIR=tzinstall ZFLAGS=\"-b fat\" install")
(raise "build failed"))))
;; requires the unarchive step to have been executed
(define (version)
(regexp-replace #rx"\n"
(file->string (build-path build-dir "version"))
""))
(define (install-data)
(delete-directory/files install-dir #:must-exist? #f)
(copy-directory/files src-dir install-dir))
(define (manifest)
(map path->string
(parameterize ([current-directory install-dir])
(for/list ([f (in-directory)])
f))))
(define (install-info)
(with-output-to-file info-file #:exists 'replace
(λ ()
(displayln "#lang info")
(newline)
(display
(string-append ";; `tzdata-zoneinfo-dir` is for backward compatibility with\n"
";; older versions of tzinfo. It can be removed in future\n"
";; versions.\n"))
(writeln `(define iana-tz-version ,(version)))
(writeln `(define tzdata-zoneinfo-dir "tzdata/zoneinfo"))
(writeln `(define tzdata-zoneinfo-module-path '(lib "tzinfo/tzdata/zoneinfo")))
(writeln `(define copy-shared-files '("tzdata"))))))
(define (run)
(clean)
(make-build-dir)
(download)
(unarchive)
(make)
(install-data)
(install-info)
(clean))
(module* main #f
(run))