1 ! Copyright (C) 2007, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors io.backend io.streams.c init fry
4 namespaces make assocs kernel parser lexer strings.parser vocabs
5 sequences words memory kernel.private
6 continuations io vocabs.loader system strings sets
7 vectors quotations byte-arrays sorting compiler.units
8 definitions generic generic.standard tools.deploy.config ;
9 QUALIFIED: bootstrap.stage2
11 QUALIFIED: command-line
12 QUALIFIED: compiler.errors
13 QUALIFIED: continuations
14 QUALIFIED: definitions
17 QUALIFIED: source-files
18 QUALIFIED: source-files.errors
20 IN: tools.deploy.shaker
22 ! This file is some hairy shit.
24 : strip-init-hooks ( -- )
25 "Stripping startup hooks" show
26 { "cpu.x86" "command-line" "libc" "system" "environment" }
27 [ init-hooks get delete-at ] each
29 "threads" init-hooks get delete-at
32 "io.thread" init-hooks get delete-at
35 "io.files" init-hooks get delete-at
36 "io.backend" init-hooks get delete-at
39 "compiler.units" init-hooks get delete-at
40 "vocabs.cache" init-hooks get delete-at
43 : strip-debugger ( -- )
44 strip-debugger? "debugger" vocab and [
45 "Stripping debugger" show
46 "vocab:tools/deploy/shaker/strip-debugger.factor"
52 "Stripping manual memory management debug code" show
53 "vocab:tools/deploy/shaker/strip-libc.factor"
58 "Stripping stack effect checking from call( and execute(" show
59 "vocab:tools/deploy/shaker/strip-call.factor" run-file ;
63 "Stripping unused Cocoa methods" show
64 "vocab:tools/deploy/shaker/strip-cocoa.factor"
68 : strip-word-names ( words -- )
69 "Stripping word names" show
70 [ f >>name f >>vocabulary drop ] each ;
72 : strip-word-defs ( words -- )
73 "Stripping symbolic word definitions" show
74 [ "no-def-strip" word-prop not ] filter
75 [ [ ] >>def drop ] each ;
77 : sift-assoc ( assoc -- assoc' ) [ nip ] assoc-filter ;
79 : strip-word-props ( stripped-props words -- )
80 "Stripping word properties" show
84 [ drop _ member? not ] assoc-filter sift-assoc
90 [ [ _ [ ] cache ] map ] change-props drop
94 : stripped-word-props ( -- seq )
102 "compiled-generic-uses"
110 "default-output-classes"
142 "predicate-definition"
179 : strip-words ( props -- )
181 deploy-word-props? get [ 2dup strip-word-props ] unless
182 deploy-word-defs? get [ dup strip-word-defs ] unless
183 strip-word-names? [ dup strip-word-names ] when
186 : strip-default-methods ( -- )
188 "Stripping default methods" show
190 [ generic? ] instances
191 [ "No method" throw ] (( -- * )) define-temp
192 dup t "default" set-word-prop
194 [ _ "default-method" set-word-prop ] [ make-generic ] bi
196 ] with-compilation-unit
199 : strip-vocab-globals ( except names -- words )
200 [ child-vocabs [ words ] map concat ] map concat
201 swap [ first2 lookup ] map sift diff ;
203 : stripped-globals ( -- seq )
205 "inspector-hook" "inspector" lookup ,
209 continuations:error-continuation
210 continuations:error-thread
211 continuations:restarts
213 source-files:source-files
219 "io-thread" "io.thread" lookup ,
221 "mallocs" "libc.private" lookup ,
224 "initial-thread" "threads" lookup ,
227 strip-io? [ io-backend , ] when
237 } strip-vocab-globals %
240 "libraries" "alien" lookup ,
242 { { "yield-hook" "compiler.utilities" } }
243 { "cpu" "compiler" } strip-vocab-globals %
248 classes:next-method-quot-cache
249 classes:class-and-cache
250 classes:class-not-cache
251 classes:class-or-cache
252 classes:class<=-cache
253 classes:classes-intersect-cache
254 classes:implementors-map
256 command-line:main-vocab-hook
258 compiled-generic-crossref
260 compiler.errors:compiler-errors
271 source-files.errors:error-types
273 vocabs:load-vocab-hook
278 { } { "math.partial-dispatch" } strip-vocab-globals %
280 { } { "peg" } strip-vocab-globals %
284 { } { "prettyprint.config" } strip-vocab-globals %
289 compiler.errors:compiler-errors
290 continuations:thread-error-hook
294 deploy-c-types? get [
295 "c-types" "alien.c-types" lookup ,
299 "ui-error-hook" "ui.gadgets.worlds" lookup ,
302 "windows-messages" "windows.messages" lookup [ , ] when*
305 : strip-globals ( stripped-globals -- )
307 "Stripping globals" show
309 '[ drop _ member? not ] assoc-filter
310 [ drop string? not ] assoc-filter ! strip CLI args
316 deploy-io get 2 = os windows? or [
319 "io.streams.c" forget-vocab
320 ] with-compilation-unit
323 : compress ( pred post-process string -- )
324 "Compressing " prepend show
325 [ instances dup H{ } clone [ [ ] cache ] curry map ] dip call
328 : compress-byte-arrays ( -- )
329 [ byte-array? ] [ ] "byte arrays" compress ;
331 : remain-compiled ( old new -- old new )
332 #! Quotations which were formerly compiled must remain
335 2dup [ compiled>> ] [ compiled>> not ] bi* and
336 [ nip jit-compile ] [ 2drop ] if
339 : compress-quotations ( -- )
340 [ quotation? ] [ remain-compiled ] "quotations" compress
341 [ quotation? ] instances [ f >>cached-effect f >>cache-counter drop ] each ;
343 : compress-strings ( -- )
344 [ string? ] [ ] "strings" compress ;
346 : compress-wrappers ( -- )
347 [ wrapper? ] [ ] "wrappers" compress ;
349 : finish-deploy ( final-image -- )
353 "Saving final image" show
354 save-image-and-exit ;
358 : [:c] ( -- word ) ":c" "debugger" lookup ;
360 : [print-error] ( -- word ) "print-error" "debugger" lookup ;
362 : deploy-boot-quot ( word -- )
365 init-hooks get values concat %
366 strip-debugger? [ , ] [
367 ! Don't reference try directly
371 [ _ execute( obj -- ) ] [
372 _ execute( obj -- ) nl
377 strip-io? [ [ flush ] % ] unless
382 : init-stripper ( -- )
384 f output-stream set-global ;
386 : compute-next-methods ( -- )
387 [ standard-generic? ] instances [
388 "methods" word-prop [
390 dup next-method-quot "next-method-quot" set-word-prop
393 "vocab:tools/deploy/shaker/next-methods.factor" run-file ;
397 strip-default-methods
405 f 5 setenv ! we can't use the Factor debugger or Factor I/O anymore
406 deploy-vocab get vocab-main deploy-boot-quot
408 stripped-globals strip-globals
415 : deploy-error-handler ( quot -- )
418 [ error-continuation get call>> callstack>array die 1 exit ]
419 ! Don't reference these words literally, if we're stripping the
420 ! debugger out we don't want to load the prettyprinter at all
421 [ [:c] execute( -- ) nl [print-error] execute( error -- ) flush ] if
425 : (deploy) ( final-image vocab config -- )
426 #! Does the actual work of a deployment in the slave
435 deploy-vocab get require
436 deploy-vocab get vocab-main [
437 "Vocabulary has no MAIN: word." print flush 1 exit
441 ] deploy-error-handler
447 "Deploying " write dup write "..." print
448 "deploy-config" get parse-file first