aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/compositor/export.lux
blob: f6a78ed78c4f8ab32f3a3f8ebf93adc49113933b (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
(.module:
  [lux #*
   [abstract
    ["." monad (#+ do)]]
   [control
    ["." try (#+ Try)]
    [concurrency
     ["." promise (#+ Promise) ("#@." monad)]]
    [security
     ["!" capability]]]
   [data
    ["." text
     ["%" format (#+ format)]]
    [collection
     ["." dictionary]
     ["." row]]
    [format
     ["." binary]
     ["." tar]]]
   [time
    ["." instant]]
   [tool
    [compiler
     [meta
      ["." io #_
       ["#" context (#+ Extension)]]]]]
   [world
    ["." file]]]
  [//
   [cli (#+ Export)]])

(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 (export system extension [sources target])
  (-> (file.System Promise) Extension Export (Promise (Try Any)))
  (let [package (format target (:: system separator) "library.tar")]
    (do (try.with promise.monad)
      [package (: (Promise (Try (file.File Promise)))
                  (file.get-file promise.monad system package))
       files (io.enumerate system extension sources)
       tar (|> (dictionary.entries files)
               (monad.map try.monad
                          (function (_ [path source-code])
                            (do try.monad
                              [path (|> path
                                        (text.replace-all (:: system separator) .module-separator)
                                        tar.path)
                               source-code (tar.content source-code)]
                              (wrap (#tar.Normal [path
                                                  (instant.from-millis +0)
                                                  tar.none
                                                  ..no-ownership
                                                  source-code])))))
               (:: try.monad map (|>> row.from-list (binary.run tar.writer)))
               promise@wrap)]
      (!.use (:: package over-write) tar))))