]> gitweb.factorcode.org Git - factor.git/blob - extra/mason/common/common.factor
Switch to https urls
[factor.git] / extra / mason / common / common.factor
1 ! Copyright (C) 2008, 2011 Eduardo Cavazos, Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays calendar calendar.format combinators
4 continuations io io.encodings.utf8 io.files io.launcher
5 io.pathnames io.sockets kernel make mason.config math namespaces
6 parser prettyprint prettyprint.config sequences splitting ;
7 IN: mason.common
8
9 : print-timestamp ( string -- )
10     now timestamp>string write bl print flush ;
11
12 ERROR: no-host-name ;
13
14 : short-host-name ( -- string )
15     host-name "." split1 drop [ no-host-name ] unless* ;
16
17 SYMBOL: current-git-id
18
19 : short-running-process ( command -- )
20     ! Give network operations and shell commands at most
21     ! 30 minutes to complete, to catch hangs.
22     >process
23         30 minutes >>timeout
24         +new-group+ >>group
25     try-output-process ;
26
27 : retry ( n quot -- )
28     [ <iota> ] dip
29     '[ drop @ f ] attempt-all drop ; inline
30
31 : upload-process ( process -- )
32     ! Give network operations and shell commands at most
33     ! 30 minutes to complete, to catch hangs.
34     >process
35         upload-timeout get >>timeout
36         +new-group+ >>group
37     try-output-process ;
38
39 :: upload-safely ( local username host remote -- )
40     remote ".incomplete" append :> temp
41     { username "@" host ":" temp } concat :> scp-remote
42     scp-command get :> scp
43     ssh-command get :> ssh
44     5 [ { scp local scp-remote } upload-process ] retry
45     5 [ { ssh host "-l" username "mv" temp remote } short-running-process ] retry ;
46
47 : eval-file ( file -- obj )
48     dup utf8 file-lines parse-fresh
49     [ "Empty file: " swap append throw ] [ nip first ] if-empty ;
50
51 : to-file ( object file -- ) utf8 [ [ . ] without-limits ] with-file-writer ;
52
53 : datestamp ( timestamp -- string )
54     [
55         {
56             [ year>> , ]
57             [ month>> , ]
58             [ day>> , ]
59             [ hour>> , ]
60             [ minute>> , ]
61         } cleave
62     ] { } make [ pad-00 ] map "-" join ;
63
64 : nanos>time ( n -- string )
65     1,000,000,000 /i 60 /mod [ 60 /mod ] dip 3array [ pad-00 ] map ":" join ;
66
67 SYMBOL: stamp
68
69 : build-dir ( -- path ) builds-dir get stamp get append-path ;
70
71 CONSTANT: load-all-vocabs-file "load-everything-vocabs"
72 CONSTANT: load-all-errors-file "load-everything-errors"
73
74 CONSTANT: test-all-vocabs-file "test-all-vocabs"
75 CONSTANT: test-all-errors-file "test-all-errors"
76
77 CONSTANT: help-lint-vocabs-file "help-lint-vocabs"
78 CONSTANT: help-lint-errors-file "help-lint-errors"
79
80 CONSTANT: compiler-errors-file "compiler-errors"
81 CONSTANT: compiler-error-messages-file "compiler-error-messages"
82
83 CONSTANT: boot-time-file "boot-time"
84 CONSTANT: load-time-file "load-time"
85 CONSTANT: test-time-file "test-time"
86 CONSTANT: help-lint-time-file "help-lint-time"
87 CONSTANT: benchmark-time-file "benchmark-time"
88 CONSTANT: html-help-time-file "html-help-time"
89
90 CONSTANT: benchmarks-file "benchmarks"
91 CONSTANT: benchmark-error-messages-file "benchmark-error-messages"
92 CONSTANT: benchmark-error-vocabs-file "benchmark-error-vocabs"
93
94 SYMBOL: status-error ! didn't bootstrap, or crashed
95 SYMBOL: status-dirty ! bootstrapped but not all tests passed
96 SYMBOL: status-clean ! everything good