]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/backend/backend.factor
Move make to its own vocabulary, remove fry _ feature
[factor.git] / basis / tools / deploy / backend / backend.factor
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces make continuations.private kernel.private init
4 assocs kernel vocabs words sequences memory io system arrays
5 continuations math definitions mirrors splitting parser classes
6 summary layouts vocabs.loader prettyprint.config prettyprint
7 debugger io.streams.c io.files io.backend quotations io.launcher
8 words.private tools.deploy.config bootstrap.image
9 io.encodings.utf8 destructors accessors ;
10 IN: tools.deploy.backend
11
12 : copy-vm ( executable bundle-name extension -- vm )
13   [ prepend-path ] dip append vm over copy-file ;
14
15 : copy-fonts ( name dir -- )
16   append-path "resource:fonts/" swap copy-tree-into ;
17
18 : image-name ( vocab bundle-name -- str )
19   prepend-path ".image" append ;
20
21 : (copy-lines) ( stream -- )
22     dup stream-readln dup
23     [ print flush (copy-lines) ] [ 2drop ] if ;
24
25 : copy-lines ( stream -- )
26     [ (copy-lines) ] with-disposal ;
27
28 : run-with-output ( arguments -- )
29     <process>
30         swap >>command
31         +stdout+ >>stderr
32         +closed+ >>stdin
33         +low-priority+ >>priority
34     utf8 <process-reader*>
35     copy-lines
36     wait-for-process zero? [ "Deployment failed" throw ] unless ;
37
38 : make-boot-image ( -- )
39     #! If stage1 image doesn't exist, create one.
40     my-boot-image-name resource-path exists?
41     [ my-arch make-image ] unless ;
42
43 : bootstrap-profile ( -- profile )
44     {
45         { "math"     deploy-math?     }
46         { "compiler" deploy-compiler? }
47         { "threads"  deploy-threads?  }
48         { "ui"       deploy-ui?       }
49         { "random"   deploy-random?   }
50     } [ nip get ] assoc-filter keys
51     native-io? [ "io" suffix ] when ;
52
53 : staging-image-name ( profile -- name )
54     "staging."
55     swap strip-word-names? [ "strip" suffix ] when
56     "-" join ".image" 3append temp-file ;
57
58 DEFER: ?make-staging-image
59
60 : staging-command-line ( profile -- flags )
61     [
62         dup empty? [
63             "-i=" my-boot-image-name append ,
64         ] [
65             dup but-last ?make-staging-image
66
67             "-resource-path=" "" resource-path append ,
68
69             "-i=" over but-last staging-image-name append ,
70
71             "-run=tools.deploy.restage" ,
72         ] if
73
74         "-output-image=" over staging-image-name append ,
75
76         "-include=" swap " " join append ,
77
78         strip-word-names? [ "-no-stack-traces" , ] when
79
80         "-no-user-init" ,
81     ] { } make ;
82
83 : run-factor ( vm flags -- )
84     swap prefix dup . run-with-output ; inline
85
86 : make-staging-image ( profile -- )
87     vm swap staging-command-line run-factor ;
88
89 : ?make-staging-image ( profile -- )
90     dup staging-image-name exists?
91     [ drop ] [ make-staging-image ] if ;
92
93 : deploy-command-line ( image vocab config -- flags )
94     [
95         bootstrap-profile ?make-staging-image
96
97         [
98             "-i=" bootstrap-profile staging-image-name append ,
99
100             "-resource-path=" "" resource-path append ,
101
102             "-run=tools.deploy.shaker" ,
103
104             "-deploy-vocab=" prepend ,
105
106             "-output-image=" prepend ,
107
108             strip-word-names? [ "-no-stack-traces" , ] when
109         ] { } make
110     ] bind ;
111
112 : make-deploy-image ( vm image vocab config -- )
113     make-boot-image
114     deploy-command-line run-factor ;
115
116 HOOK: deploy* os ( vocab -- )