factor/extra/tools/deploy/backend/backend.factor

119 lines
3.2 KiB
Factor
Raw Normal View History

2008-01-05 19:37:13 -05:00
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces continuations.private kernel.private init
assocs kernel vocabs words sequences memory io system arrays
continuations math definitions mirrors splitting parser classes
inspector layouts vocabs.loader prettyprint.config prettyprint
debugger io.streams.c io.streams.duplex io.files io.backend
quotations io.launcher words.private tools.deploy.config
2008-03-06 21:44:52 -05:00
bootstrap.image io.encodings.utf8 accessors ;
2008-01-05 19:37:13 -05:00
IN: tools.deploy.backend
: (copy-lines) ( stream -- )
dup stream-readln dup
[ print flush (copy-lines) ] [ 2drop ] if ;
: copy-lines ( stream -- )
[ (copy-lines) ] with-disposal ;
2008-02-03 21:36:04 -05:00
: run-with-output ( arguments -- )
2008-03-06 21:44:52 -05:00
<process>
swap >>command
+stdout+ >>stderr
+closed+ >>stdin
2008-03-26 16:59:11 -04:00
+low-priority+ >>priority
2008-04-11 17:08:40 -04:00
utf8 <process-stream*>
>r copy-lines r> wait-for-process zero? [
2008-02-08 22:15:29 -05:00
"Deployment failed" throw
] unless ;
: make-boot-image ( -- )
2008-01-05 19:37:13 -05:00
#! If stage1 image doesn't exist, create one.
my-boot-image-name resource-path exists?
2008-01-05 19:37:13 -05:00
[ my-arch make-image ] unless ;
: ?, [ , ] [ drop ] if ;
2008-01-05 19:37:13 -05:00
: bootstrap-profile ( -- profile )
[
"math" deploy-math? get ?,
"compiler" deploy-compiler? get ?,
"ui" deploy-ui? get ?,
"io" native-io? ?,
2008-03-20 22:11:53 -04:00
"random" deploy-random? get ?,
] { } make ;
2008-01-05 19:37:13 -05:00
2008-03-20 22:11:53 -04:00
: staging-image-name ( profile -- name )
"staging."
swap strip-word-names? [ "strip" suffix ] when
2008-03-20 22:11:53 -04:00
"-" join ".image" 3append temp-file ;
2008-01-05 19:37:13 -05:00
2008-03-20 22:11:53 -04:00
DEFER: ?make-staging-image
: staging-command-line ( profile -- flags )
2008-01-05 19:37:13 -05:00
[
2008-03-20 22:11:53 -04:00
dup empty? [
"-i=" my-boot-image-name append ,
2008-03-20 22:11:53 -04:00
] [
dup 1 head* ?make-staging-image
2008-03-20 22:11:53 -04:00
"-resource-path=" "" resource-path append ,
2008-03-20 22:11:53 -04:00
"-i=" over 1 head* staging-image-name append ,
2008-03-20 22:11:53 -04:00
"-run=tools.deploy.restage" ,
] if
2008-03-20 22:11:53 -04:00
"-output-image=" over staging-image-name append ,
"-include=" swap " " join append ,
strip-word-names? [ "-no-stack-traces" , ] when
"-no-user-init" ,
] { } make ;
2008-01-05 19:37:13 -05:00
: run-factor ( vm flags -- )
swap prefix dup . run-with-output ; inline
2008-03-20 22:11:53 -04:00
: make-staging-image ( profile -- )
2008-03-14 18:39:57 -04:00
vm swap staging-command-line run-factor ;
2008-03-20 22:11:53 -04:00
: ?make-staging-image ( profile -- )
dup staging-image-name exists?
2008-03-14 18:39:57 -04:00
[ drop ] [ make-staging-image ] if ;
: deploy-command-line ( image vocab config -- flags )
2008-01-05 19:37:13 -05:00
[
2008-03-20 22:11:53 -04:00
bootstrap-profile ?make-staging-image
[
2008-03-20 22:11:53 -04:00
"-i=" bootstrap-profile staging-image-name append ,
"-resource-path=" "" resource-path append ,
"-run=tools.deploy.shaker" ,
2008-01-05 19:37:13 -05:00
"-deploy-vocab=" prepend ,
2008-01-05 19:37:13 -05:00
"-output-image=" prepend ,
2008-01-05 19:37:13 -05:00
strip-word-names? [ "-no-stack-traces" , ] when
] { } make
] bind ;
2008-01-05 19:37:13 -05:00
: make-deploy-image ( vm image vocab config -- )
2008-02-04 21:49:59 -05:00
make-boot-image
deploy-command-line run-factor ;
: copy-vm ( executable bundle-name extension -- vm )
[ prepend-path ] dip append vm over copy-file ;
: copy-fonts ( name dir -- )
append-path "fonts/" resource-path swap copy-tree-into ;
: image-name ( vocab bundle-name -- str )
prepend-path ".image" append ;
2008-01-05 19:37:13 -05:00
2008-04-02 20:46:37 -04:00
HOOK: deploy* os ( vocab -- )