]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/macosx/macosx.factor
using the new H{ } make.
[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 QUALIFIED-WITH: tools.deploy.unix unix
11 IN: tools.deploy.macosx
12
13 : bundle-dir ( -- dir )
14     running.app?
15     [ vm 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     ] H{ } make ;
35
36 : create-app-plist ( icon? executable bundle-name -- )
37     [ app-plist ] keep
38     "Contents/Info.plist" append-path
39     write-plist ;
40
41 : copy-nib ( bundle-name -- )
42     deploy-ui? get [
43         "Contents/Resources/English.lproj/MiniFactor.nib" copy-bundle-dir
44     ] [ drop ] if ;
45
46 : copy-icns ( vocab bundle-name -- icon? )
47     swap dup vocab-mac-icon-path vocab-append-path dup exists?
48     [ swap "Contents/Resources/Icon.icns" append-path copy-file t ]
49     [ 2drop f ] if ;
50
51 : create-app-dir ( vocab bundle-name -- vm )
52     {
53         [
54             nip
55             [ copy-nib ]
56             [ "Contents/Resources" append-path make-directories ]
57             [ "Contents/Frameworks" append-path make-directories ] tri
58         ]
59         [ copy-icns ]
60         [ create-app-plist ]
61         [ "Contents/MacOS/" append-path copy-vm ]
62     } 2cleave
63     dup 0o755 set-file-permissions ;
64
65 : bundle-name ( -- string )
66     deploy-name get ".app" append ;
67
68 : show-in-finder ( path -- )
69     [ NSWorkspace -> sharedWorkspace ]
70     [ normalize-path [ <NSString> ] [ parent-directory <NSString> ] bi ] bi*
71     -> selectFile:inFileViewerRootedAtPath: drop ;
72
73 : deploy.app-image-name ( vocab bundle-name -- str )
74     [ % "/Contents/Resources/" % % ".image" % ] "" make ;
75
76 : deploy-app-bundle ( vocab -- )
77     "resource:" [
78         dup deploy-config [
79             bundle-name dup exists? [ delete-tree ] [ drop ] if
80             [ bundle-name create-app-dir ] keep
81             [ bundle-name deploy.app-image-name ] keep
82             namespace make-deploy-image
83             bundle-name
84             [ "Contents/Resources" copy-resources ]
85             [ "Contents/Frameworks" copy-libraries ] 2bi
86             bundle-name show-in-finder
87         ] with-variables
88     ] with-directory ;
89
90 : deploy-app-bundle? ( vocab -- ? )
91     deploy-config [ deploy-console? get not deploy-ui? get or ] with-variables ;
92
93 M: macosx deploy* ( vocab -- )
94     ! pass off to M: unix deploy* if we're building a console app
95     dup deploy-app-bundle?
96     [ deploy-app-bundle ]
97     [ call-next-method ] if ;