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
15 : copy-vm ( executable bundle-name -- vm )
16 prepend-path vm over copy-file ;
18 TUPLE: vocab-manifest vocabs libraries ;
20 : copy-resources ( manifest name dir -- )
21 append-path swap vocabs>> [ copy-vocab-resources ] with each ;
23 ERROR: can't-deploy-library-file library ;
25 : copy-library ( dir library -- )
27 [ swap over file-name append-path copy-file ]
28 [ can't-deploy-library-file ] ?if ;
30 : copy-libraries ( manifest name dir -- )
31 append-path swap libraries>> [ copy-library ] with each ;
33 : deployed-image-name ( vocab -- str )
34 ".image" append temp-file ;
37 readln [ print flush copy-lines ] when* ;
39 : run-with-output ( arguments -- )
44 +low-priority+ >>priority
45 utf8 [ copy-lines ] with-process-reader ;
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 ;
52 : bootstrap-profile ( -- profile )
54 deploy-math? get [ "math" , ] when
55 deploy-threads? get [ "threads" , ] when
57 deploy-help? get [ "help" , ] when
58 deploy-ui? get [ "ui" , ] when
59 deploy-unicode? get [ "unicode" , ] when
60 native-io? [ "io" , ] when
63 : staging-image-name ( profile -- name )
64 "-" join "." my-arch 3append
65 "staging." ".image" surround cache-file ;
67 DEFER: ?make-staging-image
69 : staging-command-line ( profile -- flags )
73 "-i=" my-boot-image-name append ,
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" ,
80 "-output-image=" over staging-image-name append ,
81 "-include=" swap " " join append ,
86 : run-factor ( vm flags -- )
87 swap prefix dup . run-with-output ; inline
89 : make-staging-image ( profile -- )
90 vm swap staging-command-line run-factor ;
92 : ?make-staging-image ( profile -- )
93 dup staging-image-name exists?
94 [ drop ] [ make-staging-image ] if ;
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 ;
101 : deploy-command-line ( image vocab manifest-file config -- flags )
103 bootstrap-profile ?make-staging-image
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 ,
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
124 :: make-deploy-image ( vm image vocab config -- manifest )
126 vocab "vocab-manifest-" prepend temp-file :> manifest-file
127 image vocab manifest-file config deploy-command-line :> flags
129 manifest-file parse-vocab-manifest-file ;
131 :: make-deploy-image-executable ( vm image vocab config -- manifest )
132 vm image vocab config make-deploy-image
133 image vm embed-image ;
135 HOOK: deploy* os ( vocab -- )