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