]> gitweb.factorcode.org Git - factor.git/blob - extra/mason/common/common.factor
a3ff1a8ff5116854c66d424f8a9544347aa55a3a
[factor.git] / extra / mason / common / common.factor
1 ! Copyright (C) 2008 Eduardo Cavazos, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel namespaces sequences splitting system accessors
4 math.functions make io io.files io.pathnames io.directories
5 io.directories.hierarchy io.launcher io.encodings.utf8 prettyprint
6 combinators.short-circuit parser combinators calendar
7 calendar.format arrays mason.config locals system ;
8 IN: mason.common
9
10 HOOK: really-delete-tree os ( path -- )
11
12 M: windows really-delete-tree
13     #! Workaround: Cygwin GIT creates read-only files for
14     #! some reason.
15     [ { "chmod" "ug+rw" "-R" } swap (normalize-path) suffix try-process ]
16     [ delete-tree ]
17     bi ;
18
19 M: unix really-delete-tree delete-tree ;
20
21 : short-running-process ( command -- )
22     #! Give network operations at most 15 minutes to complete.
23     <process>
24         swap >>command
25         15 minutes >>timeout
26     try-process ;
27
28 :: upload-safely ( local username host remote -- )
29     [let* | temp [ remote ".incomplete" append ]
30             scp-remote [ { username "@" host ":" temp } concat ]
31             scp [ scp-command get ]
32             ssh [ ssh-command get ] |
33         { scp local scp-remote } short-running-process
34         { ssh host "-l" username "mv" temp remote } short-running-process
35     ] ;
36
37 : eval-file ( file -- obj )
38     dup utf8 file-lines parse-fresh
39     [ "Empty file: " swap append throw ] [ nip first ] if-empty ;
40
41 : cat ( file -- ) utf8 file-contents print ;
42
43 : cat-n ( file n -- ) [ utf8 file-lines ] dip short tail* [ print ] each ;
44
45 : to-file ( object file -- ) utf8 [ . ] with-file-writer ;
46
47 : datestamp ( timestamp -- string )
48     [
49         {
50             [ year>> , ]
51             [ month>> , ]
52             [ day>> , ]
53             [ hour>> , ]
54             [ minute>> , ]
55         } cleave
56     ] { } make [ pad-00 ] map "-" join ;
57
58 : milli-seconds>time ( n -- string )
59     millis>timestamp
60     [ hour>> ] [ minute>> ] [ second>> floor ] tri 3array
61     [ pad-00 ] map ":" join ;
62
63 SYMBOL: stamp
64
65 : builds/factor ( -- path ) builds-dir get "factor" append-path ;
66 : build-dir ( -- path ) builds-dir get stamp get append-path ;
67
68 : prepare-build-machine ( -- )
69     builds-dir get make-directories
70     builds-dir get
71     [ { "git" "clone" "git://factorcode.org/git/factor.git" } try-process ]
72     with-directory ;
73
74 : git-id ( -- id )
75     { "git" "show" } utf8 [ readln ] with-process-reader
76     " " split second ;
77
78 : ?prepare-build-machine ( -- )
79     builds/factor exists? [ prepare-build-machine ] unless ;
80
81 CONSTANT: load-everything-vocabs-file "load-everything-vocabs"
82 CONSTANT: load-everything-errors-file "load-everything-errors"
83
84 CONSTANT: test-all-vocabs-file "test-all-vocabs"
85 CONSTANT: test-all-errors-file "test-all-errors"
86
87 CONSTANT: help-lint-vocabs-file "help-lint-vocabs"
88 CONSTANT: help-lint-errors-file "help-lint-errors"
89
90 CONSTANT: compiler-errors-file "compiler-errors"
91 CONSTANT: compiler-error-messages-file "compiler-error-messages"
92
93 CONSTANT: boot-time-file "boot-time"
94 CONSTANT: load-time-file "load-time"
95 CONSTANT: test-time-file "test-time"
96 CONSTANT: help-lint-time-file "help-lint-time"
97 CONSTANT: benchmark-time-file "benchmark-time"
98 CONSTANT: html-help-time-file "html-help-time"
99
100 CONSTANT: benchmarks-file "benchmarks"
101 CONSTANT: benchmark-error-messages-file "benchmark-error-messages"
102 CONSTANT: benchmark-error-vocabs-file "benchmark-error-vocabs"
103
104 SYMBOL: status
105
106 SYMBOL: status-error ! didn't bootstrap, or crashed
107 SYMBOL: status-dirty ! bootstrapped but not all tests passed
108 SYMBOL: status-clean ! everything good