]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/backend/backend.factor
alien.libraries: add a "deploy-library" word that marks a library to have its dll...
[factor.git] / basis / tools / deploy / backend / backend.factor
1 ! Copyright (C) 2007, 2009 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 IN: tools.deploy.backend
13
14 : copy-vm ( executable bundle-name -- vm )
15     prepend-path vm over copy-file ;
16
17 TUPLE: vocab-manifest vocabs libraries ;
18
19 : copy-resources ( manifest name dir -- )
20     append-path swap vocabs>> [ copy-vocab-resources ] with each ;
21
22 ERROR: cant-deploy-library-file library ;
23 <PRIVATE
24 : copy-library ( dir library -- )
25     dup find-library-file
26     [ nip swap over file-name append-path copy-file ]
27     [ cant-deploy-library-file ] if* ;
28 PRIVATE>
29
30 : copy-libraries ( manifest name dir -- )
31     append-path swap libraries>> [ copy-library ] with each ;
32
33 : image-name ( vocab bundle-name -- str )
34     prepend-path ".image" append ;
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-ui? get [ "ui" , ] when
58         deploy-unicode? get [ "unicode" , ] when
59         native-io? [ "io" , ] when
60     ] { } make ;
61
62 : staging-image-name ( profile -- name )
63     "-" join "staging." ".image" surround temp-file ;
64
65 DEFER: ?make-staging-image
66
67 : staging-command-line ( profile -- flags )
68     [
69         "-staging" ,
70         dup empty? [
71             "-i=" my-boot-image-name append ,
72         ] [
73             dup but-last ?make-staging-image
74             "-resource-path=" "" resource-path append ,
75             "-i=" over but-last staging-image-name append ,
76             "-run=tools.deploy.restage" ,
77         ] if
78         "-output-image=" over staging-image-name append ,
79         "-include=" swap " " join append ,
80         "-no-user-init" ,
81         "-pic=0" ,
82     ] { } make ;
83
84 : run-factor ( vm flags -- )
85     swap prefix dup . run-with-output ; inline
86
87 : make-staging-image ( profile -- )
88     vm swap staging-command-line run-factor ;
89
90 : ?make-staging-image ( profile -- )
91     dup staging-image-name exists?
92     [ drop ] [ make-staging-image ] if ;
93
94 : make-deploy-config ( vocab -- file )
95     [ deploy-config vocab-roots get vocab-roots associate assoc-union unparse-use ]
96     [ "deploy-config-" prepend temp-file ] bi
97     [ utf8 set-file-contents ] keep ;
98
99 : deploy-command-line ( image vocab manifest-file config -- flags )
100     [
101         bootstrap-profile ?make-staging-image
102
103         [
104             "-i=" bootstrap-profile staging-image-name append ,
105             "-resource-path=" "" resource-path append ,
106             "-run=tools.deploy.shaker" ,
107             "-vocab-manifest-out=" prepend ,
108             [ "-deploy-vocab=" prepend , ]
109             [ make-deploy-config "-deploy-config=" prepend , ] bi
110             "-output-image=" prepend ,
111             "-pic=0" ,
112         ] { } make
113     ] bind ;
114
115 : parse-vocab-manifest-file ( path -- vocab-manifest )
116     utf8 file-lines
117     dup first "VOCABS:" =
118     [ "LIBRARIES:" split1 vocab-manifest boa ]
119     [ "invalid vocab manifest!" throw ] if ;
120
121 : make-deploy-image ( vm image vocab config -- manifest )
122     make-boot-image
123     over "vocab-manifest-" prepend temp-file
124     [ swap deploy-command-line run-factor ]
125     [ parse-vocab-manifest-file ] bi ;
126
127 HOOK: deploy* os ( vocab -- )