]> gitweb.factorcode.org Git - factor.git/blob - extra/mason/common/common.factor
update existing code for [let change
[factor.git] / extra / mason / common / common.factor
1 ! Copyright (C) 2008, 2009 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 debugger fry
8 continuations strings io.sockets ;
9 IN: mason.common
10
11 : short-host-name ( -- string )
12     host-name "." split1 drop ;
13
14 SYMBOL: current-git-id
15
16 : short-running-process ( command -- )
17     #! Give network operations and shell commands at most
18     #! 15 minutes to complete, to catch hangs.
19     >process 15 minutes >>timeout try-output-process ;
20
21 HOOK: really-delete-tree os ( path -- )
22
23 M: windows really-delete-tree
24     #! Workaround: Cygwin GIT creates read-only files for
25     #! some reason.
26     [ { "chmod" "ug+rw" "-R" } swap (normalize-path) suffix short-running-process ]
27     [ delete-tree ]
28     bi ;
29
30 M: unix really-delete-tree delete-tree ;
31
32 : retry ( n quot -- )
33     '[ drop @ f ] attempt-all drop ; inline
34
35 :: upload-safely ( local username host remote -- )
36     remote ".incomplete" append :> temp
37     { username "@" host ":" temp } concat :> scp-remote
38     scp-command get :> scp
39     ssh-command get :> ssh
40     5 [ { scp local scp-remote } short-running-process ] retry
41     5 [ { ssh host "-l" username "mv" temp remote } short-running-process ] retry ;
42
43 : eval-file ( file -- obj )
44     dup utf8 file-lines parse-fresh
45     [ "Empty file: " swap append throw ] [ nip first ] if-empty ;
46
47 : to-file ( object file -- ) utf8 [ . ] with-file-writer ;
48
49 : datestamp ( timestamp -- string )
50     [
51         {
52             [ year>> , ]
53             [ month>> , ]
54             [ day>> , ]
55             [ hour>> , ]
56             [ minute>> , ]
57         } cleave
58     ] { } make [ pad-00 ] map "-" join ;
59
60 : milli-seconds>time ( n -- string )
61     millis>timestamp
62     [ hour>> ] [ minute>> ] [ second>> floor ] tri 3array
63     [ pad-00 ] map ":" join ;
64
65 SYMBOL: stamp
66
67 : builds/factor ( -- path ) builds-dir get "factor" append-path ;
68 : build-dir ( -- path ) builds-dir get stamp get append-path ;
69
70 : prepare-build-machine ( -- )
71     builds-dir get make-directories
72     builds-dir get
73     [ { "git" "clone" "git://factorcode.org/git/factor.git" } try-output-process ]
74     with-directory ;
75
76 : git-id ( -- id )
77     { "git" "show" } utf8 [ lines ] with-process-reader
78     first " " split second ;
79
80 : ?prepare-build-machine ( -- )
81     builds/factor exists? [ prepare-build-machine ] unless ;
82
83 CONSTANT: load-all-vocabs-file "load-everything-vocabs"
84 CONSTANT: load-all-errors-file "load-everything-errors"
85
86 CONSTANT: test-all-vocabs-file "test-all-vocabs"
87 CONSTANT: test-all-errors-file "test-all-errors"
88
89 CONSTANT: help-lint-vocabs-file "help-lint-vocabs"
90 CONSTANT: help-lint-errors-file "help-lint-errors"
91
92 CONSTANT: compiler-errors-file "compiler-errors"
93 CONSTANT: compiler-error-messages-file "compiler-error-messages"
94
95 CONSTANT: boot-time-file "boot-time"
96 CONSTANT: load-time-file "load-time"
97 CONSTANT: test-time-file "test-time"
98 CONSTANT: help-lint-time-file "help-lint-time"
99 CONSTANT: benchmark-time-file "benchmark-time"
100 CONSTANT: html-help-time-file "html-help-time"
101
102 CONSTANT: benchmarks-file "benchmarks"
103 CONSTANT: benchmark-error-messages-file "benchmark-error-messages"
104 CONSTANT: benchmark-error-vocabs-file "benchmark-error-vocabs"
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