blob: 46cf9c8eca5b4c92096498fb618a76ad92b3787b (
plain)
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
|
(.module:
[library
[lux (#- Source)
[abstract
["." monad (#+ do)]]
[control
["." try (#+ Try)]
[concurrency
["." async (#+ Async)]]]
[data
["." text
["%" format (#+ format)]]
[collection
["." dictionary]
["." row]]
[format
["." binary]
["." tar]]]
[time
["." instant]]
[tool
[compiler
[meta
["." io #_
["#" context (#+ Extension)]]]]]
[world
["." file]]]]
[//
[cli (#+ Source Export)]])
(def: file
"library.tar")
(def: no_ownership
tar.Ownership
(let [commons (: tar.Owner
{#tar.name tar.anonymous
#tar.id tar.no_id})]
{#tar.user commons
#tar.group commons}))
(def: #export (library fs sources)
(-> (file.System Async) (List Source) (Async (Try tar.Tar)))
(do (try.with async.monad)
[files (io.enumerate fs sources)]
(|> (dictionary.entries files)
(monad.map try.monad
(function (_ [path source_code])
(do try.monad
[path (|> path
(text.replace_all (\ fs separator) .module_separator)
tar.path)
source_code (tar.content source_code)]
(in (#tar.Normal [path
(instant.of_millis +0)
($_ tar.and
tar.read_by_owner tar.write_by_owner
tar.read_by_group tar.write_by_group
tar.read_by_other)
..no_ownership
source_code])))))
(\ try.monad map row.of_list)
(\ async.monad in))))
(def: #export (export fs [sources target])
(-> (file.System Async) Export (Async (Try Any)))
(do {! (try.with async.monad)}
[tar (\ ! map (binary.run tar.writer)
(..library fs sources))]
(|> ..file
(format target (\ fs separator))
(\ fs write tar))))
|