 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-SYMBOL: build-status
-
-: build ( -- )
-
-  "running" build-status set-global
-
-  datestamp >stamp
-
-  "/builds/factor" cd
-  
+: git-pull ( -- desc )
   {
     "git"
     "pull"
     "--no-summary"
     "git://factorcode.org/git/factor.git"
     "master"
-  }
-  run-process process-status
-  0 =
-  [ ]
-  [
-    "builder: git pull" email-string
-    "builder: git pull" throw
-  ]
-  if
+  } ;
 
-  {
-    "git" "pull" "--no-summary"
-    "http://dharmatech.onigirihouse.com/factor.git" "master"
-  } run-process drop
+: git-clone ( -- desc ) { "git" "clone" "../factor" } ;
 
-  "/builds/" stamp> append make-directory
-  "/builds/" stamp> append cd
+: enter-build-dir ( -- )
+  datestamp >stamp
+  "/builds" cd
+  stamp> make-directory
+  stamp> cd ;
 
-  { "git" "clone" "../factor" } run-process drop
+: record-git-id ( -- )
+  { "git" "show" } <process-stream> [ readln ] with-stream " " split second
+  "../git-id" log-object ;
 
-  "factor" cd
+: make-clean ( -- desc ) { "make" "clean" } ;
 
-  { "git" "show" } <process-stream> [ readln ] with-stream " " split second
-  "../git-id" log-object
-
-  { "make" "clean" } run-process drop
-
-  ! "vm" build-status set-global
-
+: make-vm ( -- )
   `{
      { +arguments+ { "make" ,[ target ] } }
      { +stdout+    "../compile-log" }
      { +stderr+    +stdout+ }
    }
-  >hashtable run-process process-status
-  0 =
-  [ ]
-  [
-    "builder: vm compile" "../compile-log" email-file
-    "builder: vm compile" throw
-  ] if
+  >hashtable ;
 
+: retrieve-boot-image ( -- )
   [ my-arch download-image ]
   [ ]
   [ "builder: image download" email-string ]
-  cleanup
+  cleanup ;
 
-  ! "bootstrap" build-status set-global
-
+: bootstrap ( -- desc )
   `{
      { +arguments+ {
                      ,[ factor-binary ]


USING: kernel io io.files io.launcher hashtables
       system continuations namespaces sequences splitting math.parser
       prettyprint tools.time calendar bake vars http.client
       combinators bootstrap.image bootstrap.image.download ;

IN: builder



SYMBOL: builder-recipients

: tag-subject ( str -- str ) `{ "builder@" ,[ host-name ] ": " , } concat ;

: email-string ( subject -- )
  `{ "mutt" "-s" ,[ tag-subject ] %[ builder-recipients get ] }
  [ ] with-process-stream drop ;

: email-file ( subject file -- )
  `{
    { +stdin+ , }
    { +arguments+
      { "mutt" "-s" ,[ tag-subject ] %[ builder-recipients get ] } }
  }
  >hashtable run-process drop ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: 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
  r> r> [ email-string throw ] 2curry
  recover ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

