]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/backend/backend.factor
Merge branch 'master' into experimental (untested!)
[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 tools.deploy.config.editor
9 bootstrap.image 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     deploy-ui? get [
17         append-path "resource:fonts/" swap copy-tree-into
18     ] [ 2drop ] if ;
19
20 : image-name ( vocab bundle-name -- str )
21     prepend-path ".image" append ;
22
23 : copy-lines ( -- )
24     readln [ print flush copy-lines ] when* ;
25
26 : run-with-output ( arguments -- )
27     <process>
28         swap >>command
29         +stdout+ >>stderr
30         +closed+ >>stdin
31         +low-priority+ >>priority
32     utf8 [ copy-lines ] with-process-reader ;
33
34 : make-boot-image ( -- )
35     #! If stage1 image doesn't exist, create one.
36     my-boot-image-name resource-path exists?
37     [ my-arch make-image ] unless ;
38
39 : bootstrap-profile ( -- profile )
40     {
41         { "math"     deploy-math?     }
42         { "compiler" deploy-compiler? }
43         { "threads"  deploy-threads?  }
44         { "ui"       deploy-ui?       }
45         { "unicode"  deploy-unicode?  }
46     } [ nip get ] assoc-filter keys
47     native-io? [ "io" suffix ] when ;
48
49 : staging-image-name ( profile -- name )
50     "staging."
51     swap strip-word-names? [ "strip" suffix ] when
52     "-" join ".image" 3append temp-file ;
53
54 DEFER: ?make-staging-image
55
56 : staging-command-line ( profile -- flags )
57     [
58         "-staging" ,
59
60         dup empty? [
61             "-i=" my-boot-image-name append ,
62         ] [
63             dup but-last ?make-staging-image
64
65             "-resource-path=" "" resource-path append ,
66
67             "-i=" over but-last staging-image-name append ,
68
69             "-run=tools.deploy.restage" ,
70         ] if
71
72         "-output-image=" over staging-image-name append ,
73
74         "-include=" swap " " join append ,
75
76         strip-word-names? [ "-no-stack-traces" , ] when
77
78         "-no-user-init" ,
79     ] { } make ;
80
81 : run-factor ( vm flags -- )
82     swap prefix dup . run-with-output ; inline
83
84 : make-staging-image ( profile -- )
85     vm swap staging-command-line run-factor ;
86
87 : ?make-staging-image ( profile -- )
88     dup staging-image-name exists?
89     [ drop ] [ make-staging-image ] if ;
90
91 : make-deploy-config ( vocab -- file )
92     [ deploy-config unparse-use ]
93     [ "deploy-config-" prepend temp-file ] bi
94     [ utf8 set-file-contents ] keep ;
95
96 : deploy-command-line ( image vocab config -- flags )
97     [
98         bootstrap-profile ?make-staging-image
99
100         [
101             "-i=" bootstrap-profile staging-image-name append ,
102
103             "-resource-path=" "" resource-path append ,
104
105             "-run=tools.deploy.shaker" ,
106
107             [ "-deploy-vocab=" prepend , ]
108             [ make-deploy-config "-deploy-config=" prepend , ] bi
109
110             "-output-image=" prepend ,
111
112             strip-word-names? [ "-no-stack-traces" , ] when
113         ] { } make
114     ] bind ;
115
116 : make-deploy-image ( vm image vocab config -- )
117     make-boot-image
118     deploy-command-line run-factor ;
119
120 HOOK: deploy* os ( vocab -- )