]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/backend/backend.factor
namespaces: Rename ``bind`` to ``with-variables``. Update a few places that called...
[factor.git] / basis / tools / deploy / backend / backend.factor
1 ! Copyright (C) 2007, 2010 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 debugger
7 io.streams.c io.files io.files.temp io.pathnames io.directories
8 io.directories.hierarchy io.backend quotations io.launcher
9 tools.deploy.config tools.deploy.config.editor bootstrap.image
10 io.encodings.utf8 destructors accessors hashtables
11 tools.deploy.libraries vocabs.metadata.resources
12 tools.deploy.embed locals ;
13 IN: tools.deploy.backend
14
15 : copy-vm ( executable bundle-name -- vm )
16     prepend-path vm over copy-file ;
17
18 TUPLE: vocab-manifest vocabs libraries ;
19
20 : copy-resources ( manifest name dir -- )
21     append-path swap vocabs>> [ copy-vocab-resources ] with each ;
22
23 ERROR: can't-deploy-library-file library ;
24
25 : copy-library ( dir library -- )
26     dup find-library-file
27     [ swap over file-name append-path copy-file ]
28     [ can't-deploy-library-file ] ?if ;
29
30 : copy-libraries ( manifest name dir -- )
31     append-path swap libraries>> [ copy-library ] with each ;
32
33 : deployed-image-name ( vocab -- str )
34     ".image" append temp-file ;
35
36 : copy-lines ( -- )
37     readln [ print flush copy-lines ] when* ;
38
39 : run-with-output ( arguments -- )
40     <process>
41         swap >>command
42         +stdout+ >>stderr
43         +closed+ >>stdin
44         +low-priority+ >>priority
45     utf8 [ copy-lines ] with-process-reader ;
46
47 : make-boot-image ( -- )
48     #! If stage1 image doesn't exist, create one.
49     my-boot-image-name resource-path exists?
50     [ my-arch make-image ] unless ;
51
52 : bootstrap-profile ( -- profile )
53     [
54         deploy-math? get [ "math" , ] when
55         deploy-threads? get [ "threads" , ] when
56         "compiler" ,
57         deploy-help? get [ "help" , ] when
58         deploy-ui? get [ "ui" , ] when
59         deploy-unicode? get [ "unicode" , ] when
60         native-io? [ "io" , ] when
61     ] { } make ;
62
63 : staging-image-name ( profile -- name )
64     "-" join "." my-arch 3append
65     "staging." ".image" surround cache-file ;
66
67 DEFER: ?make-staging-image
68
69 : staging-command-line ( profile -- flags )
70     [
71         "-staging" ,
72         dup empty? [
73             "-i=" my-boot-image-name append ,
74         ] [
75             dup but-last ?make-staging-image
76             "-resource-path=" "" resource-path append ,
77             "-i=" over but-last staging-image-name append ,
78             "-run=tools.deploy.restage" ,
79         ] if
80         "-output-image=" over staging-image-name append ,
81         "-include=" swap " " join append ,
82         "-no-user-init" ,
83         "-pic=0" ,
84     ] { } make ;
85
86 : run-factor ( vm flags -- )
87     swap prefix dup . run-with-output ; inline
88
89 : make-staging-image ( profile -- )
90     vm swap staging-command-line run-factor ;
91
92 : ?make-staging-image ( profile -- )
93     dup staging-image-name exists?
94     [ drop ] [ make-staging-image ] if ;
95
96 : make-deploy-config ( vocab -- file )
97     [ deploy-config vocab-roots get vocab-roots associate assoc-union unparse-use ]
98     [ "deploy-config-" prepend temp-file ] bi
99     [ utf8 set-file-contents ] keep ;
100
101 : deploy-command-line ( image vocab manifest-file config -- flags )
102     [
103         bootstrap-profile ?make-staging-image
104
105         [
106             "-i=" bootstrap-profile staging-image-name append ,
107             "-resource-path=" "" resource-path append ,
108             "-run=tools.deploy.shaker" ,
109             "-vocab-manifest-out=" prepend ,
110             [ "-deploy-vocab=" prepend , ]
111             [ make-deploy-config "-deploy-config=" prepend , ] bi
112             "-output-image=" prepend ,
113             "-pic=0" ,
114         ] { } make
115     ] with-variables ;
116
117 : parse-vocab-manifest-file ( path -- vocab-manifest )
118     utf8 file-lines [ "empty vocab manifest!" throw ] [
119         unclip-slice "VOCABS:" =
120         [ { "LIBRARIES:" } split1 vocab-manifest boa ]
121         [ "invalid vocab manifest!" throw ] if
122     ] if-empty ;
123
124 :: make-deploy-image ( vm image vocab config -- manifest )
125     make-boot-image
126     vocab "vocab-manifest-" prepend temp-file :> manifest-file
127     image vocab manifest-file config deploy-command-line :> flags
128     vm flags run-factor
129     manifest-file parse-vocab-manifest-file ;
130
131 :: make-deploy-image-executable ( vm image vocab config -- manifest )
132     vm image vocab config make-deploy-image
133     image vm embed-image ;
134
135 HOOK: deploy* os ( vocab -- )