factor/extra/tools/deploy/shaker/shaker.factor

179 lines
4.7 KiB
Factor
Raw Normal View History

2007-10-06 13:37:47 -04:00
! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces continuations.private kernel.private init
assocs kernel vocabs words sequences memory io system arrays
continuations math definitions mirrors splitting parser classes
inspector layouts vocabs.loader prettyprint.config prettyprint
debugger io.streams.c io.streams.duplex io.files io.backend
quotations words.private tools.deploy.config ;
IN: tools.deploy.shaker
: show ( msg -- )
#! Use primitives directly so that we can print stuff even
#! after most of the image has been stripped away
"\r\n" append stdout fwrite stdout fflush ;
: strip-init-hooks ( -- )
"Stripping startup hooks" show
2007-10-09 02:07:59 -04:00
"command-line" init-hooks get delete-at
2007-10-31 01:09:24 -04:00
strip-io? [ "io.backend" init-hooks get delete-at ] when ;
2007-10-06 13:37:47 -04:00
: strip-debugger ( -- )
2007-10-31 01:09:24 -04:00
strip-debugger? [
2007-10-06 13:37:47 -04:00
"Stripping debugger" show
2007-10-09 02:07:59 -04:00
"resource:extra/tools/deploy/shaker/strip-debugger.factor"
2007-10-06 13:37:47 -04:00
run-file
] when ;
: strip-cocoa ( -- )
"cocoa" vocab [
"Stripping unused Cocoa methods" show
2007-10-09 02:07:59 -04:00
"resource:extra/tools/deploy/shaker/strip-cocoa.factor"
2007-10-06 13:37:47 -04:00
run-file
] when ;
: strip-assoc ( retained-keys assoc -- newassoc )
swap [ nip member? ] curry assoc-subset ;
: strip-word-names ( words -- )
"Stripping word names" show
[ f over set-word-name f swap set-word-vocabulary ] each ;
: strip-word-defs ( words -- )
"Stripping unoptimized definitions from optimized words" show
[ compiled? ] subset [ [ ] swap set-word-def ] each ;
: strip-word-props ( retain-props words -- )
"Stripping word properties" show
[
[ word-props strip-assoc f assoc-like ] keep
set-word-props
] curry* each ;
: retained-props ( -- seq )
[
"class" ,
"metaclass" ,
"slot-names" ,
deploy-ui? get [
"gestures" ,
"commands" ,
{ "+nullary+" "+listener+" "+description+" }
[ "ui.commands" lookup , ] each
] when
] { } make ;
: strip-words ( props -- )
[ word? ] instances
2007-10-31 01:09:24 -04:00
deploy-word-props? get [ nip ] [ tuck strip-word-props ] if
strip-word-names? [ dup strip-word-names ] when
2007-10-06 13:37:47 -04:00
strip-word-defs ;
: strip-environment ( retain-globals -- )
"Stripping environment" show
2007-10-31 01:09:24 -04:00
strip-globals? [
2007-10-06 13:37:47 -04:00
global strip-assoc 21 setenv
] [ drop ] if ;
: finish-deploy ( final-image -- )
"Finishing up" show
>r { } set-datastack r>
{ } set-retainstack
V{ } set-namestack
V{ } set-catchstack
2007-10-09 02:07:59 -04:00
"Stripping compiled quotations" show
strip-compiled-quotations
2007-10-06 13:37:47 -04:00
"Saving final image" show
[ save-image-and-exit ] call-clear ;
SYMBOL: deploy-vocab
: set-boot-quot* ( word -- )
[
\ boot ,
init-hooks get values concat %
,
2007-10-31 01:09:24 -04:00
strip-io? [ \ flush , ] unless
2007-10-06 13:37:47 -04:00
] [ ] make "Boot quotation: " write dup . flush
set-boot-quot ;
: retained-globals ( -- seq )
[
builtins ,
2007-10-31 01:09:24 -04:00
strip-io? [ io-backend , ] unless
2007-10-06 13:37:47 -04:00
2007-10-31 01:09:24 -04:00
strip-dictionary? [
2007-10-06 13:37:47 -04:00
{
builtins
dictionary
inspector-hook
lexer-factory
load-vocab-hook
num-tags
num-types
tag-bits
tag-mask
tag-numbers
typemap
vocab-roots
} %
] unless
2007-10-31 01:09:24 -04:00
strip-prettyprint? [
2007-10-06 13:37:47 -04:00
{
tab-size
margin
} %
] unless
2007-10-31 01:09:24 -04:00
deploy-c-types? get deploy-ui? get or [
2007-10-06 13:37:47 -04:00
"c-types" "alien.c-types" lookup ,
] when
deploy-ui? get [
"ui" child-vocabs
"cocoa" child-vocabs
deploy-vocab get child-vocabs 3append
global keys [ word? ] subset
swap [ >r word-vocabulary r> member? ] curry
subset %
] when
] { } make dup . ;
: strip ( -- )
strip-cocoa
strip-debugger
strip-init-hooks
deploy-vocab get vocab-main set-boot-quot*
retained-props >r
retained-globals strip-environment
r> strip-words ;
: (deploy) ( final-image vocab config -- )
#! Does the actual work of a deployment in the slave
#! stage2 image
[
[
deploy-vocab set
parse-hook get >r
parse-hook off
deploy-vocab get require
r> [ call ] when*
strip
2007-10-09 02:07:59 -04:00
"Compressing image" show
compress-image
2007-10-06 13:37:47 -04:00
finish-deploy
] [
print-error flush 1 exit
] recover
] bind ;
: do-deploy ( -- )
"output-image" get
"deploy-vocab" get
"Deploying " write dup write "..." print
dup deploy-config dup .
(deploy) ;
MAIN: do-deploy