1 ! Copyright (C) 2007, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs bootstrap.image hashtables io io.directories
4 io.encodings.utf8 io.files io.files.temp io.launcher io.pathnames
5 kernel locals make namespaces prettyprint sequences splitting system
6 tools.deploy.config tools.deploy.config.editor tools.deploy.embed
7 tools.deploy.libraries vocabs.loader vocabs.metadata.resources
9 IN: tools.deploy.backend
11 : copy-vm ( executable bundle-name -- vm-path )
12 prepend-path vm-path over copy-file ;
14 TUPLE: vocab-manifest vocabs libraries ;
16 : copy-resources ( manifest name dir -- )
17 append-path swap vocabs>> [ copy-vocab-resources ] with each ;
19 ERROR: can't-deploy-library-file library ;
21 : copy-library ( dir library -- )
23 [ swap over file-name append-path copy-file ]
24 [ can't-deploy-library-file ] ?if ;
26 : copy-libraries ( manifest name dir -- )
27 append-path swap libraries>> [ copy-library ] with each ;
29 : deployed-image-name ( vocab -- str )
30 ".image" append temp-file ;
33 readln [ print flush copy-lines ] when* ;
35 : run-with-output ( arguments -- )
40 +low-priority+ >>priority
41 utf8 [ copy-lines ] with-process-reader ;
43 : make-boot-image ( -- )
44 ! If stage1 image doesn't exist, create one.
45 my-boot-image-name resource-path exists?
46 [ make-my-image ] unless ;
48 : staging-image-name ( profile -- name )
49 "-" join "." my-arch-name 3append
50 "staging." ".image" surround cache-file ;
52 : delete-staging-images ( -- )
54 [ "staging." head? ] filter
55 "." my-arch-name ".image" 3append [ tail? ] curry filter
57 ] with-directory-files ;
59 : input-image-name ( profile -- name )
60 but-last [ my-boot-image-name ] [ staging-image-name ] if-empty ;
62 : run-factor ( vm-path flags -- )
63 swap prefix dup . run-with-output ; inline
65 : staging-command-line ( profile -- flags )
68 "-staging" , "-no-user-init" , "-pic=0" ,
69 [ staging-image-name "-output-image=" prepend , ]
70 [ " " join "-include=" prepend , ] bi
72 input-image-name "-i=" prepend ,
73 "-resource-path=" "" resource-path append ,
74 "-run=tools.deploy.restage" ,
78 : make-staging-image ( profile -- )
79 { } [ suffix ] accumulate* [ staging-image-name exists? ] reject
80 [ staging-command-line ] map
81 [ vm-path swap run-factor ] each ;
83 : make-deploy-config ( vocab -- file )
84 [ deploy-config vocab-roots get vocab-roots associate assoc-union unparse-use ]
85 [ "deploy-config-" prepend temp-file ] bi
86 [ utf8 set-file-contents ] keep ;
88 : deploy-command-line ( image vocab manifest-file profile -- flags )
91 staging-image-name "-i=" prepend ,
92 "-vocab-manifest-out=" prepend ,
93 [ "-deploy-vocab=" prepend , ]
94 [ make-deploy-config "-deploy-config=" prepend , ] bi
95 "-output-image=" prepend ,
96 "-resource-path=" "" resource-path append ,
97 "-run=tools.deploy.shaker" ,
100 : parse-vocab-manifest-file ( path -- vocab-manifest )
101 utf8 file-lines [ "empty vocab manifest!" throw ] [
102 unclip-slice "VOCABS:" =
103 [ { "LIBRARIES:" } split1 vocab-manifest boa ]
104 [ "invalid vocab manifest!" throw ] if
107 :: make-deploy-image ( vm image vocab config -- manifest )
110 config config>profile :> profile
111 vocab "vocab-manifest-" prepend temp-file :> manifest-file
112 image vocab manifest-file profile deploy-command-line :> flags
114 profile make-staging-image
116 manifest-file parse-vocab-manifest-file ;
118 :: make-deploy-image-executable ( vm image vocab config -- manifest )
119 vm image vocab config make-deploy-image
120 image vm embed-image ;
122 SYMBOL: open-directory-after-deploy?
123 t open-directory-after-deploy? set-global
125 : maybe-open-deploy-directory ( directory -- )
126 absolute-path open-directory-after-deploy? get
127 [ open-item ] [ drop ] if ;
129 HOOK: deploy* os ( vocab -- )
131 HOOK: deploy-path os ( vocab -- path )