1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: qualified io.streams.c init fry namespaces assocs kernel
4 parser lexer strings.parser tools.deploy.config vocabs sequences
5 words words.private memory kernel.private continuations io
6 prettyprint vocabs.loader debugger system strings sets ;
7 QUALIFIED: bootstrap.stage2
9 QUALIFIED: command-line
10 QUALIFIED: compiler.errors.private
11 QUALIFIED: compiler.units
12 QUALIFIED: continuations
13 QUALIFIED: definitions
19 QUALIFIED: libc.private
20 QUALIFIED: libc.private
22 QUALIFIED: prettyprint.config
23 QUALIFIED: source-files
26 IN: tools.deploy.shaker
28 : strip-init-hooks ( -- )
29 "Stripping startup hooks" show
30 "command-line" init-hooks get delete-at
31 "libc" init-hooks get delete-at
33 "threads" init-hooks get delete-at
36 "io.thread" init-hooks get delete-at
39 "io.backend" init-hooks get delete-at
42 : strip-debugger ( -- )
44 "Stripping debugger" show
45 "resource:extra/tools/deploy/shaker/strip-debugger.factor"
51 "Stripping manual memory management debug code" show
52 "resource:extra/tools/deploy/shaker/strip-libc.factor"
58 "Stripping unused Cocoa methods" show
59 "resource:extra/tools/deploy/shaker/strip-cocoa.factor"
63 : strip-word-names ( words -- )
64 "Stripping word names" show
65 [ f over set-word-name f swap set-vocabulary>> ] each ;
67 : strip-word-defs ( words -- )
68 "Stripping symbolic word definitions" show
69 [ "no-def-strip" word-prop not ] filter
70 [ [ ] swap set-word-def ] each ;
72 : strip-word-props ( stripped-props words -- )
73 "Stripping word properties" show
77 '[ drop , member? not ] assoc-filter
82 : stripped-word-props ( -- seq )
91 "default-output-classes"
108 "predicate-definition"
138 : strip-words ( props -- )
140 deploy-word-props? get [ 2dup strip-word-props ] unless
141 deploy-word-defs? get [ dup strip-word-defs ] unless
142 strip-word-names? [ dup strip-word-names ] when
145 : strip-recompile-hook ( -- )
146 [ [ f ] { } map>assoc ]
147 compiler.units:recompile-hook
150 : strip-vocab-globals ( except names -- words )
151 [ child-vocabs [ words ] map concat ] map concat swap diff ;
153 : stripped-globals ( -- seq )
155 "callbacks" "alien.compiler" lookup ,
158 bootstrap.stage2:bootstrap-time
160 continuations:error-continuation
161 continuations:error-thread
162 continuations:restarts
165 inspector:inspector-hook
168 source-files:source-files
175 threads:initial-thread ,
178 strip-io? [ io.backend:io-backend , ] when
184 } strip-vocab-globals %
187 { } { "cpu" } strip-vocab-globals %
192 classes:class-and-cache
193 classes:class-not-cache
194 classes:class-or-cache
195 classes:class<=-cache
196 classes:classes-intersect-cache
197 classes:implementors-map
199 command-line:main-vocab-hook
201 compiler.units:recompile-hook
202 compiler.units:update-tuples-hook
211 listener:listener-hook
215 vocabs:load-vocab-hook
219 { } { "optimizer.math.partial" } strip-vocab-globals %
224 prettyprint.config:margin
225 prettyprint.config:string-limit
226 prettyprint.config:tab-size
232 compiler.errors.private:compiler-errors
233 continuations:thread-error-hook
237 deploy-c-types? get [
238 "c-types" "alien.c-types" lookup ,
242 "ui-error-hook" "ui.gadgets.worlds" lookup ,
245 "<computer>" "inference.dataflow" lookup [ , ] when*
247 "windows-messages" "windows.messages" lookup [ , ] when*
251 : strip-globals ( stripped-globals -- )
253 "Stripping globals" show
255 '[ drop , member? not ] assoc-filter
256 [ drop string? not ] assoc-filter ! strip CLI args
257 dup keys unparse show
261 : finish-deploy ( final-image -- )
263 >r { } set-datastack r>
268 "Saving final image" show
269 [ save-image-and-exit ] call-clear ;
273 : set-boot-quot* ( word -- )
276 init-hooks get values concat %
278 strip-io? [ \ flush , ] unless
279 ] [ ] make "Boot quotation: " write dup . flush
288 deploy-vocab get vocab-main set-boot-quot*
289 stripped-word-props >r
290 stripped-globals strip-globals
293 : (deploy) ( final-image vocab config -- )
294 #! Does the actual work of a deployment in the slave
299 deploy-vocab get require
303 print-error flush 1 exit
310 "Deploying " write dup write "..." print
311 dup deploy-config dup .