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