factor/basis/tools/deploy/shaker/shaker.factor

348 lines
9.1 KiB
Factor
Raw Normal View History

! Copyright (C) 2007, 2008 Slava Pestov.
2007-10-06 13:37:47 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-06-30 17:06:14 -04:00
USING: accessors qualified io.streams.c init fry namespaces
assocs kernel parser lexer strings.parser tools.deploy.config
vocabs sequences words words.private memory kernel.private
continuations io prettyprint vocabs.loader debugger system
2008-07-05 04:07:10 -04:00
strings sets vectors quotations byte-arrays ;
QUALIFIED: bootstrap.stage2
QUALIFIED: classes
2008-04-04 11:11:31 -04:00
QUALIFIED: command-line
QUALIFIED: compiler.errors.private
QUALIFIED: compiler.units
QUALIFIED: continuations
QUALIFIED: definitions
QUALIFIED: init
QUALIFIED: io.backend
QUALIFIED: io.thread
QUALIFIED: layouts
QUALIFIED: libc.private
QUALIFIED: libc.private
QUALIFIED: listener
QUALIFIED: prettyprint.config
QUALIFIED: source-files
QUALIFIED: threads
QUALIFIED: vocabs
2007-10-06 13:37:47 -04:00
IN: tools.deploy.shaker
2008-07-02 16:57:38 -04:00
! This file is some hairy shit.
2007-10-06 13:37:47 -04:00
: strip-init-hooks ( -- )
"Stripping startup hooks" show
2008-07-02 16:57:38 -04:00
"cpu.x86" init-hooks get delete-at
2007-10-09 02:07:59 -04:00
"command-line" init-hooks get delete-at
"libc" init-hooks get delete-at
deploy-threads? get [
"threads" init-hooks get delete-at
] unless
native-io? [
"io.thread" init-hooks get delete-at
] unless
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
2008-07-28 23:03:13 -04:00
"resource:basis/tools/deploy/shaker/strip-debugger.factor"
2007-10-06 13:37:47 -04:00
run-file
] when ;
: strip-libc ( -- )
"libc" vocab [
"Stripping manual memory management debug code" show
2008-07-28 23:03:13 -04:00
"resource:basis/tools/deploy/shaker/strip-libc.factor"
run-file
2007-10-06 13:37:47 -04:00
] when ;
: strip-cocoa ( -- )
"cocoa" vocab [
"Stripping unused Cocoa methods" show
2008-07-28 23:03:13 -04:00
"resource:basis/tools/deploy/shaker/strip-cocoa.factor"
2007-10-06 13:37:47 -04:00
run-file
] when ;
: strip-word-names ( words -- )
"Stripping word names" show
2008-06-30 17:06:14 -04:00
[ f >>name f >>vocabulary drop ] each ;
2007-10-06 13:37:47 -04:00
: strip-word-defs ( words -- )
2008-01-07 16:14:21 -05:00
"Stripping symbolic word definitions" show
2008-06-19 00:29:56 -04:00
[ "no-def-strip" word-prop not ] filter
2008-06-30 17:06:14 -04:00
[ [ ] >>def drop ] each ;
2007-10-06 13:37:47 -04:00
2008-07-02 16:57:38 -04:00
: sift-assoc ( assoc -- assoc' ) [ nip ] assoc-filter ;
2008-06-25 21:47:07 -04:00
: strip-word-props ( stripped-props words -- )
2007-10-06 13:37:47 -04:00
"Stripping word properties" show
[
[
props>> swap
2008-07-05 04:07:10 -04:00
'[ drop , member? not ] assoc-filter sift-assoc
dup assoc-empty? [ drop f ] [ >alist >vector ] if
2008-06-30 17:06:14 -04:00
] keep (>>props)
2008-01-09 17:36:30 -05:00
] with each ;
2007-10-06 13:37:47 -04:00
2008-06-25 21:47:07 -04:00
: stripped-word-props ( -- seq )
2007-10-06 13:37:47 -04:00
[
2008-06-25 21:47:07 -04:00
strip-dictionary? [
{
"coercer"
"compiled-effect"
"compiled-uses"
"constraints"
"declared-effect"
2008-07-05 04:07:10 -04:00
"default"
"default-method"
2008-06-25 21:47:07 -04:00
"default-output-classes"
2008-07-05 04:07:10 -04:00
"derived-from"
2008-06-25 21:47:07 -04:00
"identities"
"if-intrinsics"
"infer"
"inferred-effect"
2008-07-12 02:08:30 -04:00
"input-classes"
2008-06-25 21:47:07 -04:00
"interval"
"intrinsics"
"loc"
"members"
"methods"
2008-07-05 04:07:10 -04:00
"method-class"
"method-generic"
2008-06-25 21:47:07 -04:00
"combination"
"cannot-infer"
2008-07-05 04:07:10 -04:00
"no-compile"
2008-06-25 21:47:07 -04:00
"optimizer-hooks"
"output-classes"
"participants"
"predicate"
"predicate-definition"
"predicating"
2008-07-05 04:07:10 -04:00
"tuple-dispatch-generic"
2008-06-25 21:47:07 -04:00
"slots"
"slot-names"
"specializer"
"step-into"
"step-into?"
"superclass"
"reading"
"writing"
"type"
"engines"
} %
] when
strip-prettyprint? [
{
2008-07-05 04:07:10 -04:00
"break-before"
"break-after"
2008-06-25 21:47:07 -04:00
"delimiter"
"flushable"
"foldable"
"inline"
"lambda"
"macro"
"memo-quot"
"parsing"
"word-style"
} %
2007-10-06 13:37:47 -04:00
] when
] { } make ;
: strip-words ( props -- )
[ word? ] instances
deploy-word-props? get [ 2dup strip-word-props ] unless
deploy-word-defs? get [ dup strip-word-defs ] unless
2007-10-31 01:09:24 -04:00
strip-word-names? [ dup strip-word-names ] when
2drop ;
2007-10-06 13:37:47 -04:00
: strip-recompile-hook ( -- )
[ [ f ] { } map>assoc ]
compiler.units:recompile-hook
set-global ;
: strip-vocab-globals ( except names -- words )
[ child-vocabs [ words ] map concat ] map concat swap diff ;
: stripped-globals ( -- seq )
[
"callbacks" "alien.compiler" lookup ,
2008-07-02 01:20:01 -04:00
"inspector-hook" "inspector" lookup ,
{
bootstrap.stage2:bootstrap-time
continuations:error
continuations:error-continuation
continuations:error-thread
continuations:restarts
2008-05-06 10:01:28 -04:00
listener:error-hook
init:init-hooks
io.thread:io-thread
libc.private:mallocs
source-files:source-files
input-stream
output-stream
error-stream
} %
deploy-threads? [
threads:initial-thread ,
] unless
strip-io? [ io.backend:io-backend , ] when
2008-06-25 21:47:07 -04:00
{ } {
"alarms"
"tools"
"io.launcher"
} strip-vocab-globals %
strip-dictionary? [
{ } { "cpu" } strip-vocab-globals %
{
2008-04-04 11:11:31 -04:00
gensym
name>char-hook
2008-03-24 21:15:42 -04:00
classes:class-and-cache
classes:class-not-cache
classes:class-or-cache
2008-05-02 03:51:38 -04:00
classes:class<=-cache
2008-03-24 21:15:42 -04:00
classes:classes-intersect-cache
classes:implementors-map
2008-03-24 21:15:42 -04:00
classes:update-map
2008-04-04 11:11:31 -04:00
command-line:main-vocab-hook
2008-03-24 21:15:42 -04:00
compiled-crossref
compiler.units:recompile-hook
2008-04-04 11:11:31 -04:00
compiler.units:update-tuples-hook
2008-03-24 21:15:42 -04:00
definitions:crossref
interactive-vocabs
layouts:num-tags
layouts:num-types
layouts:tag-mask
layouts:tag-numbers
layouts:type-numbers
2008-03-24 21:15:42 -04:00
lexer-factory
listener:listener-hook
root-cache
vocab-roots
2008-03-24 21:15:42 -04:00
vocabs:dictionary
vocabs:load-vocab-hook
word
} %
{ } { "optimizer.math.partial" } strip-vocab-globals %
] when
strip-prettyprint? [
{
prettyprint.config:margin
prettyprint.config:string-limit
prettyprint.config:tab-size
} %
] when
strip-debugger? [
{
compiler.errors.private:compiler-errors
continuations:thread-error-hook
} %
] when
deploy-c-types? get [
"c-types" "alien.c-types" lookup ,
] unless
deploy-ui? get [
"ui-error-hook" "ui.gadgets.worlds" lookup ,
] when
2008-04-04 11:05:52 -04:00
2008-04-04 11:11:31 -04:00
"<computer>" "inference.dataflow" lookup [ , ] when*
2008-04-04 11:05:52 -04:00
"windows-messages" "windows.messages" lookup [ , ] when*
] { } make ;
: strip-globals ( stripped-globals -- )
2007-10-31 01:09:24 -04:00
strip-globals? [
"Stripping globals" show
global swap
'[ drop , member? not ] assoc-filter
[ drop string? not ] assoc-filter ! strip CLI args
2008-07-02 16:57:38 -04:00
sift-assoc
2008-03-16 03:21:51 -04:00
dup keys unparse show
21 setenv
2007-10-06 13:37:47 -04:00
] [ drop ] if ;
2008-07-05 04:07:10 -04:00
: compress ( pred string -- )
"Compressing " prepend show
instances
dup H{ } clone [ [ ] cache ] curry map
become ; inline
: compress-byte-arrays ( -- )
[ byte-array? ] "byte arrays" compress ;
: compress-quotations ( -- )
[ quotation? ] "quotations" compress ;
: compress-strings ( -- )
[ string? ] "strings" compress ;
2007-10-06 13:37:47 -04:00
: finish-deploy ( final-image -- )
"Finishing up" show
>r { } set-datastack r>
{ } set-retainstack
V{ } set-namestack
V{ } set-catchstack
"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 ;
2008-01-07 16:14:21 -05:00
: strip ( -- )
strip-libc
2007-10-06 13:37:47 -04:00
strip-cocoa
strip-debugger
2008-01-07 16:14:21 -05:00
strip-recompile-hook
2007-10-06 13:37:47 -04:00
strip-init-hooks
deploy-vocab get vocab-main set-boot-quot*
2008-06-25 21:47:07 -04:00
stripped-word-props >r
stripped-globals strip-globals
2008-07-05 04:07:10 -04:00
r> strip-words
compress-byte-arrays
compress-quotations
compress-strings ;
2007-10-06 13:37:47 -04:00
: (deploy) ( final-image vocab config -- )
#! Does the actual work of a deployment in the slave
#! stage2 image
[
[
deploy-vocab set
deploy-vocab get require
strip
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