factor/extra/builder/builder.factor

308 lines
6.6 KiB
Factor
Raw Normal View History

2008-01-31 01:25:06 -05:00
2008-02-11 15:59:02 -05:00
USING: kernel io io.files io.launcher io.sockets hashtables math threads
2008-02-04 22:26:59 -05:00
system continuations namespaces sequences splitting math.parser
2008-02-04 22:58:57 -05:00
prettyprint tools.time calendar bake vars http.client
2008-02-10 02:04:14 -05:00
combinators bootstrap.image bootstrap.image.download
combinators.cleave ;
2008-01-31 01:25:06 -05:00
IN: builder
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-06 05:26:13 -05:00
: runtime ( quot -- time ) benchmark nip ;
: log-runtime ( quot file -- )
>r runtime r> <file-writer> [ . ] with-stream ;
: log-object ( object file -- ) <file-writer> [ . ] with-stream ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-01-31 01:25:06 -05:00
: datestamp ( -- string )
now `{ ,[ dup timestamp-year ]
,[ dup timestamp-month ]
,[ dup timestamp-day ]
,[ dup timestamp-hour ]
,[ timestamp-minute ] }
2008-02-05 00:48:18 -05:00
[ pad-00 ] map "-" join ;
2008-01-31 01:25:06 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SYMBOL: builder-recipients
2008-02-10 04:01:20 -05:00
: host-name* ( -- name ) host-name "." split first ;
: tag-subject ( str -- str ) `{ "builder@" ,[ host-name* ] ": " , } concat ;
2008-02-10 02:04:14 -05:00
: email-string ( subject -- )
`{ "mutt" "-s" ,[ tag-subject ] %[ builder-recipients get ] }
[ ] with-process-stream drop ;
2008-01-31 01:25:06 -05:00
: email-file ( subject file -- )
`{
2008-02-04 22:26:59 -05:00
{ +stdin+ , }
2008-02-10 02:04:14 -05:00
{ +arguments+
{ "mutt" "-s" ,[ tag-subject ] %[ builder-recipients get ] } }
2008-02-04 22:26:59 -05:00
}
>hashtable run-process drop ;
2008-02-10 02:04:14 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: run-or-notify ( desc message -- )
[ [ try-process ] curry ]
[ [ email-string throw ] curry ]
bi*
recover ;
: run-or-send-file ( desc message file -- )
>r >r [ try-process ] curry
2008-02-10 04:05:34 -05:00
r> r> [ email-file throw ] 2curry
2008-02-10 02:04:14 -05:00
recover ;
2008-02-04 22:26:59 -05:00
2008-01-31 01:25:06 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-06 00:09:33 -05:00
: target ( -- target ) `{ ,[ os ] %[ cpu "." split ] } "-" join ;
2008-02-05 19:28:05 -05:00
2008-01-31 01:25:06 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-04 22:58:57 -05:00
: factor-binary ( -- name )
os
{ { "macosx" [ "./Factor.app/Contents/MacOS/factor" ] }
2008-02-06 00:09:33 -05:00
{ "winnt" [ "./factor-nt.exe" ] }
2008-02-04 22:58:57 -05:00
[ drop "./factor" ] }
case ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-01-31 01:25:06 -05:00
VAR: stamp
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-10 02:04:14 -05:00
: git-pull ( -- desc )
2008-02-06 00:09:33 -05:00
{
"git"
"pull"
"--no-summary"
2008-02-07 16:14:40 -05:00
"git://factorcode.org/git/factor.git"
2008-02-06 00:09:33 -05:00
"master"
2008-02-10 02:04:14 -05:00
} ;
2008-02-07 19:30:20 -05:00
2008-02-10 02:04:14 -05:00
: git-clone ( -- desc ) { "git" "clone" "../factor" } ;
2008-02-04 22:26:59 -05:00
2008-02-10 02:04:14 -05:00
: enter-build-dir ( -- )
datestamp >stamp
"/builds" cd
stamp> make-directory
stamp> cd ;
2008-02-04 22:26:59 -05:00
2008-02-11 15:59:02 -05:00
: git-id ( -- id )
{ "git" "show" } <process-stream> [ readln ] with-stream " " split second ;
: record-git-id ( -- ) git-id "../git-id" log-object ;
2008-02-04 22:26:59 -05:00
2008-02-10 02:04:14 -05:00
: make-clean ( -- desc ) { "make" "clean" } ;
2008-02-08 21:09:59 -05:00
2008-02-10 02:04:14 -05:00
: make-vm ( -- )
2008-02-04 22:26:59 -05:00
`{
{ +arguments+ { "make" ,[ target ] } }
{ +stdout+ "../compile-log" }
{ +stderr+ +stdout+ }
}
2008-02-10 02:04:14 -05:00
>hashtable ;
2008-02-04 22:26:59 -05:00
2008-02-10 02:04:14 -05:00
: retrieve-boot-image ( -- )
[ my-arch download-image ]
[ ]
2008-02-04 22:26:59 -05:00
[ "builder: image download" email-string ]
2008-02-11 15:59:02 -05:00
cleanup
flush ;
2008-02-08 21:09:59 -05:00
2008-02-10 02:04:14 -05:00
: bootstrap ( -- desc )
2008-02-04 22:26:59 -05:00
`{
{ +arguments+ {
2008-02-04 22:58:57 -05:00
,[ factor-binary ]
,[ "-i=" my-boot-image-name append ]
2008-02-04 22:26:59 -05:00
"-no-user-init"
} }
{ +stdout+ "../boot-log" }
{ +stderr+ +stdout+ }
}
2008-02-10 02:04:14 -05:00
>hashtable ;
2008-02-04 22:26:59 -05:00
2008-02-10 02:04:14 -05:00
: builder-test ( -- desc ) `{ ,[ factor-binary ] "-run=builder.test" } ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-08 21:09:59 -05:00
! SYMBOL: build-status
2008-02-10 02:04:14 -05:00
! : build ( -- )
2008-02-10 02:04:14 -05:00
! enter-build-dir
2008-02-10 02:04:14 -05:00
! git-clone "git clone error" run-or-notify
! "factor" cd
! record-git-id
! make-clean "make clean error" run-or-notify
! make-vm "vm compile error" "../compile-log" run-or-send-file
! retrieve-boot-image
! bootstrap "bootstrap error" "../boot-log" run-or-send-file
! builder-test "builder.test fatal error" run-or-notify
! "../load-everything-log" exists?
! [ "load-everything" "../load-everything-log" email-file ]
! when
! "../failing-tests" exists?
! [ "failing tests" "../failing-tests" email-file ]
! when ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SYMBOL: report
: (build) ( -- )
enter-build-dir
"report" <file-writer> report set
report get [ "Build machine: " write host-name write nl ] with-stream*
report get [ "Build directory: " write cwd write nl ] with-stream*
[ git-clone try-process ]
[
report get
[ "Builder fatal error: git clone failed" write nl ]
with-stream*
throw
]
recover
2008-02-10 02:04:14 -05:00
"factor" cd
record-git-id
make-clean run-process drop
2008-02-10 02:04:14 -05:00
[ make-vm try-process ]
[
report get
[
"Builder fatal error: vm compile error" write nl
"../compile-log" <file-reader> contents write
]
with-stream*
throw
]
recover
2008-02-10 02:04:14 -05:00
[ my-arch download-image ]
[
report get
[ "Builder fatal error: image download" write nl ]
with-stream*
throw
]
recover
2008-02-10 02:04:14 -05:00
[ bootstrap try-process ]
[
report get
[
"Bootstrap error" write nl
"../boot-log" <file-reader> contents write
]
with-stream*
throw
]
recover
2008-02-10 02:04:14 -05:00
[ builder-test try-process ]
[
report get
[
"Builder test error" write nl
"../load-everything-log" exists?
[ "../load-everything-log" <file-reader> contents write nl ]
when
"../test-all-log" exists?
[ "../test-all-log" <file-reader> contents write nl ]
when
]
with-stream*
throw
]
recover
report get
[
"Bootstrap time: " write
"../bootstrap-time" <file-reader> contents write nl
]
with-stream*
"../load-everything-vocabs" exists?
[
report get
[
"Did not pass load-everything: " write nl
"../load-everything-vocabs" <file-reader> contents write nl
]
with-stream*
]
2008-02-06 00:09:33 -05:00
when
"../test-all-vocabs" exists?
[
report get
[
"Did not pass test-all: " write nl
"../test-all-vocabs" <file-reader> contents write nl
]
with-stream*
]
2008-02-11 15:59:02 -05:00
when ;
: send-report ( -- )
report get dispose
"report" "../report" email-file ;
: build ( -- )
[ (build) ]
[ drop ]
recover
send-report ;
2008-02-11 15:59:02 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-06 05:26:13 -05:00
2008-02-11 15:59:02 -05:00
: minutes>ms ( min -- ms ) 60 * 1000 * ;
: updates-available? ( -- ? )
git-id
git-pull run-process drop
git-id
= not ;
: build-loop ( -- )
[
"/builds/factor" cd
updates-available?
[ build ]
when
]
[ drop ]
recover
5 minutes>ms sleep
build-loop ;
2008-01-31 01:25:06 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-02-11 15:59:02 -05:00
MAIN: build-loop