]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/macosx/macosx.factor
factor: trim more using lists.
[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: cocoa.application cocoa.plists combinators io.backend
4 io.directories io.files io.files.info.unix io.pathnames kernel
5 make namespaces sequences system tools.deploy.backend
6 tools.deploy.config tools.deploy.config.editor vocabs.loader ;
7 QUALIFIED-WITH: tools.deploy.unix unix
8 IN: tools.deploy.macosx
9
10 : bundle-dir ( -- dir )
11     running.app?
12     [ vm-path parent-directory parent-directory parent-directory ]
13     [ "resource:Factor.app" ]
14     if ;
15
16 : copy-bundle-dir ( bundle-name dir -- )
17     [ bundle-dir prepend-path swap ] keep
18     append-path copy-tree ;
19
20 : app-plist ( icon? executable bundle-name -- assoc )
21     [
22         "6.0" "CFBundleInfoDictionaryVersion" ,,
23         "APPL" "CFBundlePackageType" ,,
24
25         file-name "CFBundleName" ,,
26
27         [ "CFBundleExecutable" ,, ]
28         [ "org.factor." prepend "CFBundleIdentifier" ,, ] bi
29
30         [ "Icon.icns" "CFBundleIconFile" ,, ] when
31
32         t "NSHighResolutionCapable" ,,
33     ] H{ } make ;
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 : vocab-mac-icon-path ( vocab -- string )
46     vocab-dir "icon.icns" append-path ;
47
48 : copy-icns ( vocab bundle-name -- icon? )
49     swap dup vocab-mac-icon-path vocab-append-path dup file-exists?
50     [ swap "Contents/Resources/Icon.icns" append-path copy-file t ]
51     [ 2drop f ] if ;
52
53 : create-app-dir ( vocab bundle-name -- vm )
54     {
55         [
56             nip
57             [ copy-nib ]
58             [ "Contents/Resources" append-path make-directories ]
59             [ "Contents/Frameworks" append-path make-directories ] tri
60         ]
61         [ copy-icns ]
62         [ create-app-plist ]
63         [ "Contents/MacOS/" append-path copy-vm ]
64     } 2cleave
65     dup 0o755 set-file-permissions ;
66
67 : bundle-name ( -- string )
68     deploy-name get ".app" append ;
69
70 : deploy.app-image-name ( vocab bundle-name -- str )
71     [ % "/Contents/Resources/" % % ".image" % ] "" make ;
72
73 : deploy-app-bundle ( vocab -- )
74     bundle-name dup file-exists? [ delete-tree ] [ drop ] if
75     [ bundle-name create-app-dir ] keep
76     [ bundle-name deploy.app-image-name ] keep
77     namespace make-deploy-image
78     bundle-name
79     [ "Contents/Resources" copy-resources ]
80     [ "Contents/Frameworks" copy-libraries ] 2bi
81     bundle-name maybe-open-deploy-directory ;
82
83 : deploy-app-bundle? ( vocab -- ? )
84     deploy-config [ deploy-console? get not deploy-ui? get or ] with-variables ;
85
86 M: macosx deploy*
87     ! pass off to M: unix deploy* if we're building a console app
88     dup deploy-app-bundle? [
89         deploy-app-bundle
90     ] [
91         call-next-method
92     ] if ;
93
94 M: macosx deploy-path
95     dup deploy-app-bundle? [
96         deploy-directory get [
97             dup deploy-config [
98                 bundle-name "Contents/MacOS/" append-path
99                 swap append-path normalize-path
100             ] with-variables
101         ] with-directory
102     ] [
103         call-next-method
104     ] if ;