]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deploy/macosx/macosx.factor
alien.libraries: add a "deploy-library" word that marks a library to have its dll...
[factor.git] / basis / tools / deploy / macosx / macosx.factor
1 ! Copyright (C) 2007, 2009 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     vm parent-directory parent-directory ;
14
15 : copy-bundle-dir ( bundle-name dir -- )
16     [ bundle-dir prepend-path swap ] keep
17     "Contents" prepend-path append-path copy-tree ;
18
19 : app-plist ( icon? 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
29         [ "Icon.icns" "CFBundleIconFile" set ] when
30     ] H{ } make-assoc ;
31
32 : create-app-plist ( icon? executable bundle-name -- )
33     [ app-plist ] keep
34     "Contents/Info.plist" append-path
35     write-plist ;
36
37 : copy-dll ( bundle-name -- )
38     "Frameworks/libfactor.dylib" copy-bundle-dir ;
39
40 : copy-nib ( bundle-name -- )
41     deploy-ui? get [
42         "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-dll ]
55                 [ copy-nib ]
56                 [ "Contents/Resources" append-path make-directories ]
57             } cleave
58         ]
59         [ copy-icns ]
60         [ create-app-plist ]
61         [ "Contents/MacOS/" append-path copy-vm ]
62     } 2cleave
63     dup OCT: 755 set-file-permissions ;
64
65 : deploy.app-image ( vocab bundle-name -- str )
66     [ % "/Contents/Resources/" % % ".image" % ] "" make ;
67
68 : bundle-name ( -- string )
69     deploy-name get ".app" append ;
70
71 : show-in-finder ( path -- )
72     [ NSWorkspace -> sharedWorkspace ]
73     [ normalize-path [ <NSString> ] [ parent-directory <NSString> ] bi ] bi*
74     -> selectFile:inFileViewerRootedAtPath: drop ;
75
76 M: macosx deploy* ( vocab -- )
77     ".app deploy tool" assert.app
78     "resource:" [
79         dup deploy-config [
80             bundle-name dup exists? [ delete-tree ] [ drop ] if
81             [ bundle-name create-app-dir ] keep
82             [ bundle-name deploy.app-image ] keep
83             namespace make-deploy-image
84             bundle-name
85             [ "Contents/Resources" copy-resources ]
86             [ "Contents/Frameworks" copy-libraries ] 2bi
87             bundle-name show-in-finder
88         ] bind
89     ] with-directory ;