1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors qualified io.streams.c init fry namespaces
4 assocs kernel parser lexer strings.parser tools.deploy.config
5 vocabs sequences words words.private memory kernel.private
6 continuations io prettyprint vocabs.loader debugger system
8 QUALIFIED: bootstrap.stage2
10 QUALIFIED: command-line
11 QUALIFIED: compiler.errors.private
12 QUALIFIED: compiler.units
13 QUALIFIED: continuations
14 QUALIFIED: definitions
19 QUALIFIED: libc.private
20 QUALIFIED: libc.private
22 QUALIFIED: prettyprint.config
23 QUALIFIED: source-files
26 IN: tools.deploy.shaker
28 ! This file is some hairy shit.
30 : strip-init-hooks ( -- )
31 "Stripping startup hooks" show
32 "cpu.x86" init-hooks get delete-at
33 "command-line" init-hooks get delete-at
34 "libc" init-hooks get delete-at
36 "threads" init-hooks get delete-at
39 "io.thread" init-hooks get delete-at
42 "io.backend" init-hooks get delete-at
45 : strip-debugger ( -- )
47 "Stripping debugger" show
48 "resource:extra/tools/deploy/shaker/strip-debugger.factor"
54 "Stripping manual memory management debug code" show
55 "resource:extra/tools/deploy/shaker/strip-libc.factor"
61 "Stripping unused Cocoa methods" show
62 "resource:extra/tools/deploy/shaker/strip-cocoa.factor"
66 : strip-word-names ( words -- )
67 "Stripping word names" show
68 [ f >>name f >>vocabulary drop ] each ;
70 : strip-word-defs ( words -- )
71 "Stripping symbolic word definitions" show
72 [ "no-def-strip" word-prop not ] filter
73 [ [ ] >>def drop ] each ;
75 : sift-assoc ( assoc -- assoc' ) [ nip ] assoc-filter ;
77 : strip-word-props ( stripped-props words -- )
78 "Stripping word properties" show
82 '[ drop , member? not ] assoc-filter
83 sift-assoc f assoc-like
87 : stripped-word-props ( -- seq )
96 "default-output-classes"
113 "predicate-definition"
143 : strip-words ( props -- )
145 deploy-word-props? get [ 2dup strip-word-props ] unless
146 deploy-word-defs? get [ dup strip-word-defs ] unless
147 strip-word-names? [ dup strip-word-names ] when
150 : strip-recompile-hook ( -- )
151 [ [ f ] { } map>assoc ]
152 compiler.units:recompile-hook
155 : strip-vocab-globals ( except names -- words )
156 [ child-vocabs [ words ] map concat ] map concat swap diff ;
158 : stripped-globals ( -- seq )
160 "callbacks" "alien.compiler" lookup ,
162 "inspector-hook" "inspector" lookup ,
165 bootstrap.stage2:bootstrap-time
167 continuations:error-continuation
168 continuations:error-thread
169 continuations:restarts
174 source-files:source-files
181 threads:initial-thread ,
184 strip-io? [ io.backend:io-backend , ] when
190 } strip-vocab-globals %
193 { } { "cpu" } strip-vocab-globals %
198 classes:class-and-cache
199 classes:class-not-cache
200 classes:class-or-cache
201 classes:class<=-cache
202 classes:classes-intersect-cache
203 classes:implementors-map
205 command-line:main-vocab-hook
207 compiler.units:recompile-hook
208 compiler.units:update-tuples-hook
217 listener:listener-hook
221 vocabs:load-vocab-hook
225 { } { "optimizer.math.partial" } strip-vocab-globals %
230 prettyprint.config:margin
231 prettyprint.config:string-limit
232 prettyprint.config:tab-size
238 compiler.errors.private:compiler-errors
239 continuations:thread-error-hook
243 deploy-c-types? get [
244 "c-types" "alien.c-types" lookup ,
248 "ui-error-hook" "ui.gadgets.worlds" lookup ,
251 "<computer>" "inference.dataflow" lookup [ , ] when*
253 "windows-messages" "windows.messages" lookup [ , ] when*
257 : strip-globals ( stripped-globals -- )
259 "Stripping globals" show
261 '[ drop , member? not ] assoc-filter
262 [ drop string? not ] assoc-filter ! strip CLI args
264 dup keys unparse show
268 : finish-deploy ( final-image -- )
270 >r { } set-datastack r>
275 "Saving final image" show
276 [ save-image-and-exit ] call-clear ;
280 : set-boot-quot* ( word -- )
283 init-hooks get values concat %
285 strip-io? [ \ flush , ] unless
286 ] [ ] make "Boot quotation: " write dup . flush
295 deploy-vocab get vocab-main set-boot-quot*
296 stripped-word-props >r
297 stripped-globals strip-globals
300 : (deploy) ( final-image vocab config -- )
301 #! Does the actual work of a deployment in the slave
306 deploy-vocab get require
310 print-error flush 1 exit
317 "Deploying " write dup write "..." print
318 dup deploy-config dup .