]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/macosx/macosx.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / basis / tools / deploy / macosx / macosx.factor
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io io.files kernel namespaces make sequences system
4 tools.deploy.backend tools.deploy.config
5 tools.deploy.config.editor assocs hashtables prettyprint
6 io.unix.backend cocoa io.encodings.utf8 io.backend
7 cocoa.application cocoa.classes cocoa.plists qualified
8 combinators ;
9 IN: tools.deploy.macosx
10
11 : bundle-dir ( -- dir )
12     vm parent-directory parent-directory ;
13
14 : copy-bundle-dir ( bundle-name dir -- )
15     bundle-dir over append-path -rot
16     "Contents" prepend-path append-path copy-tree ;
17
18 : app-plist ( executable bundle-name -- assoc )
19     [
20         "6.0" "CFBundleInfoDictionaryVersion" set
21         "APPL" "CFBundlePackageType" set
22
23         file-name "CFBundleName" set
24
25         [ "CFBundleExecutable" set ]
26         [ "org.factor." prepend "CFBundleIdentifier" set ] bi
27     ] H{ } make-assoc ;
28
29 : create-app-plist ( executable bundle-name -- )
30     [ app-plist ] keep
31     "Contents/Info.plist" append-path
32     write-plist ;
33
34 : copy-dll ( bundle-name -- )
35     "Frameworks/libfactor.dylib" copy-bundle-dir ;
36
37 : copy-freetype ( bundle-name -- )
38     deploy-ui? get [ "Frameworks" copy-bundle-dir ] [ drop ] if ;
39
40 : copy-nib ( bundle-name -- )
41     deploy-ui? get [
42         "Resources/English.lproj/MiniFactor.nib" copy-bundle-dir
43     ] [ drop ] if ;
44
45 : create-app-dir ( vocab bundle-name -- vm )
46     [
47         nip {
48             [ copy-dll ]
49             [ copy-freetype ]
50             [ copy-nib ]
51             [ "Contents/Resources/" copy-fonts ]
52             [ "Contents/Resources" append-path make-directories ]
53         } cleave
54     ]
55     [ create-app-plist ]
56     [ "Contents/MacOS/" append-path "" copy-vm ] 2tri ;
57
58 : deploy.app-image ( vocab bundle-name -- str )
59     [ % "/Contents/Resources/" % % ".image" % ] "" make ;
60
61 : bundle-name ( -- string )
62     deploy-name get ".app" append ;
63
64 : show-in-finder ( path -- )
65     [ NSWorkspace -> sharedWorkspace ]
66     [ normalize-path [ <NSString> ] [ parent-directory <NSString> ] bi ] bi*
67     -> selectFile:inFileViewerRootedAtPath: drop ;
68
69 M: macosx deploy* ( vocab -- )
70     ".app deploy tool" assert.app
71     "resource:" [
72         dup deploy-config [
73             bundle-name dup exists? [ delete-tree ] [ drop ] if
74             [ bundle-name create-app-dir ] keep
75             [ bundle-name deploy.app-image ] keep
76             namespace make-deploy-image
77             bundle-name show-in-finder
78         ] bind
79     ] with-directory ;