Add try-process word

db4
Slava Pestov 2008-02-08 21:15:29 -06:00
parent d7af06c75a
commit 52d91bf0bc
9 changed files with 36 additions and 11 deletions

View File

@ -9,6 +9,6 @@ IN: benchmark.bootstrap2
"-i=" my-boot-image-name append , "-i=" my-boot-image-name append ,
"-output-image=foo.image" , "-output-image=foo.image" ,
"-no-user-init" , "-no-user-init" ,
] { } make run-process drop ; ] { } make try-process ;
MAIN: bootstrap-benchmark MAIN: bootstrap-benchmark

3
extra/bootstrap/image/upload/upload.factor Normal file → Executable file
View File

@ -16,8 +16,7 @@ bootstrap.image sequences io namespaces io.launcher math ;
: upload-images ( -- ) : upload-images ( -- )
[ [
"scp" , boot-image-names % "checksums.txt" , destination , "scp" , boot-image-names % "checksums.txt" , destination ,
] { } make run-process ] { } make try-process ;
wait-for-process zero? [ "Upload failed" throw ] unless ;
: new-images ( -- ) : new-images ( -- )
make-images compute-checksums upload-images ; make-images compute-checksums upload-images ;

View File

@ -8,7 +8,7 @@ IN: editors.emacs
"--no-wait" , "--no-wait" ,
"+" swap number>string append , "+" swap number>string append ,
, ,
] { } make run-process drop ; ] { } make try-process ;
: emacs ( word -- ) : emacs ( word -- )
where first2 emacsclient ; where first2 emacsclient ;

View File

@ -5,6 +5,6 @@ IN: editors.textmate
: textmate-location ( file line -- ) : textmate-location ( file line -- )
[ "mate" , "-a" , "-l" , number>string , , ] { } make [ "mate" , "-a" , "-l" , number>string , , ] { } make
run-process drop ; try-process ;
[ textmate-location ] edit-hook set-global [ textmate-location ] edit-hook set-global

View File

@ -116,6 +116,15 @@ HELP: run-detached
"The output value can be passed to " { $link wait-for-process } " to get an exit code." "The output value can be passed to " { $link wait-for-process } " to get an exit code."
} ; } ;
HELP: process-failed
{ $values { "code" "an exit status" } }
{ $description "Throws a " { $link process-failed } " error." }
{ $error-description "Thrown by " { $link try-process } " if the process exited with a non-zero status code." } ;
HELP: try-process
{ $values { "desc" "a launch descriptor" } }
{ $description "Launches a process and waits for it to complete. If it exits with a non-zero status code, throws a " { $link process-failed } " error." } ;
HELP: kill-process HELP: kill-process
{ $values { "process" process } } { $values { "process" process } }
{ $description "Kills a running process. Does nothing if the process has already exited." } ; { $description "Kills a running process. Does nothing if the process has already exited." } ;
@ -175,6 +184,7 @@ $nl
"The following words are used to launch processes:" "The following words are used to launch processes:"
{ $subsection run-process } { $subsection run-process }
{ $subsection run-detached } { $subsection run-detached }
{ $subsection try-process }
"Stopping processes:" "Stopping processes:"
{ $subsection kill-process } { $subsection kill-process }
"Redirecting standard input and output to a pipe:" "Redirecting standard input and output to a pipe:"

View File

@ -84,6 +84,15 @@ HOOK: run-process* io-backend ( desc -- handle )
: run-detached ( desc -- process ) : run-detached ( desc -- process )
>descriptor H{ { +detached+ t } } union run-process ; >descriptor H{ { +detached+ t } } union run-process ;
TUPLE: process-failed code ;
: process-failed ( code -- * )
process-failed construct-boa throw ;
: try-process ( desc -- )
run-process wait-for-process dup zero?
[ drop ] [ process-failed ] if ;
HOOK: kill-process* io-backend ( handle -- ) HOOK: kill-process* io-backend ( handle -- )
: kill-process ( process -- ) : kill-process ( process -- )

View File

@ -2,13 +2,17 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: parser-combinators memoize kernel sequences USING: parser-combinators memoize kernel sequences
logging arrays words strings vectors io io.files logging arrays words strings vectors io io.files
namespaces combinators combinators.lib logging.server ; namespaces combinators combinators.lib logging.server
calendar ;
IN: logging.parser IN: logging.parser
: string-of satisfy <!*> [ >string ] <@ ; : string-of satisfy <!*> [ >string ] <@ ;
SYMBOL: multiline
: 'date' : 'date'
[ CHAR: ] eq? not ] string-of multiline-header token [ drop multiline ] <@
[ CHAR: ] eq? not ] string-of [ rfc3339>timestamp ] <@ <|>
"[" "]" surrounded-by ; "[" "]" surrounded-by ;
: 'log-level' : 'log-level'
@ -41,7 +45,7 @@ MEMO: 'log-line' ( -- parser )
first malformed eq? ; first malformed eq? ;
: multiline? ( line -- ? ) : multiline? ( line -- ? )
first first CHAR: - = ; first multiline eq? ;
: malformed-line : malformed-line
"Warning: malformed log line:" print "Warning: malformed log line:" print

View File

@ -22,7 +22,10 @@ IN: tools.deploy.backend
+stdout+ +stderr+ set +stdout+ +stderr+ set
] H{ } make-assoc <process-stream> ] H{ } make-assoc <process-stream>
dup duplex-stream-out dispose dup duplex-stream-out dispose
copy-lines ; dup copy-lines
process-stream-process wait-for-process zero? [
"Deployment failed" throw
] unless ;
: make-boot-image ( -- ) : make-boot-image ( -- )
#! If stage1 image doesn't exist, create one. #! If stage1 image doesn't exist, create one.

View File

@ -8,10 +8,10 @@ QUALIFIED: unix
IN: tools.deploy.macosx IN: tools.deploy.macosx
: touch ( path -- ) : touch ( path -- )
{ "touch" } swap add run-process drop ; { "touch" } swap add try-process ;
: rm ( path -- ) : rm ( path -- )
{ "rm" "-rf" } swap add run-process drop ; { "rm" "-rf" } swap add try-process ;
: bundle-dir ( -- dir ) : bundle-dir ( -- dir )
vm parent-directory parent-directory ; vm parent-directory parent-directory ;