]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/macosx/macosx.factor
use radix literals
[factor.git] / basis / tools / deploy / macosx / macosx.factor
1 ! Copyright (C) 2007, 2010 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
9 combinators vocabs.metadata vocabs.loader ;
10 IN: tools.deploy.macosx
11
12 : bundle-dir ( -- dir )
13     running.app?
14     [ vm parent-directory parent-directory ]
15     [ "resource:Factor.app" ]
16     if ;
17
18 : copy-bundle-dir ( bundle-name dir -- )
19     [ bundle-dir prepend-path swap ] keep
20     append-path copy-tree ;
21
22 : app-plist ( icon? executable bundle-name -- assoc )
23     [
24         "6.0" "CFBundleInfoDictionaryVersion" set
25         "APPL" "CFBundlePackageType" set
26
27         file-name "CFBundleName" set
28
29         [ "CFBundleExecutable" set ]
30         [ "org.factor." prepend "CFBundleIdentifier" set ] bi
31
32         [ "Icon.icns" "CFBundleIconFile" set ] when
33     ] H{ } make-assoc ;
34
35 : create-app-plist ( icon? executable bundle-name -- )
36     [ app-plist ] keep
37     "Contents/Info.plist" append-path
38     write-plist ;
39
40 : copy-nib ( bundle-name -- )
41     deploy-ui? get [
42         "Contents/Resources/English.lproj/MiniFactor.nib" copy-bundle-dir
43     ] [ drop ] if ;
44
45 : copy-icns ( vocab bundle-name -- icon? )
46     swap dup vocab-mac-icon-path vocab-append-path dup exists?
47     [ swap "Contents/Resources/Icon.icns" append-path copy-file t ]
48     [ 2drop f ] if ;
49
50 : create-app-dir ( vocab bundle-name -- vm )
51     {
52         [
53             nip
54             [ copy-nib ]
55             [ "Contents/Resources" append-path make-directories ]
56             [ "Contents/Frameworks" append-path make-directories ] tri
57         ]
58         [ copy-icns ]
59         [ create-app-plist ]
60         [ "Contents/MacOS/" append-path copy-vm ]
61     } 2cleave
62     dup 0o755 set-file-permissions ;
63
64 : deploy.app-image ( vocab bundle-name -- str )
65     [ % "/Contents/Resources/" % % ".image" % ] "" make ;
66
67 : bundle-name ( -- string )
68     deploy-name get ".app" append ;
69
70 : show-in-finder ( path -- )
71     [ NSWorkspace -> sharedWorkspace ]
72     [ normalize-path [ <NSString> ] [ parent-directory <NSString> ] bi ] bi*
73     -> selectFile:inFileViewerRootedAtPath: drop ;
74
75 M: macosx deploy* ( vocab -- )
76     "resource:" [
77         dup deploy-config [
78             bundle-name dup exists? [ delete-tree ] [ drop ] if
79             [ bundle-name create-app-dir ] keep
80             [ bundle-name deploy.app-image ] keep
81             namespace make-deploy-image
82             bundle-name
83             [ "Contents/Resources" copy-resources ]
84             [ "Contents/Frameworks" copy-libraries ] 2bi
85             bundle-name show-in-finder
86         ] bind
87     ] with-directory ;